Skip to content

Instantly share code, notes, and snippets.

@vlhs-beep
Forked from fschutt/main.cpp
Last active January 19, 2022 02:34
Show Gist options
  • Save vlhs-beep/0f56713577889d923bf6bc06572a662b to your computer and use it in GitHub Desktop.
Save vlhs-beep/0f56713577889d923bf6bc06572a662b to your computer and use it in GitHub Desktop.
//Example of how to create a minimal MFC application
//1. Create a new Win32 project, select empty project
//2. Go to project options > Use MFC in a shared library (.dll)
//3. Make a new resource file with an empty dialog
//4. Give the dialog the name "INTERFACE1"
//5. Build and run.
//---------------------------------------
#include <afxwin.h>
#include "resource.h"
//---------------------------------------
// Globals
CEdit * pINPUT;
CEdit * pOUTPUT;
CButton * pSTART;
class GAME_FORM : public CDialog
{
public:
GAME_FORM(CWnd* pParent = NULL) : CDialog(GAME_FORM::IDD, pParent) {};
//Dialog data, name of dialog here
enum { IDD = INTERFACE1 };
protected:
virtual void DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); };
//Called right after constructor. Initialize things here
virtual BOOL OnInitDialog()
{
CDialog::OnInitDialog();
pINPUT = (CEdit *)GetDlgItem(CE_INPUT);
pOUTPUT = (CEdit *)GetDlgItem(CE_OUTPUT);
pSTART = (CButton *)GetDlgItem(CB_START);
pINPUT->SetWindowText(L"Type HERE!");
pOUTPUT->SetWindowText(L"Click \"START\" to begin!");
return true;
}
public:
//---------------------------------------------
afx_msg void start() { STARTBUTTON(); }
//---------------------------------------------
void STARTBUTTON()
{
MessageBox(L"BYE!");
pSTART->EnableWindow(false);
}
DECLARE_MESSAGE_MAP()
};
//--------------------------------------------------
//Actual App
class TheGame : public CWinApp
{
public:
TheGame() {};
virtual BOOL InitInstance()
{
CWinApp::InitInstance();
GAME_FORM dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
return false;
}
};
//---------------------------------------------
//Need a Message Map Macro for both CDialog and CWinApp
BEGIN_MESSAGE_MAP(GAME_FORM, CDialog)
ON_COMMAND(CB_START, start)
END_MESSAGE_MAP()
//---------------------------------------------
//Start application
TheGame theApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment