|
-
October 6th, 2005, 03:58 AM
#1
how to update or refresh the menu?
how to update or refresh the menu when its text is changed . i used getmenustring() using that i got the string and using modifymenu() it modified my required menu. but the problem is after modification, its overwrites there and not changing . only solution is to update or refresh the menu.
thanks
-
October 6th, 2005, 04:03 AM
#2
Re: how to update or refresh the menu?
Why aren't you using the MFC's updateui mechanism?
Har Har
-
October 6th, 2005, 04:10 AM
#3
Re: how to update or refresh the menu?
i am using win32 project. in that only i have to do.
-
October 6th, 2005, 04:15 AM
#4
Re: how to update or refresh the menu?
hmm, in this case do post the cose you are using for updating the menu and tell us where you are doing it.
Har Har
-
October 6th, 2005, 04:33 AM
#5
Re: how to update or refresh the menu?
code[]
#include <afxwin.h>
#include "window.h"
#include "resource.h"
//#define MF_UNCHECKED 0;
CDerivedApp myApp;
BOOL CDerivedApp::InitInstance ()
{
m_pMainWnd = new CParentWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
BEGIN_MESSAGE_MAP (CParentWindow, CFrameWnd)
ON_WM_PAINT ()
//ON_BN_CLICKED(ID_DRAW_CIRCLE,DrawCircle)
//ON_BN_CLICKED(ID_DRAW_SQUARE,DrawSquare)
// ON_UPDATE_COMMAND_UI (ID_DRAW_CIRCLE,DrawCircle)
//ON_UPDATE_COMMAND_UI (ID_DRAW_SQUARE,DrawSquare)
ON_COMMAND(ID_SQUARE,DrawSquare)
ON_COMMAND (ID_CIRCLE,DrawCircle)
//ON_COMMAND (ID_DRAW_SQUARE,DrawSquare)
END_MESSAGE_MAP ()
CParentWindow::CParentWindow ()
{
//Create (NULL, _T ("Sample Application"));
// Create (NULL, _T ("sample Application"), WS_OVERLAPPEDWINDOW,
//rectDefault, NULL, MAKEINTRESOURCE (IDR_MENU1));
flag=0;
LoadFrame(IDR_MENU1,WS_OVERLAPPEDWINDOW, NULL, NULL);
/*CMenu menu;
menu.LoadMenu (IDR_MENU1);
SetMenu (&menu);
menu.Detach ();*/
}
void CParentWindow::OnPaint ()
{
/*CPaintDC dc(this);
CRect rect;
GetClientRect (&rect);
dc.DrawText (_T (""), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
*/
if(flag==1)
{
CMenu* circleMenu=GetMenu();
CString h;
// circleMenu->ModifyMenu (ID_SQUARE, MF_STRING | MF_BYCOMMAND,
// ID_SQUARE, "&Square");
// circleMenu->DeleteMenu(1,MF_BYPOSITION);
//circleMenu->InsertMenu(1,MF_BYPOSITION,ID_SQUARE,"&new");
CPaintDC paint(this);
CRect rect;
GetClientRect (&rect);
int var1 = rect.Width () / 2;
int var2 = rect.Height () / 2;
CRect cir (var1 - 60, var2 - 60, var1 + 60, var2 + 60);
CBrush c (RGB(255,255,255));
CBrush* d = paint.SelectObject (&c);
paint.Ellipse (cir);
paint.SelectObject(d);
//h=this->m_hWnd;
//InvalidateRect(h, NULL, TRUE);
circleMenu->DeleteMenu(0,MF_BYPOSITION);
circleMenu->InsertMenu(0,MF_BYPOSITION,ID_SQUARE,"Square");
// flag=2;
}
else if(flag==2)
{
CMenu* circleMenu;
circleMenu=GetMenu();
/* circleMenu->ModifyMenu (ID_SQUARE, MF_STRING | MF_BYCOMMAND,
ID_CIRCLE, "&Circle");
*/
// circleMenu->ModifyMenu (ID_SQUARE, MF_STRING | MF_BYCOMMAND,
// ID_SQUARE, "&Circle");
CPaintDC paint(this);
CRect rect;
GetClientRect (&rect);
int var1 = rect.Width () / 2;
int var2 = rect.Height () / 2;
CRect rec (var1 - 60, var2 - 60, var1 + 60, var2 + 60);
CBrush c (RGB(255,255,255));
CBrush* d = paint.SelectObject (&c);
paint.Rectangle (rec);
paint.SelectObject(d);
circleMenu->DeleteMenu(0,MF_BYPOSITION);
circleMenu->InsertMenu(0,MF_BYPOSITION,ID_SQUARE,"Circle");
//flag=1;
}
}
void CParentWindow: rawCircle()
{
Invalidate();
CMenu* circleMenu=GetMenu();
if(str=="Circle")
{
// circleMenu->GetMenuString(ID_SQUARE,h,MF_BYPOSITION);
//circleMenu->CheckMenuItem(ID_DRAW_CIRCLE, MF_CHECKED);
//circleMenu->CheckMenuItem(ID_DRAW_SQUARE, MF_UNCHECKED);
// circleMenu->CheckMenuRadioItem(ID_DRAW_CIRCLE,ID_DRAW_SQUARE,ID_DRAW_CIRCLE,MF_BYCOMMAND);
//(GetMenu()->CheckMenuItem(
// ID_DRAW_SQUARE,
// MF_UNCHECKED
// );
flag=1;
Invalidate();
//OnPaint();
//pCmdUI->SetCheck(1);
//OnPaint();
//CPoint points[3];
}
else
{
this->DrawSquare();
}
}
void CParentWindow: rawSquare()
{
Invalidate();
CMenu* circleMenu;
circleMenu=GetMenu();
circleMenu->GetMenuString(ID_SQUARE,str,MF_BYCOMMAND);
if(str=="Square")
{
//circleMenu->CheckMenuItem(ID_DRAW_SQUARE, MF_CHECKED);
//circleMenu->CheckMenuItem(ID_DRAW_CIRCLE, MF_UNCHECKED);
// circleMenu->CheckMenuRadioItem(ID_DRAW_CIRCLE,ID_DRAW_SQUARE,ID_DRAW_SQUARE,MF_BYCOMMAND);
//circleMenu->ModifyMenu (ID_SQUARE, MF_STRING | MF_BYCOMMAND,
//ID_DRAW_SQUARE, "&Circle");
//circleMenu->ModifyMenu (2, MF_STRING ¦ MF_BYPOSITION,
//ID_DRAW_CIRCLE, "&NEW2");
flag=2;
Invalidate();
}
else
{
this->DrawCircle();
}
}
code[/]
-
October 6th, 2005, 04:56 AM
#6
Re: how to update or refresh the menu?
And how is this a Win32 app? This MFC all day long. And I see you've tried the updateui mechanism.
Har Har
-
October 6th, 2005, 05:04 AM
#7
Re: how to update or refresh the menu?
padex ,
all are handled by my, i created MFC application in win32 application. everything was hand written by me, thats only certain things such as control variable is not available here
-
October 6th, 2005, 10:57 AM
#8
Re: how to update or refresh the menu?
If your updating a menu which is currenty selected into a window you need to call DrawMenuBar(HWND) to cause it to refresh.
Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
Please remember to rate useful answers. It lets us know when a question has been answered.
-
October 6th, 2005, 12:14 PM
#9
Re: how to update or refresh the menu?
tamsel, please use code tags properly. See my signature below on how to use. Please use Testing area to experiment
-
October 6th, 2005, 12:55 PM
#10
Re: how to update or refresh the menu?
kirants , i wll surely follow that.
but that drawmenubar() is not repainting the menu. where that DrawMenuBar() can be called?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|