📄 dialog.cpp
字号:
#include <afxwin.h>
#include "resource.h"
class CApp : public CWinApp
{
public:
virtual InitInstance();
};
class CWindow : public CFrameWnd
{
CMenu *menu;
public:
CWindow();
afx_msg void OnPrompt();
afx_msg void OnExit();
DECLARE_MESSAGE_MAP()
};
class CPromptDialog : public CDialog
{
private:
CString inputString;
public:
CPromptDialog(CString initString=NULL,CWnd *pParentWnd=NULL)
: CDialog(IDC_DIALOG1 , pParentWnd)
{
inputString=initString;
}
virtual void OnOk();
virtual BOOL OnInitDialog();
CString & GetInputString()
{ return inputString; }
};
void CPromptDialog ::OnOk()
{
GetDlgItemText(IDC_EDIT1,
inputString.GetBuffer(100),100);
inputString.ReleaseBuffer();
EndDialog(IDOK);
}
BOOL CPromptDialog ::OnInitDialog()
{
SetDlgItemText(IDC_EDIT1,inputString);
return TRUE;
}
void CWindow :: OnPrompt()
{
CPromptDialog promptDialog("initial string",
this);
if (promptDialog.DoModal() == IDOK)
{
MessageBox(promptDialog.GetInputString(),
"String Entered", MB_ICONINFORMATION);
}
}
void CWindow ::OnExit()
{
DestroyWindow();
}
CApp App;
CWindow ::CWindow()
{
Create(NULL,"Simple Custom Dialog",
WS_OVERLAPPEDWINDOW,
rectDefault,NULL,
MAKEINTRESOURCE(IDR_MENU1));
}
BOOL CApp ::InitInstance()
{
m_pMainWnd = new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CWindow,CFrameWnd)
ON_COMMAND(IDM_FILE_PROMPT,OnPrompt)
ON_COMMAND(IDM_FILE_EXIT,OnExit)
END_MESSAGE_MAP()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -