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

Win32编程

时间:2017-05-20 15:25:18      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:hwnd   default   color   bool   make   显示   resource   gets   chm   

#include <windows.h>

HINSTANCE hinst;

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hWnd, L"ONDragon", L"ONDragon", MB_OK);
        break;
    default:
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int lpCmdShow)
{
    //定义窗口类
    WNDCLASSEX wcx;

    hinst = hInstance;
    MSG msg;
    BOOL getMessage;

    wcx.lpszClassName = L"MainClass";
    wcx.cbSize = sizeof(wcx);
    wcx.style = CS_HREDRAW | CS_VREDRAW;
    wcx.hInstance = hinst;
    wcx.lpfnWndProc = MainWndProc;
    wcx.cbClsExtra = 0;
    wcx.cbWndExtra = 0;
    wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wcx.lpszMenuName = NULL;
    wcx.hIconSm = (HICON)LoadImage( hInstance,
                                    MAKEINTRESOURCE(5),
                                    IMAGE_ICON,
                                    GetSystemMetrics(SM_CXSMICON),
                                    GetSystemMetrics(SM_CYSMICON),
                                    LR_DEFAULTCOLOR);
    //注册窗口类
    if (!RegisterClassEx(&wcx))
    {
        return 0;
    }
    //使用窗口类创建窗口
    HWND hWnd = CreateWindow(   L"MainClass",
                                L"ONDragon",
                                WS_OVERLAPPEDWINDOW,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                CW_USEDEFAULT,
                                NULL,
                                NULL,
                                hinst,
                                NULL);
    if (!hWnd)
    {
        return 0;
    }
    //显示窗口
    ShowWindow(hWnd,lpCmdShow);
    //立即显示窗口
    UpdateWindow(hWnd);
    while ( 0 != (getMessage = GetMessage(&msg,NULL,0,0)))
    {
        //传递个回调函数MainProc
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

Win32编程

标签:hwnd   default   color   bool   make   显示   resource   gets   chm   

原文地址:http://www.cnblogs.com/ONDragon/p/6882129.html

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