Reputation: 197
When i create the window named'A' by CreateWindow function,the window 'A' become not responding,but can draw it before it does not respond.
When i click the 'Sign In' button
unsigned __stdcall ThreadFunc(void *lParam) {
pMsgHead pmsgHead = new MsgHead;
while (RecvMsg(ConnectSocket,pmsgHead,sizeof(MsgHead))) {
switch (pmsgHead->dwCmd) {
case WM_SIGN_IN:
g_hMain=CreateWindow(szMainClass, L"A", WS_OVERLAPPEDWINDOW,
200, 200, 250, 500, 0, 0, hInst, nullptr);
ShowWindow(g_hMain, SW_SHOW);
UpdateWindow(g_hMain);
break;
case WM_BROADCAST:
//DrawText()
break;
}
}
_endthreadex(0);
return 0;
}
But when i click the 'Sign Up' button,it will work.
case IDB_SIGN_UP:
g_hSignUp = CreateWindow(szSignUpClass, L"Sign Up", WS_OVERLAPPEDWINDOW,
800, 200, 300, 300, 0, 0, hInst, nullptr);
ShowWindow(g_hSignUp, SW_SHOW);
UpdateWindow(g_hSignUp);
break;
case IDB_SIGN_IN:
{
TCHAR uname[20], psd[20];
GetWindowText(g_hSignInuname, uname, 20);
GetWindowText(g_hSignInpsd, psd, 20);
pMsgHead pmsgHead = new MsgHead;
pmsgHead->dwCmd = WM_SIGN_IN;
wcscpy_s(pmsgHead->tszbuf, uname);
wcscat_s(pmsgHead->tszbuf, L",");
wcscat_s(pmsgHead->tszbuf, psd);
SendMsg(ConnectSocket, pmsgHead, sizeof(MsgHead));
break;
}
I just use while loop in GetMessage function in Main thread and RecvMsg in the above,I use the single-step debug the program, one thread will wait in
while(RecvMsg())the Main thread will run the 'break' in
case IDB_SIGN_IN:then return 0,if I still use single-step debug,it will tips not loaded 'wuser32.pdb'
Upvotes: 0
Views: 287
Reputation: 612884
You are creating the window in a thread. Which means the window has affinity with that thread. Messages are sent to that threads message queue. You don't have a message loop in the thread so nothing can respond to the messages.
The fix is to create all your windows in the main thread. You should send a message to the main window that asks for your other window to be created. That way you will ensure that all your windows are created by the main UI thread.
Upvotes: 4