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

创建一个Windows窗体

时间:2014-05-22 16:20:18      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   c   code   

vs2010下的代码提示快捷键:CTRL + J

step:

窗口类赋值(12个参数)

注册窗口类

创建窗口

消息循环

 

 

bubuko.com,布布扣
#include<Windows.h>
#include<tchar.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    const TCHAR pClassName[] = _T("MyWindow");
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
    wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
    wcex.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
    wcex.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION);
    wcex.hInstance = hInstance;
    wcex.lpfnWndProc = WindowProc;
    wcex.lpszClassName = pClassName;
    wcex.lpszMenuName = NULL;
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    BOOL bRet = ::RegisterClassEx(&wcex);
    if(!bRet)
    {
        MessageBox(NULL, _T("提示"), _T("注册窗口类失败"), MB_OK);
        return FALSE;
    }
    HWND hWnd = ::CreateWindowEx(0, pClassName, _T("WinDemo"), WS_VISIBLE|WS_OVERLAPPEDWINDOW, 
                                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
                                NULL, NULL, hInstance, NULL);
    
    if(NULL == hWnd)
    {
        MessageBox(NULL, _T("提示"), _T("创建窗口失败!"), MB_OK);
        return FALSE;
    }
    ::ShowWindow(hWnd, SW_SHOW);
    ::UpdateWindow(hWnd);

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0))
    {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);
    }
    return TRUE;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_CLOSE:
            ::DestroyWindow(hwnd);
            return 0;
        case WM_DESTROY:
            ::PostQuitMessage(0);
            return 0;
        default:
            break;
    }
    return ::DefWindowProc(hwnd,uMsg,wParam,lParam);
}
bubuko.com,布布扣

 

创建一个Windows窗体,布布扣,bubuko.com

创建一个Windows窗体

标签:des   style   class   blog   c   code   

原文地址:http://www.cnblogs.com/wenwujuncheng/p/3743988.html

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