| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to add menu to a Dialog
Hello
I use to add menu to a dialog box by adding a menu to the resources and then select the dlg class for the menu. This is not working anymore. I wonder if there is something special with Visual 6 or not. Or do u just know another way to add menu to a dialog app ? Thanks. -- Where there is a WISH, there is a WILL. |
|
#2
|
|||
|
|||
|
Re: How to add menu to a Dialog
You can try using SetMenu(...), but before that you need to load your menu resource into a CMenu object using LoadMenu(...), as the parameter to SetMenu(...) is a pointer to a CMenu object.
Chen Weiye ------------------------------------------------------------------------------ When pursuing your dream, don't forget to enjoy your life... ------------------------------------------------------------------------------
__________________
Chen Weiye ----------------------------------------------------------------------------- When pursuing your dream, don't forget to enjoy your life ----------------------------------------------------------------------------- |
|
#3
|
||||
|
||||
|
Re: How to add menu to a Dialog
Hi,
See this// in OnInitDialog Menu.LoadMenu(IDR_MENU1); SetMenu(&Menu); Just add as member variable in your class CMenu Menu and insert a menu from resource (let the default ID). HTH. Regards, Emi.
__________________
Regards, Emanuel Vaduva |
|
#4
|
|||
|
|||
|
Re: How to add menu to a Dialog
Thanks a lot. It worked!
-- Where there is a WISH, there is a WILL. |
|
#5
|
||||
|
||||
|
Re: How to add menu to a Dialog
You are welcome.
Regards, Emi.
__________________
Regards, Emanuel Vaduva |
|
#6
|
|||
|
|||
|
Re: How to add menu to a Dialog
thanks a lot.
-- Where there is a WISH, there is a WILL. |
|
#7
|
|||
|
|||
|
Re: How to add menu to a Dialog
No problem. You are welcome.
Chen Weiye ------------------------------------------------------------------------------ When pursuing your dream, don't forget to enjoy your life... ------------------------------------------------------------------------------
__________________
Chen Weiye ----------------------------------------------------------------------------- When pursuing your dream, don't forget to enjoy your life ----------------------------------------------------------------------------- |
|
#8
|
|||
|
|||
|
Re: How to add menu to a Dialog
Emi,
I know U are one of the most talented gurus around here. U help us a lot. To tell U the truth, I'm learning VC++ by examples. This ex is like this (also from this forum) Dialog-based draw either line or rectangle. In the header of Dlg.h I added #define MODE_LINE 1 #define MODE_RECT 2 typedef CArray<POINT,POINT&> CPoly; typedef CArray<CPoly*,CPoly*> CPolyArray; /////////////////////////////////////// In Dlg.h, at constructor I added int m_mode; BOOL m_draw; CPoint m_click,m_move; CPolyArray m_objects; public: CLineDrawDlg(CWnd* pParent = NULL); // standard constructor void DeleteObjects(); In Dlg.cpp I added under m_hIcon = AfxGetApp()->LoadIcon(IDR_MENU2);//LoadIcon(IDR_MAINFRAME); the following: m_mode = MODE_LINE; m_draw = FALSE; and in func. void CLinedraw050101Dlg: eleteObjects(){ for(int i=0; i<m_objects.GetSize(); i++) delete m_objects[i]; m_objects.RemoveAll(); } In OnInitDialog(), I added: CMenu Menu; Menu.LoadMenu(IDR_MENU2);SetMenu(&Menu); In OnPaint() I added: CPaintDC dc(this); // device context for painting // draw all objects for(int i=0; i<m_objects.GetSize(); i++) dc.Polyline(m_objects[i]->GetData(),m_objects[i]->GetSize()); // CDialog::OnPaint(); In OnUpdateLine(CCmdUI* pCmdUI) , I added: pCmdUI->SetCheck(m_mode == MODE_LINE); In OnUpdateRect(CCmdUI* pCmdUI) , I added: pCmdUI->SetCheck(m_mode == MODE_RECT); In OnLButtonDown(UINT nFlags, CPoint point) , I added: m_click = m_move = point; m_draw = TRUE; SetCapture(); In OnLButtonUp(UINT nFlags, CPoint point) , I added: if(m_draw) { ReleaseCapture(); m_draw = FALSE; switch(m_mode) { case MODE_LINE: { CPoly *po; if(!(po = new CPoly)) break; po->Add(m_click); po->Add(point); m_objects.Add(po); InvalidateRect(0,0); break; } case MODE_RECT: { CPoly *po; if(!(po = new CPoly)) break; po->Add(m_click); po->Add(CPoint(point.x,m_click.y)); po->Add(point); po->Add(CPoint(m_click.x,point.y)); po->Add(m_click); m_objects.Add(po); InvalidateRect(0,0); break; } } } In OnMouseMove(UINT nFlags, CPoint point) , I added: if(m_draw) { CDC *dc=GetDC(); CRect re; CRect lre(m_click,m_move); // the rectangle of last movement CRect cre(m_click,point); // the rectangle of current movement lre.NormalizeRect(); cre.NormalizeRect(); re.UnionRect(lre,cre); // union rectangle of last + current movement re.InflateRect(2,2); // to include the border InvalidateRect(re,TRUE); UpdateWindow(); // update the modified rectangle switch(m_mode) { case MODE_LINE: dc->MoveTo(m_click); dc->LineTo(point); break; case MODE_RECT: dc->MoveTo(m_click); dc->LineTo(CPoint(point.x,m_click.y)); dc->LineTo(point); dc->LineTo(CPoint(m_click.x,point.y)); dc->LineTo(m_click); break; } m_move = point; } In PostNcDestroy() , I added: CDialog::PostNcDestroy();DeleteObjects(); In OnClose() , I added: CDialog::OnCancel(); CDialog::OnClose(); In OnCircle() , I added: m_mode = MODE_LINE; and in OnRectangle() , I added: m_mode = MODE_RECT; ( Plaese bear with me, newbie) When run my proj. I don't see "MODE" to select either Circle or Rectangle. Please help. L |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|