Here is some basic code which you shouldn't really need. It's better to use Visual Studio Wizard to make an MFC application, dialog based or something, then go to resource editor, create a dialog, double click on that dialog in resource editor, it gets done for you. While still in resource editor, drag & drop a button to the dialog, double click on that button which you just dropped in...
//mydialog.h
class CMyDialog : public CDialog
{
public:
CMyDialog(int id, CWnd* parent = NULL);
void OnButton1();
DECLARE_MESSAGE_MAP()
};
//mydialog.cpp
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_COMMAND(IDC_BUTTON1, OnButton1)
END_MESSAGE_MAP()
CMyDialog::CMyDialog(int id, CWnd* parent) : CDialog(id, parent){
}
void CMyDialog::OnButton1(){
MessageBox(L"hello world");
}
//myapp.cpp
BOOL CMyApp::InitInstance()
{
CWinApp::InitInstance();
CMyDialog dlg(IDD_DIALOG1);
dlg.DoModal();
return 0;
}
CDialog
, named for exampleCMyDialog
. You can search for tutorials onCDialog
, there are many. Or add a new dialog in resource section, double click on the dialog in resource, Visual Studio will automatically create the class for you. In resource editor, insert a button in dialog, double click on the button, VS should create a function to handle what happens when you click the button. – Barmak Shemirani