Click here to Skip to main content
15,899,679 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to realize Multi-Chat application? Pin
bruspark28-May-06 19:22
bruspark28-May-06 19:22 
GeneralRe: How to realize Multi-Chat application? Pin
bob1697228-May-06 20:37
bob1697228-May-06 20:37 
GeneralRe: How to realize Multi-Chat application? Pin
bruspark29-May-06 18:12
bruspark29-May-06 18:12 
QuestionHow to add WndPRoc function to an windows Service application Pin
bmurali28-May-06 17:49
bmurali28-May-06 17:49 
QuestionHow to get the menu of the ChildFrame in MDI Pin
raycadarena28-May-06 16:23
raycadarena28-May-06 16:23 
AnswerRe: How to get the menu of the ChildFrame in MDI [modified] Pin
bob1697228-May-06 17:03
bob1697228-May-06 17:03 
GeneralRe: How to get the menu of the ChildFrame in MDI [modified] Pin
raycadarena28-May-06 20:07
raycadarena28-May-06 20:07 
GeneralRe: How to get the menu of the ChildFrame in MDI [modified] Pin
bob1697229-May-06 7:34
bob1697229-May-06 7:34 
The different templates would ideally each have their own menu resource and toolbar resource. Some menu/toolbar items would be common to all and some unique.

m_pDoc1Template = new CMultiDocTemplate(
IDR_YOUR_RESOURCE_1,
RUNTIME_CLASS(CYourDoc1),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CYourView1));
AddDocTemplate(m_pDoc1Template);

m_pDoc2Template = new CMultiDocTemplate(
IDR_YOUR_RESOURCE_2,
RUNTIME_CLASS(CYourDoc2),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CYourView2));
AddDocTemplate(m_pDoc2Template);

When you click on a document view, the corresponding menu/toolbar should show. Setting up handlers for the resource Id's is the same as usual: choose a class that will handle a message, and then using the wizard or whatever they call it the version of VC++ your using, to set up those handlers.

If you want to manipulate those menu's further like adding or removing items, any code in any one of your view classes can assume (normally) that the corresponding menu resource is being used by the parent frame so you can simply use

CMenu* pMenu=AfxGetMainWnd()->GetMenu();

from your view class to get the pointer to that menu. Some of what I use was influenced by Roger Allens article on menus here at CP.

I choose to find the submenu's by looking for the menu string since I insert menu items which effectively changes the index.

Something like...

CMenu* pMenu=AfxGetMainWnd()->GetMenu();
CString sMenuText="SomeMenuText"; // The menu text to search for
CString sTemp="";

if (pMenu) {
UINT uiCount=pMenu->GetMenuItemCount();
for (UINT i=0;i<uiCount;++i) {
pMenu->GetMenuString(i,sTemp,MF_BYPOSITION);
if (sTemp==sMenuText) {
// Found it. If you are adding/removing
// menus then do not store this index for later
// use as it might not be valid further down
// the road.
}
}
}

To insert a submenu, something like

CMenu menuPopup;
CString sMenuText="Some name for it";
// NOTE: nPosition is assumed to be the index (i) of menu item just before
// where you want to insert this. Usually the value of "i" in code above

menuPopup.CreatePopupMenu();
pMenu->InsertMenu(nPosition+1,MF_BYPOSITION|MF_POPUP,(UINT)menuPopup.Detach(),sMenuText);

Adding submenu items is a bit more tricky as you will have to ensure you have some COMMAND_ID's set aside for them. These can be added in the "Resource Symbols" section in VC++ 6.0 and the corresponding section for other version of VC++.

The book "Professional MFC With Visual C++ 6" by Mike Blaszczak was a lifesaver for this part. I would highly recommend it for this type of project as he gets into the nitty gritty of MFC specific stuff.

Inserting the items into a submenu...
pSubMenu->AppendMenu(MF_STRING,/*Resource ID goes here */,"Subitem text");

Deleting an item from a submenu...
pMenu->DeleteMenu(/*resource ID goes here*/,MF_BYCOMMAND);

Refresh. After any visible change you need to call...
AfxGetMainWnd()->DrawMenuBar(); // Refresh

I set up my handlers in an odd way using a contiguous range of const'ed resource ID's since I don't know what the menu item text or how many will be given to me to show. I intercept the OnCmdMsg and process them based on there offset from the start of the resource ID range set aside.

You probably won't need to do this as you'll likely know ahead of time what your Resource ID's are. I am assuming you can just set up handlers for those Resource ID's as usual but I have not verified this. Mike Blaszczak's book covers the issues with the OnCmdMsg approach if your menu's are unknown at compile time.

Also, it's been a while, but I think there are some "gotcha's" with refreshing and switching between documents when jacking with the menu's dynamically like that. There's a lot of code dedicated to refreshing those menus so I will assume I responded to a few of those with whatever duct tape was necessary in my problem context.

I apologize for my lack of preparedness for this response. I'm kinda realizing that I bit off more than I could chew since it would probably be easier to just send the whole program. I hope some of it at least helps get you closer to your goals.
QuestionHow i make a scroll bar to scroll down by itself? Pin
Immunity1828-May-06 14:14
Immunity1828-May-06 14:14 
AnswerRe: How i make a scroll bar to scroll down by itself? Pin
bob1697228-May-06 14:30
bob1697228-May-06 14:30 
GeneralRe: How i make a scroll bar to scroll down by itself? [modified] Pin
Immunity1828-May-06 14:36
Immunity1828-May-06 14:36 
GeneralRe: How i make a scroll bar to scroll down by itself? [modified] Pin
bob1697228-May-06 15:01
bob1697228-May-06 15:01 
GeneralRe: How i make a scroll bar to scroll down by itself? [modified] Pin
Immunity1828-May-06 15:06
Immunity1828-May-06 15:06 
GeneralRe: How i make a scroll bar to scroll down by itself? [modified] Pin
bob1697228-May-06 15:27
bob1697228-May-06 15:27 
GeneralRe: How i make a scroll bar to scroll down by itself? [modified] Pin
Immunity1828-May-06 15:32
Immunity1828-May-06 15:32 
GeneralRe: How i make a scroll bar to scroll down by itself? [modified] Pin
bob1697228-May-06 16:40
bob1697228-May-06 16:40 
QuestionProblem writing large character array to a file Pin
fourierman28-May-06 13:20
fourierman28-May-06 13:20 
AnswerRe: Problem writing large character array to a file [modified] Pin
Chris Losinger28-May-06 13:23
professionalChris Losinger28-May-06 13:23 
GeneralRe: Problem writing large character array to a file [modified] Pin
bob1697228-May-06 14:12
bob1697228-May-06 14:12 
AnswerRe: Problem writing large character array to a file [modified] Pin
bob1697228-May-06 14:17
bob1697228-May-06 14:17 
GeneralRe: Problem writing large character array to a file [modified] Pin
fourierman28-May-06 14:35
fourierman28-May-06 14:35 
GeneralRe: Problem writing large character array to a file [modified] Pin
Chris Losinger28-May-06 16:06
professionalChris Losinger28-May-06 16:06 
AnswerRe: Problem writing large character array to a file Pin
kakan28-May-06 20:49
professionalkakan28-May-06 20:49 
GeneralRe: Problem writing large character array to a file Pin
fourierman29-May-06 10:15
fourierman29-May-06 10:15 
GeneralRe: Problem writing large character array to a file Pin
kakan29-May-06 19:39
professionalkakan29-May-06 19:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.