zoukankan      html  css  js  c++  java
  • 创建win32窗口

     1 #include <windows.h>
     2 LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
     3 int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
     4 {
     5     TCHAR szname[]=TEXT("classname");
     6     HWND hwnd;
     7     MSG msg;
     8     ZeroMemory(&msg,sizeof(msg));
     9     WNDCLASS wndclass;
    10     wndclass.style=CS_HREDRAW | CS_VREDRAW;
    11     wndclass.lpfnWndProc=WinProc;
    12     wndclass.cbClsExtra=0;
    13     wndclass.cbWndExtra=0;
    14     wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    15     wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
    16     wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    17     wndclass.hInstance=hInstance;
    18     wndclass.lpszClassName=szname;
    19     wndclass.lpszMenuName=NULL;
    20     RegisterClass(&wndclass);
    21     hwnd=CreateWindow(szname,TEXT("windowsnametest"),WS_OVERLAPPEDWINDOW ,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
    22     if(hwnd)
    23         ShowWindow(hwnd,SW_SHOW);
    24     else
    25     {
    26         MessageBox(NULL,TEXT("创建窗口失败!"),TEXT("提示"),MB_OK);
    27         UnregisterClass(szname,hInstance);
    28         return 1;
    29     }
    30     UpdateWindow(hwnd);
    31     
    32     while(GetMessage(&msg,hwnd,0,0)>0)
    33     {
    34         TranslateMessage(&msg);
    35         DispatchMessage(&msg);
    36     }
    37     UnregisterClass(szname,hInstance);
    38     return msg.wParam;
    39 }
    40 LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    41 {
    42     switch(message)
    43     {
    44     case WM_CLOSE:
    45         DestroyWindow(hwnd);
    46         PostQuitMessage(0);
    47         break;
    48     default:
    49         return DefWindowProc(hwnd,message,wParam,lParam);
    50     }
    51     return 0;
    52 }

    GetStockObject在库#pragma comment(lib, "gdi32.lib") 中。

  • 相关阅读:
    同库 不同表更新
    js 随机时间
    转 vagrant package[打包命令]详解
    mysql 批量更新与批量更新多条记录的不同值实现方法 (转)
    vagrant up时提示 Authentication failure. Retrying
    vagrant 错误记录
    签名保存
    linux下svn命令大全
    linux 搭建SVN服务器,为多个项目分别建立版本库并单独配置权限
    log file sync
  • 原文地址:https://www.cnblogs.com/zl1991/p/4935345.html
Copyright © 2011-2022 走看看