转的一个WIN32SDK程序框架demo

转的一个WIN32SDK程序框架demo

#include <windows.h>
#include<windowsx.h>

BOOL Cls_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
    MessageBox(NULL,"使用消息分流器创建窗口成功","ddd",MB_OK); 
    return 1;
}

LRESULT CALLBACK WinProc(HWND hwnd,
                         UINT msg,
                         WPARAM wparam,
                         LPARAM lparam)
{
    switch(msg)
    {
        case WM_CREATE:
            return HANDLE_WM_CREATE(hwnd, wparam, lparam, Cls_OnCreate);
        case WM_CLOSE:
            DestroyWindow(hwnd);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd, msg, wparam, lparam);
    }

    //这里可以输入响应消息的代码
    return 0;
}


int WINAPI WinMain(HINSTANCE hinstance,
                   HINSTANCE hprevinstance,
                   LPSTR lpcmdline,
                   int ncmdshow)
{
    HWND hWnd;
    MSG msg;     
    WNDCLASSEX wndclass; 
    wndclass.cbSize=sizeof(WNDCLASSEX);
    wndclass.style=CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc=(WNDPROC) WinProc;
    wndclass.cbClsExtra=0;
    wndclass.cbWndExtra=0;
    wndclass.hInstance = hinstance;   
    wndclass.hIcon = LoadIcon(NULL,IDI_ERROR);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = "WINCLASS1";
    wndclass.hIconSm = LoadIcon(wndclass.hInstance, (LPCTSTR)IDI_ERROR);
    wndclass.lpszMenuName = NULL;
    wndclass.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH);
    wndclass.lpszClassName ="WINCLASS1";
   

    if (!RegisterClassEx(&wndclass))
    {
        MessageBox(NULL,"ddd","ddd",MB_OK); 
         return 0;
    }    //    //……

    hWnd=CreateWindowEx(NULL,"WINCLASS1",
        "wndtitle",
        WS_OVERLAPPEDWINDOW|WS_VISIBLE ,       
        CW_USEDEFAULT, 0,
        400,400,
        NULL,
        NULL,
        hinstance,
        NULL );
    if (!hWnd)
            return 0;   
    ShowWindow(hWnd, ncmdshow);
    UpdateWindow(hWnd);
    while(GetMessage(&msg, NULL, 0, 0)) 
    {     
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }
   
    return msg.wParam;
}

转帖注明来自软工吧论坛
此信息来自〖软工吧论坛http://www.gcs8.cn〗
查看原网址:http://www.gcs8.cn/htm_data/2/0811/15785.html

你可能感兴趣的:(转的一个WIN32SDK程序框架demo)