作者共发了3篇帖子。 内容转换:不转换▼
 
点击 回复
290 2
【程序】一个最简单的MFC窗口程序
一派护法 十九级
1楼 发表于:2016-3-1 13:49
【代码】
#include <afxwin.h>

class CMyWnd : public CFrameWnd
{
public:
    CMyWnd()
    {
        Create(NULL, TEXT("My First MFC Program"));
    }
};

class CMyApp : public CWinApp
{
    BOOL InitInstance()
    {
        m_pMainWnd = new CMyWnd;
        m_pMainWnd->ShowWindow(m_nCmdShow);
        return CWinApp::InitApplication();
    }
};

CMyApp theApp;

【运行效果】

一派护法 十九级
2楼 发表于:2016-3-1 14:12
如果各位很讨厌MFC类名开头的那个C的话,可以用typedef强制去掉:

一派护法 十九级
3楼 发表于:2016-3-1 15:22
【使用Win32默认的细边框的窗口程序】
#define _WIN32_WINNT 0x0502
#include <afxwin.h>

// 消除MFC类名开头的C
typedef CFrameWnd FrameWnd;
typedef CString String;
typedef CWinApp WinApp;

// 定义窗口类
class MyWnd : public FrameWnd
{
public:
    MyWnd()
    {
        Create(NULL, TEXT("My First MFC Program"));
    }

    DECLARE_MESSAGE_MAP()
    afx_msg void OnPaint();
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};

// 定义程序类
class MyApp : public WinApp
{
    BOOL InitInstance()
    {
        m_pMainWnd = new MyWnd;
        m_pMainWnd->ShowWindow(m_nCmdShow);
        return WinApp::InitApplication();
    }
};

MyApp theApp;

BEGIN_MESSAGE_MAP(MyWnd, FrameWnd)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

// 可以直接用Visual Studio添加消息映射 (切换到类视图)
void MyWnd::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    // TODO: Add your message handler code here
    // Do not call FrameWnd::OnPaint() for painting messages
    String str = "这是一段字符串";
    dc.TextOut(2, 2, str);
}


int MyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (FrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    // TODO:  Add your specialized creation code here
    // 去除默认的粗边框
    ModifyStyleEx(WS_EX_CLIENTEDGE, NULL);

    return 0;
}


void MyWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    MessageBox(TEXT("You have clicked me."));

    FrameWnd::OnLButtonDown(nFlags, point);
}
【运行效果】

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:290 回复数:2
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2016-3-1 15:22
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。