Win32程序框架

Posted 泛未分晨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Win32程序框架相关的知识,希望对你有一定的参考价值。

#include<Windows.h>

LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int iCmdShow
    )
{
    TCHAR szAppName[] = TEXT("KeyView1");
    HWND hwnd;
    MSG msg;
    WNDCLASSEX wndClass;

    wndClass.cbSize = sizeof(WNDCLASSEX);
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
    wndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    wndClass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
    wndClass.hInstance = hInstance;
    wndClass.lpfnWndProc = WindowProc;
    wndClass.lpszClassName = szAppName;
    wndClass.lpszMenuName = NULL;
    wndClass.style = CS_VREDRAW|CS_HREDRAW;

    if(!RegisterClassEx(&wndClass))
    {
        MessageBox(NULL,TEXT("it requires Windows NT!"),TEXT("TIPS"),0);
        return -1;
    }

    hwnd = CreateWindow(
        szAppName,TEXT("KeyView1 Window"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
        NULL,NULL,hInstance,NULL
        );

    ShowWindow(hwnd,iCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&msg,0,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;

    switch(message)
    {
    case WM_CREATE:
        break;
    case WM_PAINT:
        hdc = BeginPaint(hwnd,&ps);
        EndPaint(hwnd,&ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hwnd,message,wParam,lParam);
}

 

以上是关于Win32程序框架的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Win32 控制台应用程序中将 argv[] 设置为不区分大小写?

使用 Win32/MFC 关闭并等待子框架窗口的最佳方法

Win32多线程调用gdal库接口

win32编程里,ransMessage()和DispatchMessage()是干嘛的

python将文本转换成语音的代码

win32是啥意思