@Sam of Simple Samples alsmot done, but what i can do about the loop in Step3? I still need the code to execute other things instead of stuck on a endless loop.
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
const char* translatedMessage = TrMessage(msg);
std::wstringstream ss;
ss << L"\nmsg: " << msg << L" " << translatedMessage;
OutputDebugString(ss.str().c_str());
switch(msg)
{
case WM_COPYDATA:
{
OutputDebugString(L"\nWM_COPYDATA!");
PCOPYDATASTRUCT pcds = reinterpret_cast<PCOPYDATASTRUCT>(lParam);
auto string = (char*)pcds->lpData;
//.......
return 1;
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int Main()
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = 0;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = L"myWindowClass";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Window Registration Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_LEFT, // this is the default
L"myWindowClass", // the name of the class, as passed to the RegisterClass function
NULL, // Title
0, // dwFlags, in our case this really doesn't matter
0, // X
0, // Y
0, // W
0, // H
HWND_MESSAGE , //the most important flag! Creates a message-only window
0, // hMenu
0 , // hInstance this function gets the instance handle of the current app
0 // lpParam
);
if(hwnd == NULL)
{
MessageBox(NULL, L"Window Creation Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0; // Msg.wParam;
}