BASE_MFC

这篇博客介绍了如何使用MFC进行Windows程序设计,重点在于窗口类的注册和WM_PAINT消息的处理。代码展示了自定义窗口过程函数custWndProc的实现,用于绘制'Hello WINDOW XP!'文本,并在窗口接收到WM_DESTROY消息时退出程序。
摘要由CSDN通过智能技术生成

BASE_MFC 



#include <stdio.h>
#include <windows.h>
LRESULT CALLBACK custWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
    switch (msg)
    {
    case WM_PAINT:
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
        hdc = BeginPaint(hwnd,&ps);
        GetClientRect(hwnd,&rect);
        //HDC hdc,LPCSTR lpchText,int cchText,LPRECT lprc,UINT format
        DrawText(hdc,TEXT("Hello WINDOW XP!"),-1,&rect,DT_INTERNAL);
        EndPaint(hwnd,&ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,msg,wParam,lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInStance,LPTSTR lptCmd,int nCmdShow){

    static TCHAR lpClassName[] = TEXT("WinProgram");
    HWND hwnd;
    MSG msg;
    //     UINT style;
    // WNDPROC lpfnWndProc;
    // int cbClsExtra;
    // int cbWndExtra;
    // HINSTANCE hInstance;
    // HICON hIcon;
    // HCURSOR hCursor;
    // HBRUSH hbrBackground;
    // LPCWSTR lpszMenuName;
    // LPCWSTR lpszClassName;
    WNDCLASS wClass;
    wClass.style = CS_DROPSHADOW;
    wClass.lpfnWndProc = custWndProc;
    wClass.cbClsExtra = 0;
    wClass.cbWndExtra = 0;
    wClass.hInstance = hInstance;
    wClass.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
    wClass.hCursor = LoadCursor(hInstance,IDC_ARROW);
    wClass.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
    wClass.lpszClassName = lpClassName;
    wClass.lpszMenuName = NULL;
    if(!RegisterClass(&wClass)){
        MessageBox(NULL,TEXT("注册窗口类失败!"),TEXT("WARNING"),MB_OK);
        return 0;
    }
    //DWORD dwExStyle,LPCSTR lpClassName,LPCSTR lpWindowName,DWORD dwStyle,int X,int Y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance,LPVOID lpParam
    hwnd = CreateWindow(
        lpClassName,
        TEXT("MFC Program"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        NULL,
        NULL,
        hInstance,
        NULL
    );
    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&msg,NULL,0,0)){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.lParam;

}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值