En utilisant les API Win32, est-il possible de créer une fenêtre ou une boîte de dialogue dans un thread puis de collecter des événements pour un autre thread?Est-ce que le HWND de CreateWindow/CreateDialog peut être GetMessage'd d'un autre thread?
Les HWND sont-ils liés aux threads?
En essayant l'exemple artificiel ci-dessous, je ne vois jamais GetMessage() fire.
HWND g_hWnd; DWORD WINAPI myThreadProc(LPVOID lpParam) { while(GetMessage(&msg, hWnd, 0, 0) > 0) { ... } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MYDIALOG), 0, myDlgProc); CreateThread(NULL, 0 myThreadProc, NULL, 0, NULL); ... }
Mais ici, je fais.
HWND g_hWnd; HINSTANCE g_hInstance; DWORD WINAPI myThreadProc(LPVOID lpParam) { hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MYDIALOG), 0, myDlgProc); while(GetMessage(&msg, hWnd, 0, 0) > 0) { ... } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { g_hInstance = hInstance; CreateThread(NULL, 0 myThreadProc, NULL, 0, NULL); ... }
Quelqu'un peut-il expliquer ce que je vois?
HA! Si vous définissez «possible», «en faisant autre chose entièrement», alors oui, tout est possible. – Shog9