zoukankan      html  css  js  c++  java
  • 非主线程创建窗口也能工作正常,只要我们注意一点:消息循环必须要和创建窗口在同一线程!

    #include "stdafx.h" #include "win32.h" #include "windows.h" #include #define MAX_LOADSTRING 100 HWND g_hWnd = NULL; HINSTANCE g_hInst; LRESULT CALLBACK WndProc(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); DispatchMessage(&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); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND hWnd,UINT wMsg,WPARAM wParam,LPARAM lParam) { return DefWindowProc(hWnd,wMsg,wParam,lParam); }
  • 相关阅读:
    qwebchannel.js
    锚点
    ECharts
    基于html2canvas实现网页保存为图片及图片清晰度优化
    JS判断某变量是否为某数组中的一个值的3种方法
    .on()之selector——jQuery
    Loading——spin.js
    理解CSS3 transform中的Matrix(矩阵)
    IOS中修改图片的大小:修改分辨率和裁剪
    IOS版本被拒的经历
  • 原文地址:https://www.cnblogs.com/chunyou128/p/4278164.html
Copyright © 2011-2022 走看看