Originally Posted by
xevo1
Wouldn't it be easier to have your computer make a sound?
Somehow I never saw this thread.. :l
I wrote a little something out of curiosity again..
Can be further advanced to print messages and send messages as well as many other possibilities.. Turned into a plugin, it'd be a cool toy I guess..
C++ Code:
/** © 2014, Brandon T. All Rights Reserved.
*
* This file is part of the SkypeHook API.
* SkypeHook is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SkypeHook is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SkypeHook. If not, see <http://www.gnu.org/licenses/>.
*/
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <iostream>
#include <memory>
#include <thread>
class SkypeAPI
{
private:
HWND WindowHandle = NULL;
HWND SkypeHandle = NULL;
std::uint32_t Attach_ID = 0;
std::uint32_t Discover_ID = 0;
const wchar_t* SkypeControlAPIAttach = L"SkypeControlAPIAttach";
const wchar_t* SkypeControlAPIDiscover = L"SkypeControlAPIDiscover";
public:
enum class ATTACH_STATUS : std::uint32_t
{
SUCCESS = 0, PENDING = 1, REFUSED = 2, UNAVAILABLE = 3, AVAILABLE = 0x8001
};
SkypeAPI(HWND WindowHandle);
const std::uint32_t GetAttachedID() const {return Attach_ID;}
const std::uint32_t GetDiscoverID() const {return Discover_ID;}
const HWND GetSkypeHandle() const {return this->SkypeHandle;}
void SetSkypeHandle(HWND SkypeHandle) {this->SkypeHandle = SkypeHandle;}
bool Connect()
{
DWORD_PTR Result = 0;
SendMessageTimeoutW(HWND_BROADCAST, this->Discover_ID, reinterpret_cast<WPARAM>(this->WindowHandle), 0, 0x0000, 100, &Result);
return Result != 0;
}
};
SkypeAPI::SkypeAPI(HWND WindowHandle)
{
this->WindowHandle = WindowHandle;
this->Attach_ID = RegisterWindowMessageW(this->SkypeControlAPIAttach);
this->Discover_ID = RegisterWindowMessageW(this->SkypeControlAPIDiscover);
}
void InitSkypeThread(HWND WindowHandle)
{
static std::unique_ptr<std::thread> runnable(nullptr);
if (!runnable.get())
{
runnable.reset(new std::thread(&InitSkypeThread, WindowHandle));
runnable.get()->detach();
}
}
LRESULT __stdcall WindowProcedure(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
static SkypeAPI api(Hwnd);
switch (Msg)
{
case WM_CREATE:
{
api.Connect();
}
break;
case WM_COPYDATA:
{
if (wParam == reinterpret_cast<WPARAM>(api.GetSkypeHandle()))
{
COPYDATASTRUCT* DataStruct = reinterpret_cast<COPYDATASTRUCT*>(lParam);
char* Response = static_cast<char*>(DataStruct->lpData);
std::cout<<Response<<"\n";
return 1;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
if (Msg == api.GetAttachedID())
{
SkypeAPI::ATTACH_STATUS status = static_cast<SkypeAPI::ATTACH_STATUS>(lParam);
if (status == SkypeAPI::ATTACH_STATUS::SUCCESS)
{
api.SetSkypeHandle(reinterpret_cast<HWND>(wParam));
std::cout<<"Connection: Successful.\n";
}
else if (status == SkypeAPI::ATTACH_STATUS::PENDING)
{
std::cout<<"Connection: Pending.\n";
}
else if (status == SkypeAPI::ATTACH_STATUS::REFUSED)
{
std::cout<<"Connection: Refused.\n";
}
else if (status == SkypeAPI::ATTACH_STATUS::UNAVAILABLE)
{
std::cout<<"Connection: Unavailable.\n";
}
else if (status == SkypeAPI::ATTACH_STATUS::AVAILABLE)
{
std::cout<<"Connection: Available.\n";
}
else
{
std::cout<<"Connection: Status-Unknown.\n";
}
return 1;
}
return DefWindowProcW(Hwnd, Msg, wParam, lParam);
}
return 0;
}
int InitWindow()
{
WNDCLASSEXW WndClass = {0};
WndClass.cbSize = sizeof(WndClass);
WndClass.lpfnWndProc = WindowProcedure;
WndClass.lpszClassName = L"SkypeHook";
WndClass.hInstance = GetModuleHandleW(nullptr);
if(RegisterClassExW(&WndClass))
{
MSG Messages = {0};
CreateWindowExW(0, L"SkypeHook", nullptr, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, HWND_MESSAGE, nullptr, GetModuleHandleW(nullptr), nullptr);
while(true)
{
if (PeekMessageW(&Messages, nullptr, 0, 0, PM_REMOVE) > 0)
{
if (Messages.message != WM_QUIT)
{
TranslateMessage(&Messages);
DispatchMessageW(&Messages);
continue;
}
break;
}
else
{
Sleep(100);
}
}
return Messages.wParam;
}
return 0;
}
int main()
{
InitWindow();
return 0;
}