Click to See Complete Forum and Search --> : How to add menu to a Dialog
Djibril
February 1st, 2001, 08:32 AM
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.
Weiye
February 1st, 2001, 08:35 AM
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...
------------------------------------------------------------------------------
Emi
February 1st, 2001, 08:40 AM
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.
Djibril
February 1st, 2001, 08:48 AM
Thanks a lot. It worked!
--
Where there is a WISH, there is a WILL.
Emi
February 1st, 2001, 08:50 AM
You are welcome.
Regards,
Emi.
Djibril
February 1st, 2001, 09:01 AM
thanks a lot.
--
Where there is a WISH, there is a WILL.
Weiye
February 1st, 2001, 09:54 AM
No problem. You are welcome.
Chen Weiye
------------------------------------------------------------------------------
When pursuing your dream, don't forget to enjoy your life...
------------------------------------------------------------------------------
Louis
May 18th, 2001, 05:41 PM
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::DeleteObjects()
{
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
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.