The non-main thread creation window also works fine as long as we notice that the message loop must be created with the window on the same thread!

Source: Internet
Author: User
Tags getmessage

#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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.