• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

How to develop a basic Win32 Application in Visual C++ using a Dialog Box

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
? Complete Guide: Creating a Win32 Application with a Dialog Box in Visual C++ (MFC)


This guide walks you through creating a basic Win32 desktop application using Visual C++ and MFC, starting from scratch and using a dialog box as the main interface.

? Step 1: Create a New Project in Visual Studio

  1. Open Visual Studio.
  2. Go to File > New > Project....
  3. In the template list, select Windows Desktop Wizard.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



  1. Name the project and click OK.
  2. In the next screen:
    • Application type: select Desktop application
    • Check Empty Project to start from scratch.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



⚙ Step 2: Enable MFC Support


To use MFC (Microsoft Foundation Classes):

  1. Right-click the project in Solution Explorer and select Properties.
  2. Navigate to:

Project Properties > Configuration Properties > General
  1. Set Use of MFC to:
    • Use MFC in a Static Library.
  2. Click Apply, then OK.
? Step 3: Create the Main Application Class (Main)


This class represents the entry point for the application.

➤ Add the Header File

  1. Right-click on Header Files > Add > New Item
  2. Choose Header File (.h) and name it Main.h.

#pragma once
#include "afxwin.h"

class Main : public CWinApp {
public:
BOOL InitInstance();
};
➤ Add the Source File

  1. Right-click on Source Files > Add > New Item.
  2. Select C++ File (.cpp) and name it Main.cpp.

#include "afxwin.h"
#include "Main.h"
#include "CMainDlg.h" // To be created later

Main app;

BOOL Main::InitInstance() {
CMainDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
return TRUE;
}
? Step 4: Add a Dialog Box Resource

  1. Right-click Resource Files > Add > Resource.
  2. Select Dialog and click New.
  3. A dialog template named IDD_DIALOG1 will appear in the editor.

You can customize the dialog using the toolbox, adding buttons, labels, etc.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



? Step 5: Create the Dialog Class

  1. Right-click on the dialog template and select Add Class....
  2. Name the class CMainDlg.
  3. This will generate two files:
    • CMainDlg.h
    • CMainDlg.cpp


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



➤ Edit CMainDlg.h


Make sure it includes the necessary header:


#pragma once
#include "afxdialogex.h"

class CMainDlg : public CDialogEx {
public:
CMainDlg(CWnd* pParent = nullptr); // Constructor

#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG1 };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX);

DECLARE_MESSAGE_MAP()
};
➤ Edit CMainDlg.cpp


Ensure this file includes the resources header and links to the dialog ID:


#include "resource.h"
#include "CMainDlg.h"

IMPLEMENT_DYNAMIC(CMainDlg, CDialogEx)

CMainDlg::CMainDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG1, pParent) {}

void CMainDlg::DoDataExchange(CDataExchange* pDX) {
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMainDlg, CDialogEx)
END_MESSAGE_MAP()
? Step 6: (Optional) Enable Windows Visual Styles


To make your application use modern Windows controls:

  1. Right-click the project and select Add > New Item.
  2. Choose XML File, name it app.manifest.
  3. Paste the following into the file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*" />
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

This enables high-DPI support and modern UI styles for controls like buttons.

▶ Step 7: Run the Application

  1. Build the project (Ctrl + Shift + B).
  2. Run the application with Ctrl + F5.
  3. The dialog box should appear as the main window.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



✅ What's Next?


Now that you have a basic MFC app running with a dialog, you can:

  • Add buttons, text boxes, combo boxes, etc.
  • Handle events like button clicks with ON_BN_CLICKED macros.
  • Store user input using UpdateData(TRUE/FALSE).
? Related Video



Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



? Questions or improvements? Fork this guide or leave a comment in your repo!

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу