In WinMain() use the window handle and post your self a message using PostMessage(), then process the message in WndProc(). The following code shows the basic structure.
Code:
#define WM_MY_MESSAGE1 WM_USER +1
#define WM_MY_MESSAGE2 WM_USER +2
#define WM_MY_MESSAGE3 WM_USER +3
struct My_Struct_A
{
int a; int b; int c;
};
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
...
...
hWnd = CreateWindow(...);
...
...
char strHello[] = "hello";
PostMessage( hWnd, WM_MY_MESSAGE1 ,0, (LPARAM )strHello );
int iValue = 12345;
PostMessage( hWnd, WM_MY_MESSAGE2 ,0, (LPARAM )iValue );
struct My_Struct_A *pMySA = (struct My_Struct_A *) malloc(sizeof(struct My_Struct_A));
...
pMySA->a = 1234;
...
PostMessage( hWnd, WM_MY_MESSAGE2 ,0, (LPARAM )pMySA );
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
...
...
int iNumber;
char *strText;
struct My_Struct_A *pMySA;
switch (message)
{
case WM_MY_MESSAGE1:
strText = (char*) lParam;
break;
case WM_MY_MESSAGE2:
iNumber = (int) lParam;
break;
case WM_MY_MESSAGE3:
pMySA = (struct My_Struct_A *) lParam;
break;
...
...
...
...
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}