关于菜单的问题!谢谢

asos2002 2002-05-12 05:08:33
我想自己制作菜单 项,使其与 xp 的风格很相似,,,有这方面的介绍文章吗?

我看了一个源代码,,写的太多了,,我急需用的,,一时间我也看不懂啊!

最好哪里有这方面制作自己的菜单的文章 ,,

谢谢
...全文
77 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
weakpig 2002-05-12
  • 打赏
  • 举报
回复
参看http://www.codeproject.com/menu/menuxp2.asp写得很详细
meteor_wr 2002-05-12
  • 打赏
  • 举报
回复
菜单的风格还不是随便可以弄,你想怎样就怎样。
提供一些技巧给你吧:

9.1.1. How do I get a pointer to the menu bar in a MDI app?
QUESTION:

I'm writing a MDI application and I have problems to get a pointer to the actual menu bar. The normal construction doesn't seem to work in MDI:

CMenu *menu;
menu = GetMenu()->GetSubMenu(0);
How can I get a pointer to the menu bar to update the menu?ANSWER:

AfxGetApp()->m_pMainWnd->GetMenu()->GetSubMenu(n);
mlinar@pollux.usc.edu, Mitch Mlinar, 6/8/95

9.1.2. How do I implement a right-mouse popup-menu?
///////////////////////////////////////////////////////////////////
// WM_RBUTTONDOWN handler.
//
// Trap this message and display the button properties popup menu.
// The main frame receives the popup menu messages. This allows the
// status bar to be updated with the help text.
// ///////////////////////////////////////////////////////////////////
void CAppButton::OnRButtonDown(UINT flags, CPoint point)
{
CMenu menu;
CMenu *submenu;
// load the menu
menu.LoadMenu(IDR_LAUNCH);
// get the popup menu
submenu = menu.GetSubMenu(0);
// convert to screen coordinates
ClientToScreen(&point);
// post the menu
submenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
point.x, point.y,
AfxGetApp()->m_pMainWnd,NULL);
}
johnm@unipalm.co.uk, programmer.win32, 7/12/95

It's better to use RBUTTONUP instead, however right-clicking on dialog controls doesn't generate RBUTTONUP and RBUTTONDOWN messages.

If it's necessary to treat this situation too, a program have to catch WM_PARENTNOTIFY message in Win3.x and WinNT and WM_CONTEXTMENU in Windows 95. Here's a code:

// May be dialog too:
BEGIN_MESSAGE_MAP(CMyPropertyPage, CPropertyPage)
//{{AFX_MSG_MAP(CMyPropertyPage)
ON_WM_RBUTTONUP()
ON_WM_PARENTNOTIFY()
ON_MESSAGE(WM_CONTEXTMENU, OnContextMenu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CMyPropertyPage::OnRButtonUp(UINT nFlags, CPoint point)=20
{
PopupMenu (&point);
}

void CMyPropertyPage::OnParentNotify(UINT message, LPARAM lParam)
{
if (message !=3D WM_RBUTTONDOWN)
CPropertyPage::OnParentNotify(message, lParam);
else
{
CPoint pt(LOWORD(lParam),HIWORD(lParam));
PopupMenu (&pt);
}
}

LONG CMyPropertyPage::OnContextMenu (UINT wParam, LONG lParam)
{
CPoint pt(LOWORD(lParam),HIWORD(lParam));
ScreenToClient (&pt);
PopupMenu (&pt);
return 0;
}

//*****************************************************************

void CMyPropertyPage::PopupMenu(CPoint* pt)
{
ASSERT(m_idContextMenu !=3D 0);
ASSERT(nSubMenu >=3D 0);
ClientToScreen (pt);
CMenu FloatingMenu;
VERIFY(FloatingMenu.LoadMenu(ID_POPUP_MENU));
CMenu* pPopupMenu =3D FloatingMenu.GetSubMenu (0);
ASSERT(pPopupMenu !=3D NULL);
pPopupMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON,=20
pt->x, pt->y, this);
}
PaulACost@msn.com - via email, 10/15/95

9.1.3. How do I dynamically change the mainframe menu?
CMenu newMenu;
newMenu.LoadMenu (IDR_MENU1);
AfxGetMainWnd()->SetMenu( &newMenu );
AfxGetMainWnd()->DrawMenuBar();
newMenu.Detach ();
Arun Rao, MSMFC, 6/27/95

9.1.4. How do I 'attach' a menu to a window's creation/destruction?
{Note the original question talked about dialogs, but you can interpolate this code to any kind of window that you want to have change the menu.}

One of the ways to do this is as follows……

Declare a variable CMenu pNewMenu in one of the dialog class.
Handle the WM_INITDIALOG and WM_CLOSE messages in the dialog class as follows.

BOOL CMydlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Load the IDR_MYFRAME menu
pNewMenu = new CMenu;
pNewMenu->LoadMenu(IDR_MYFRAME);
// Set the mainframe menu to mainframe.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
return TRUE;
}
And

void CMydlg::OnClose()
{
// Detach the previous HMenu handle from the object.
pNewMenu->Detach();
pNewMenu->LoadMenu(IDR_MAINFRAME);
// Restore the mainframe menu.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
CDialog::OnClose();
}
If there are other methods of closing the dialog (example- By clicking a button in the Dialog), then The code given above in OnClose handler, must be put in the button click handler.

Sanjeev Kumar, MSMFC, 6/23/95

9.1.5. How do I add 'What's this' menus to my application - like Win95 hip apps have?
Here's some steps to get you started->

Put the following menu into a resource script:
IDR_WHAT_IS_THIS_MENU MENU DISCARDABLE
BEGIN
BEGIN
POPUP "a"
BEGIN
MENUITEM "What's this?", ID_WHAT_IS_THIS
END
END
END
Add to your dialog a right-click handler (OnRButtonDown) with menu IDR_WHAT_IS_THIS_MENU. You need to store the point of the last click in some variable - for example
CPoint m_cLastRClickPoint;

and store here the client coordinates of the last right click.
Put the following code into your dialog class (or probably the parent class of all your dialogs):
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
// whatever
//}}
ON_COMMAND(ID_WHAT_IS_THIS, OnWhatIsThis)
END_MESSAGE_MAP()

void CMyDialog::OnWhatIsThis()
{
CWnd* pControl = ChildWindowFromPoint (m_cLastRClickPoint);

// if the click wasn't on one of the controls - open help for dialog
if (pControl == NULL || pControl->m_hWnd == m_hWnd)
WinHelp (HID_BASE_RESOURCE + m_nIDHelp, HELP_CONTEXTPOPUP);
else
WinHelp (HID_BASE_CONTROL + pControl->GetDlgCtrlID(), HELP_CONTEXTPOPUP);
}

- and finally add the following lines to the makehelp.bat file:

echo. >>hlp\wr.hm
echo // Controls (IDC_*) >>hlp\wr.hm
makehm IDC_,HIDC_,0x50000 resource.h >>hlp\wr.hm


相关的书籍很多很多,自己好好研究吧。做好了给我发一个哦:)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧