How to get the resource ID of a frame window?

G

Guest

Hey All,

After a doc/view/frame is created and initialized, is there a way from
within the frame class code (CMyChildFrame::OnUpdateFrameMenu()) to get the
resource ID (nIDResource = IDR_???TYPE) used by CFrameWnd::LoadFrame()?

I know the member variable m_nIDHelp is set to nIDResource in the
LoadFrame() call, but don't feel that is a safe way to retrieve the resource
ID. So I was hoping there was an API that I could call to get the resource ID
that was used by the frame to load the menu, icon, and string table. I need
to dynamically reload the frames menu at runtime after the frame has alrady
been created in order to alter it. I am trying to avoid passing this in as a
new parameter to the constructor and I have tried to make the call GetMenu()
from inside of OnUpdateFrameMenu() but get an exception.

Thanks for any help,
Danny
 
G

Gary Chang[MSFT]

Hi Danny,
I know the member variable m_nIDHelp is set to nIDResource in the
LoadFrame() call, but don't feel that is a safe way to retrieve the resource
ID. So I was hoping there was an API that I could call to get the resource ID
that was used by the frame to load the menu, icon, and string table. I need
to dynamically reload the frames menu at runtime after the frame has alrady
been created in order to alter it.

Based on my understanding, you do not want to use the m_nIDHelp directly
to retrieve the resource IDs which used by the CFrameWnd::LoadFrame() call,
please correct me if I have misunderstood anything.

In this scenario, since the resource ID is unique in the application, do
you have tried to use a UINT array to cache the nIDResource parameter of
the CMyChildFrame::LoadFrame() call...

If you prefer a Win32 API to do this, the EnumResourceNames API is an
option, but at first you need to know what and which types of these
resources you wanted...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/resources/introductiontoresources/resourcereference/re
sourcefunctions/enumresourcenames.asp


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Based on my understanding, you do not want to use the m_nIDHelp directly
to retrieve the resource IDs which used by the CFrameWnd::LoadFrame() call,
please correct me if I have misunderstood anything.

In this scenario, since the resource ID is unique in the application, do
you have tried to use a UINT array to cache the nIDResource parameter of
the CMyChildFrame::LoadFrame() call...

If you prefer a Win32 API to do this, the EnumResourceNames API is an
option, but at first you need to know what and which types of these
resources you wanted...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui
/windowsuserinterface/resources/introductiontoresources/resourcereference/re
sourcefunctions/enumresourcenames.asp

Yes, I am afraid to use the m_nIDHelp because it is possible that it may get
changed without my knowledge. And it also is not intended as a place holder
for referencing the resource ID used to load the menu, icon and string table.
To the best of my understanding it is used as a base/offset into the help
context.

The EnumResourceNames API requires knowledge of the resource you are trying
to access, which in turn would require me to pass something in the
constructor. I do not want to require the developers to do this.

As a solution, I have derived my own class (CMyChildFrame) from CMDIChildWnd
and did an override of LoadFrame(), in LoadFrame() I saved the nIDResource
value to a member variable (m_IdrFrameTypeResourceId). During
OnUpdateFrameMenu(), I then use the m_IdrFrameTypeResourceId to load the menu
from the resources. Now the developers are not required to make any code
modifications.

FYI: Here's what I am doing:
====================
When a new doc/view/frame is opened by the user, I am merging the main frame
menu with my child frames menu. This allows me to have an independent main
frame menu that the developers can modify as needed and not have to update
all the individual child frame menus. The child frame menu only contains menu
items releated to that doc/view/frame. This app will end up having around 30
to 40 doc/view/frame components in it.

The IDR_MAINFRAME menu: File View Help
My IDR_MYFRAME menu: Actions Window
Merged menu: File View Actions Window Help

Everything works great now, and is very automated, except for one thing, the
'Windows' menu item (which is the standard one) does not show the open files
anymore. So I'm trying to find out when the open files list is updated on the
menu item, so I can merge the menus at the appropriate time.

Here's the code snippet:

void CGuiPanelChildFrame::OnUpdateFrameMenu(BOOL bActive, CWnd* pActiveWnd,
HMENU hMenuAlt)
{
CMDIChildWnd::OnUpdateFrameMenu(bActive, pActiveWnd, hMenuAlt);

if( bActive == TRUE )
{
CMenu MainMenu;
if( MainMenu.LoadMenu( IDR_MAINFRAME ) == 0 )
return;

CMenu GuiPanelMenu;
if( GuiPanelMenu.LoadMenu( m_IdrFrameTypeResourceId ) == 0 )
return;

if( MergeMenu( &MainMenu, &GuiPanelMenu, true ) == false ) //
codeproject.com
return;

if( AfxGetMainWnd()->SetMenu( &MainMenu ) == 0 )
return;

MainMenu.Detach();
}
}


Thanks for your help and any advice,
Danny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top