请使用C语言编写一个简单的MFC应用程序,实现一个窗口并在其中添加一些控件。

以下是一个简单的使用C++编写的MFC应用程序示例,可以在其中添加一些控件。请使用Visual Studio等C++开发工具打开并编译运行。

cpp 复制代码
#include <afxwin.h>

class CMyApp : public CWinApp
{
public:
    virtual BOOL InitInstance();
};

class CMainWindow : public CFrameWnd
{
public:
    CMainWindow();
    afx_msg void OnButtonClicked();
    DECLARE_MESSAGE_MAP()
};

BOOL CMyApp::InitInstance()
{
    CMainWindow* pMainWnd = new CMainWindow();
    m_pMainWnd = pMainWnd;
    pMainWnd->Create(NULL, _T("My Application"));
    pMainWnd->ShowWindow(m_nCmdShow);
    pMainWnd->UpdateWindow();
    return TRUE;
}

CMainWindow::CMainWindow()
{
    Create(NULL, _T("My Application"), WS_OVERLAPPEDWINDOW, CRect(100, 100, 500, 300), NULL);

    CButton* pButton = new CButton();
    pButton->Create(_T("Click Me"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(10, 10, 100, 30), this, 1);

    CEdit* pEdit = new CEdit();
    pEdit->Create(WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL, CRect(10, 50, 200, 200), this, 2);
}

void CMainWindow::OnButtonClicked()
{
    MessageBox(_T("Button clicked!"), _T("Message"), MB_OK);
}

BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
    ON_COMMAND(1, OnButtonClicked)
END_MESSAGE_MAP()

CMyApp myApp;
相关推荐
不想写bug呀2 小时前
多线程案例——单例模式
java·开发语言·单例模式
我不会写代码njdjnssj2 小时前
网络编程 TCP UDP
java·开发语言·jvm
李少兄9 天前
解决OSS存储桶未创建导致的XML错误
xml·开发语言·python
阿蒙Amon9 天前
《C#图解教程 第5版》深度推荐
开发语言·c#
学Linux的语莫9 天前
python基础语法
开发语言·python
暖馒9 天前
C#委托与事件的区别
开发语言·c#
嘉琪0019 天前
2025——js 面试题
开发语言·javascript·ecmascript
Jinxiansen02119 天前
Vue3 中 ref 与 reactive 使用场景总结(含对比与示例)
开发语言·javascript·ecmascript
时空自由民.9 天前
C++ 不同线程之间传值
开发语言·c++·算法
止观止9 天前
Rust智能指针演进:从堆分配到零复制的内存管理艺术
开发语言·后端·rust