#include "stdafx.h" #include "win32.h" #include "windows.h" #include #define Max_loadstring 100HWND g_hwnd = NULL; HINSTANCE G_hinst; LRESULT Callbackwndproc (HWND, UINT, WPARAM, LPARAM); void Createwnd (void) {Wndclass WC = {0};wc.style = 0;wc.lpfnwndproc = Wndproc;wc.cbclsextra = 0;wc.cbwndextra = 0;wc.hinstance = G_hinst;wc.hicon = NULL; Wc.hcursor = LoadCursor (NULL, idc_arrow); wc.hbrbackground = (Hbrush) getsyscolorbrush (color_window); wc.lpszMenuName = Null;wc.lpszclassname = TEXT ("Simplewindow"); RegisterClass (&WC); G_hwnd = CreateWindowEx (0,text ("Simplewindow"), TEXT ("Simplewindow"), Ws_visible, 0,0,200,200,null, NULL, G_hinst, 0);} DWORD Threadbasefunc (lpvoid lpparam) {Createwnd (); MSG Msg;while (GetMessage (&msg,null,0,0)) {TranslateMessage (&msg);D ispatchmessage (&msg);} return 0;} int Apientry _tWinMain (hinstance hinstance, hinstance hprevinstance, LPTSTR lpcmdline, int ncmdshow) {g_hinst = HINSTANCE; HANDLE HTHRD = (HANDLE) _beginthreadex (null,0, (unsigned int (__stdcall*) (void*)) threadbasefunc,null,0,null); CloseHandle (HTHRD); MSG Msg;while (GetMessage(&msg,null,0,0)) {TranslateMessage (&msg);D ispatchmessage (&msg);} return 0;} LRESULT CALLBACK WndProc (HWND hwnd,uint wmsg,wparam wparam,lparam LPARAM) {return DefWindowProc (Hwnd,wmsg,wparam, LParam);}
The
Non-main thread creation window works fine as long as we notice that the message loop must be created with the window on the same thread!