CMake创建MFC桌面应用

2023-12-15 15:44:58

CMake创建MFC桌面应用

安装

项目代码

  • CMakeLists.txt (关键
cmake_minimum_required(VERSION 3.0)
project(mfc_demo)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
# 1: static MFC library, 2: shared MFC library
set(CMAKE_MFC_FLAG 2)
#find_package(MFC)
#if(NOT MFC_FOUND)
#    message(FATAL_ERROR "MFC is not found, please check MFC installation")
#endif()

add_executable(mfc_demo mfc.cpp)
#target_sources(mfc_demo PRIVATE
#        mfc.cpp
#        )
#set_target_properties(mfc_demo PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
target_compile_definitions(mfc_demo PRIVATE
        -DWIN32
        -D_DEBUG
        -D_WINDOWS
        -D_UNICODE
        -DUNICODE
        -D_AFXDLL
        )
target_link_options(mfc_demo PRIVATE
        /ENTRY:wWinMainCRTStartup
        )
  • mfc.h
#ifndef MFC_DEMO_MFC_H
#define MFC_DEMO_MFC_H

#include <afxwin.h>

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

class MyFrame:public CFrameWnd
{
public:
    MyFrame();

};

#endif //MFC_DEMO_MFC_H
  • mfc.cpp
#include "mfc.h"

MyApp app;

BOOL MyApp::InitInstance()
{

    MyFrame* frame = new MyFrame;
    frame->ShowWindow(SW_SHOWNORMAL);
    frame->UpdateWindow();

    m_pMainWnd = frame;

    return TRUE;
}

MyFrame::MyFrame() {
    Create(NULL, TEXT("mfc"));
}

文章来源:https://blog.csdn.net/alionsss/article/details/135013330
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。