码迷,mamicode.com
首页 > Windows程序 > 详细

NativeWindow_01_CreateWindow(Ex)_VC6

时间:2016-02-26 23:38:02      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:

1、

 1 #include <windows.h>
 2 
 3 
 4 LRESULT CALLBACK ProcWindow(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 5 void QuitWindow();
 6 
 7 HINSTANCE    g_hInstance = 0;
 8 HWND        g_hWnd = 0;
 9 
10 ////////////   ////////////   ////////////   ////////////   ////////////   ////////////
11 
12 int WINAPI WinMain(
13     HINSTANCE _hInstance,        // 当前 hInstance句柄
14     HINSTANCE _hPrevInstance,    // 之前的 hInstance句柄
15     LPSTR _lpCmdLine,            // 命令行
16     int _nCmdShow                // 显示状态
17 )
18 {
19     g_hInstance = _hInstance;
20 
21 // 程序(.exe)的图标貌似默认是 资源文件中 的第一个图标??
22     WNDCLASS wndcls = {0};
23     wndcls.style        = CS_HREDRAW | CS_VREDRAW;
24     wndcls.lpfnWndProc    = ProcWindow;
25     wndcls.cbClsExtra    = 0;
26     wndcls.cbWndExtra    = 0;
27     wndcls.hInstance    = _hInstance;
28     wndcls.hIcon        = LoadIcon(NULL, IDI_ERROR);    // 窗口图标
29     wndcls.hCursor        = LoadCursor(NULL, IDC_CROSS);
30     wndcls.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);    // 背景画刷
31     wndcls.lpszMenuName = NULL;
32     wndcls.lpszClassName= "zc20110929";
33 // 注册窗口类
34     RegisterClass(&wndcls);
35 
36     g_hWnd = CreateWindowEx(
37         NULL, //WS_EX_CLIENTEDGE,
38         wndcls.lpszClassName,
39         "ZC Window",
40         WS_OVERLAPPEDWINDOW,
41         100, 100,
42         400, 300,
43         NULL,
44         NULL, //g_hMenu,
45         _hInstance,
46         NULL);
47 
48     ShowWindow(g_hWnd, SW_SHOWNORMAL);
49     UpdateWindow(g_hWnd);
50 
51     MSG msg;
52     while(GetMessage(&msg, 0, 0, 0))
53     {
54         TranslateMessage(&msg);
55         DispatchMessage(&msg);
56     }
57 
58     return msg.wParam;
59 }
60 
61 LRESULT CALLBACK ProcWindow(
62     HWND _hWnd, // 窗口句柄
63     UINT _uMsg, // 消息ID(identifier)
64     WPARAM _wParam,
65     LPARAM _lParam)
66 {
67     switch (_uMsg)
68     {
69     case WM_PAINT:
70         {
71             HDC hDc;
72             PAINTSTRUCT ps;
73             hDc = BeginPaint(_hWnd, &ps);
74             TextOut(hDc, 0, 0, "ASDFG zxcvb", strlen("ASDFG zxcvb"));
75             EndPaint(_hWnd, &ps);
76             return 0;
77 //            break;
78         }
79     case WM_DESTROY:
80         {
81             PostQuitMessage(0);
82             return 0;    
83         }
84     }
85     return DefWindowProc(_hWnd, _uMsg, _wParam, _lParam);
86 }
87 
88 void QuitWindow()
89 {
90     DestroyWindow(g_hWnd);
91     PostQuitMessage(0);
92 }

 

2、

 

NativeWindow_01_CreateWindow(Ex)_VC6

标签:

原文地址:http://www.cnblogs.com/cppskill/p/5222017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!