GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 21-Feb-2005, 21:06
kumaran kumaran is offline
Junior Member
 
Join Date: Dec 2004
Posts: 31
kumaran is on a distinguished road

menu creation


hi ,
i want to know how to link a newly created menu with the coding written
on OnDraw function.

in detail:

i made a grid using on draw function and i need to create a menu,
let me label it as 'diagram' which has cells as 'ondraw' 'indraw' where if i
click 'ondraw' cell the particular grid should be displayed.
pls tell me how.
  #2  
Old 21-Feb-2005, 22:01
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
I think no one rplys to your original post because thay can't help without you decribing in more detail what actually you want to do...

is it dialog or sdi application?? is it a context menu or you want to rplace the main menu??? and what is it you do in the OnDraw function that you want to link to...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #3  
Old 22-Feb-2005, 01:40
kumaran kumaran is offline
Junior Member
 
Join Date: Dec 2004
Posts: 31
kumaran is on a distinguished road
Quote:
Originally Posted by Max Payne
I think no one rplys to your original post because thay can't help without you decribing in more detail what actually you want to do...

is it dialog or sdi application?? is it a context menu or you want to rplace the main menu??? and what is it you do in the OnDraw function that you want to link to...


it is an SDI application. i created a context menu. in the ondraw function i drew up a grid. i want to know how to display the grid if i clk a cell,by name grid, in the menu.pls tell me
  #4  
Old 22-Feb-2005, 21:43
kumaran kumaran is offline
Junior Member
 
Join Date: Dec 2004
Posts: 31
kumaran is on a distinguished road
hi
im repeating the same problem,someone pls help me. mine is an SDI appln.
i created a context menu. i had a cell in that context menu by name 'grid'
on clicking which i should get a grid drawn. i have already written the coding
for the grid in the 'ondraw' function of view class. so now i need to know how
to call it. hope im clear. pls reply me.
  #5  
Old 23-Feb-2005, 19:12
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Hi,

for a context menu, there is a function which handles the contect menu creation and manipulation.its called the OnContextMenu, open your class wizard and search for this function and add it to your proect..

CPP / C++ / C Code:
void CContextView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
	ClientToScreen(&point);
	CMenu Menu;
	Menu.CreatePopupMenu();
	Menu.InsertMenu(1, MF_BYPOSITION, ID_FIRST, "First");
	Menu.InsertMenu(2, MF_BYPOSITION, ID_SECOND, "Second");
	Menu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
}

the above example is for creating a menu without using the resource editor, here is an example of how to create a menu from the resourse editor..

CPP / C++ / C Code:
void CContextView::OnContextMenu(CWnd* pWnd, CPoint pt) 
{
	// TODO: Add your message handler code here
	ClientToScreen(&pt);
	CMenu Menu;
             Menu.LoadMenu(IDR_CONTEXT_MENU);
	Menu.GetSubMenu(0)->TrackPopupMenu(TPM_CENTERALIGN|TPM_RIGHTBUTTON,pt.x,pt.y,this);
		
            
	Menu.TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this);
}

now how do you handle mesage for each menu item, ID_FIRST, and ID_SECOND?? put it in your message map..

CPP / C++ / C Code:
BEGIN_MESSAGE_MAP(CContextMenuSDIDemoView, CView)
	//{{AFX_MSG_MAP(CContextMenuSDIDemoView)
	ON_COMMAND(ID_FIRST, OnTestFirst)
	ON_COMMAND(ID_SCOND, OnTestSecond)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CContextMenuSDIDemoView::OnTestFirst() 
{
	// TODO: Add your command handler code here
	Show your grid 1 here
}

void CContextMenuSDIDemoView::OnTestSecond() 
{
	// TODO: Add your command handler code here
	show your grid 2 here
}

BTW: the code above might not run properly, since I don't have a VC++ on my pc to test it, so use it as a guide...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #6  
Old 24-Feb-2005, 00:09
kumaran kumaran is offline
Junior Member
 
Join Date: Dec 2004
Posts: 31
kumaran is on a distinguished road
hi,
thanks a lot. i want 2 know how to call the ondraw function of viewclass
if i click the menu which i created.while trying that i got 3 error which i
have mentioned below:

error C2143: syntax error : missing ';' before '*'
error C2501: 'CSamDoc' : missing storage-class or type specifiers
error C2501: 'GetDocument' : missing storage-class or type specifiers

i've declared the viewclass header file in the corresponding class of the
resource. i donno whether is it rcorrect or not.

iam beginner in vc++, so if u find any of
my doubts to be silly pls bear with me.
  #7  
Old 24-Feb-2005, 00:53
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
First: don't call your OnDraw function on your own, it is reserver for the windows to call on event of WM_PAINT !!

can you post what code is in the OnDraw function, maybe we can figure out to write the code on another function, not in OnDraw.

and also post the line of code which produce the error. and also where did you include the view class header file??

Quote:
iam beginner in vc++, so if u find any of
my doubts to be silly pls bear with me.

i don't find your doubt is silly, but you should be more detail in xplaining your problem, no one is a magician here who could guess and figure out your problems... you must explaine in detail, what you want to do, post some of your codes involved...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #8  
Old 24-Feb-2005, 02:29
kumaran kumaran is offline
Junior Member
 
Join Date: Dec 2004
Posts: 31
kumaran is on a distinguished road
hi
to write the entire coding, that is in my ondraw function, here will be too lengthy. to tell u wats there,it is just to print a grid(simply by using MOVETO,LINETO etc).

the code that produces error is in samview.h file('sam' is my proj name)
it is as follows.

public:
CSamDoc* GetDocument(); --all three errors which i said earlier points to this line only.



i included the view class header file in the mainframe.cpp file. as the menu which i created is in the mainframe class.

i wanted to know how to print the grid if i click the menu. i mainly want to know how to call ondraw function when i click the menu.
  #9  
Old 24-Feb-2005, 02:53
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Ok, figure how to clear the error first:

your context menu is for your view right? so put your context menu in your view class, don't touch the mainframe class, so no need to include the view class there, and move your code for the context mnu to the view class..

Now, OnDraw should not be called directly, so make a new function say "DrawGrid()" and cut and paste the code in OnDraw to the new function, then call that function from your OnDraw()..

and onCommand for the context menu, call also the DrawGrid function..

did that solve your problem? if no, please post your coding, or attach the file involved..
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #10  
Old 24-Feb-2005, 03:04
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
BTW: I recomended the context menu is handled in the view class becaus its supposed to be the context menu for the view, and its a lot neater handling it from the view class...

but you also can proceed what youre doing but then itll be a litle messy as you have to call the memberfunction of the view class from the mainframe by casting pointer to the class...

so, if you want to manage the context menu in the mainframe.. just

#include "CSamDoc.h"
#include "CSamView.h"

to the mainframe.cpp.
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Photoshop Tutorial: Make An Inspirational/Mystical Picture ToddSAFM Graphics Forum 9 09-Aug-2005 20:32
Popup menu gavrile MS Visual C++ / MFC Forum 8 12-Aug-2004 01:50
javascript menu dopee Web Design Forum 7 30-Jul-2004 23:22
Great way to disable flash rightclick menu BobbyDouglas Web Design Forum 0 02-Sep-2003 18:23
top menu bar trouble chalaska Web Design Forum 3 18-Jul-2002 21:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:43.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.