MFC课中最重要的核心

  1. 这是MFC课上的内容,理解窗口程序很重要
#include <windows.h>
#include <iostream>
using namespace std;
#define APPNAME "MFC_Lession"
#define GUINAME "MFC_GUI"

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

int WINAPI WinMain(
    HINSTANCE hInstance,      // handle to current instance当前实例
    HINSTANCE hPrevInstance,  // handle to previous instance前一个实例
    LPSTR lpCmdLine,          // command line 字符串指针
    int nCmdShow              // show state  指定窗口的显示方式最大最小隐藏
    )
{
    /************************************************************************/
    /* s设计完毕                                                                     */
    /************************************************************************/
    WNDCLASS wcls;
    wcls.cbClsExtra = 0;
    wcls.cbWndExtra = 0;
    wcls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wcls.hIcon = LoadIcon(hInstance, IDI_WARNING);
    wcls.hCursor = LoadCursor(hInstance, IDC_CROSS);
    wcls.hInstance = hInstance;
    wcls.lpfnWndProc = MyProc;
    wcls.lpszClassName = APPNAME;
    wcls.lpszMenuName = NULL;
    wcls.style = CS_VREDRAW|CS_HREDRAW;

    /************************************************************************/
    /* 现在开始检测项目                                                  */
    /************************************************************************/
    RegisterClass(&wcls);

    /************************************************************************/
    /* 查看项目号                                                                     */
    /************************************************************************/

    HWND hwd;
    hwd = CreateWindow(APPNAME, GUINAME, WS_OVERLAPPEDWINDOW, 200, 200, 400, 400, NULL, NULL, hInstance, NULL);
    ShowWindow(hwd,SW_SHOWNORMAL);
    UpdateWindow(hwd);
/*
    HWND hwnd;                                                //创建对象变量
    hwnd = CreateWindow("sunxin2006", "http://www.sunxin.org", WS_OVERLAPPEDWINDOW,
        0, 0, 600, 400, NULL, NULL, hInstance, NULL);                //创建的对象变量存放数据
    ShowWindow(hwnd, SW_SHOWNORMAL);
    UpdateWindow(hwnd);*/
    /*
     * 创建消息机制 
    */
    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    //来自一条表示退出的消息,返回这个值给系统,从而退出
    return msg.wParam;

}
/*
 * 回调函数; 
*/
LRESULT CALLBACK MyProc(
                    HWND hwnd ,
                    UINT uMsg,
                    WPARAM wParam,
                    LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_PAINT:
            HDC dc;
            PAINTSTRUCT ps ;
            dc = BeginPaint(hwnd,&ps);
            TextOut(dc,100,100,"haha",strlen("haha"));
            EndPaint(hwnd,&ps);
            break;

        case WM_CLOSE:                                            //关闭窗口
            if (IDYES == MessageBox(hwnd, "是否真的结束?", "message", MB_YESNO))//文本输出
            {
                DestroyWindow(hwnd);
            }
            break;

        case WM_DESTROY:                                          //销毁窗口
            PostQuitMessage(0);                                   //发送消息关闭窗口
            break;

        default:
            return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;           
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值