对话框上多国语菜单:
Cmfc8testDlg::Cmfc8testDlg(CWnd* pParent /*=NULL*/)
: CDialog(Cmfc8testDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cmfc8testDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Cmfc8testDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &Cmfc8testDlg::OnBnClickedButton1)
ON_WM_RBUTTONDOWN()
ON_BN_CLICKED(IDC_BUTTON2, &Cmfc8testDlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, &Cmfc8testDlg::OnBnClickedButton3)
ON_COMMAND(ID_MENU1_32771, &Cmfc8testDlg::OnMenu132771)
END_MESSAGE_MAP()
// Cmfc8testDlg 消息处历咸衼E
BOOL Cmfc8testDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 将“关于...”菜单消楮赜到系统菜单中。
// IDM_ABOUTBOX 必衼E谙低趁丒?段?凇
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操讈E
SetIcon(m_hIcon, TRUE); // 设置大图眮E
SetIcon(m_hIcon, FALSE); // 设置小图眮E
// TODO: 在此铁赜尔殁的初始化代聛E
GetDlgItem(IDC_STATIC_SIZELIST)->SetWindowText(L"枠サイズ:葋E骓摛晰??扭颏慈丒Δ?坤丹?);
m_menu.LoadMenu(IDR_MENU1);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void Cmfc8testDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框铁赜?臁化按钮,则需要下面的代聛E
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动蛠E伞
void Cmfc8testDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);
// 使图眮E诠ぷ骶匦沃芯又
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图眮E
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动?臁化窗口时系统调用此函数取得光眮E允尽
//
HCURSOR Cmfc8testDlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}
void Cmfc8testDlg::OnBnClickedButton1()
{
// TODO: 在此铁赜控件通知处历咸序代聛E
HANDLE hModule = GetModuleHandle(NULL);
//AfxMessageBox(_T("hello unicode"));
m_menu.DestroyMenu();
m_menu.LoadMenu(IDR_MENU2);
HMENU hMenu = ::GetMenu(this->m_hWnd);
CMenu *pMenu = CMenu::FromHandle(hMenu);
pMenu->Detach();
SetMenu(&m_menu);
//m_menu.Attach(hMenu);
}
void Cmfc8testDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此铁赜消息处历咸序代聛E?或调用默认值
CMenu* pPopupMenu=m_menu.GetSubMenu(0);
CPoint pt;
GetCursorPos(&pt);
CRect rectLeft,rectRight;
pPopupMenu->TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this);
CDialog::OnRButtonDown(nFlags, point);
}
void Cmfc8testDlg::OnBnClickedButton2()
{
// TODO: 在此铁赜控件通知处历咸序代聛E
m_menu.DestroyMenu();
m_menu.LoadMenu(IDR_MENU3);
SetMenu(&m_menu);
}
void Cmfc8testDlg::OnBnClickedButton3()
{
m_menu.DestroyMenu();
m_menu.LoadMenu(IDR_MENU1);
SetMenu(&m_menu);
// TODO: 在此铁赜控件通知处历咸序代聛E
}
void Cmfc8testDlg::OnMenu132771()
{
// TODO: 在此铁赜脕E???绦虼?丒
m_menu.DestroyMenu();
m_menu.LoadMenu(IDR_MENU1);
SetMenu(&m_menu);
}
阅读(1164) | 评论(0) | 转发(0) |