[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Switching Menus in dialog based appliaction at runtime

Posted on 2000-02-10
9
Medium Priority
?
313 Views
Last Modified: 2013-11-20
I'm writing an vc++ application that support 4 languages (user may change it at runtime).
I solved this for dialogs, string tables and other ressources by creating a separate resource dll for all four languages. When the user changes the language, the applicable dll is loaded and all resources are used from this dll.

The problem is, that this doesn't seem to work with menus. I need some advice (best with source code fragments) on how to switch menus (not modifying) from one ressource to another.
Second problem is that if I try to load another menu with
hMyMenu = LoadMenu(tmp->GetResHandle(), "IDR_MAIN_MENU\r\n"); or  hMyMenu = LoadMenu(tmp->GetResHandle(), MAKEITRESOURCE(IDR_MAIN_MENU));
I always get back a NULL pointer.
tmp->GetResHandle() returns a handle to the active resource dll and it works fine to load string table entries with LoadString(...).

Does anyone have a good suggestion to this problem
0
Comment
Question by:UandI
  • 3
  • 3
  • 3
9 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2507005
Hi Uandl,

What does GetLastError() return when the LoadMenu call fails? Is the IDR_MAIN_MENU defined in the dll's resource.h or in the application's resource.h. If defined in both, are the defined values identical?

Try if finding and loading of the resource is working via FindResource(Ex)()/LoadResource().

ZOPPO
0
 

Author Comment

by:UandI
ID: 2507062
GetLastError() returns 1814.
The IDR_MAIN_MENU is defined in the application's resouce.h and in all of the dll's resource.h identical. The difference I make is by the ResourceHandle. The values ind IDR_MAIN_MENU resources have the same menu structure but not the same values (different languages).

GetLastError() returns 998 after the LoadResource() call.

How can I access the menu loaded to global memory with LoadResource()?

Thank for your help!
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 400 total points
ID: 2507150
1814 (ERROR_RESOURCE_NAME_NOT_FOUND) means a resource with this name cannot be found.

998 (ERROR_NOACCESS) means an invalid access to a memory location occured.

Try calling LoadMenu(..., "IDR_MAIN_MENU" ) // without the "\r\n"

>are the defined values identical
I meant the defined values in resource.h, like this:
#define IDR_MAIN_MENU xyz
must be equal for the application and all dll's


Another thing:
are the resources in the dll's from the same language or different languages, i.e:
if you have english and french resources, did you set the resource's language property to 'english' and 'french' or both to 'default'.

ZOPPO
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
LVL 12

Expert Comment

by:migel
ID: 2507180
Hi!
in MSDN:
1814 - The specified resource name cannot be found in the image file.
check your resource DLL!
you can open it by the MSVC (as "file type" exe and "open as" resource)
0
 

Author Comment

by:UandI
ID: 2507305
Hi migel!
Could you be a little more specific. I didn't understand what you meant with
>you can open it by the MSVC (as "file type" exe and "open as" resource)

Hi ZOPPO!
I'm not using the laguage attributes. I've set all the language properties to 'neutral'. I've checked the resource.h files and set them all to the same xyz value (130). They now all look the same: #define IDR_MAIN_MENU 130
I've also tried Try calling LoadMenu(..., "IDR_MAIN_MENU" ) // without the "\r\n"  but it didn't help as well.

Maybe you've got some more ideas?

Thanks!
 
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2507333
You could mail me your complete project so I could try to debug into it and find the problem ... unfortunately I have no better idea now

zoppo@cdsgmbh.de
0
 
LVL 12

Expert Comment

by:migel
ID: 2507456
Hi:
that is in the MSVC you choose :
File|Open
in the appeared dialog box choose dll you need, and in the "Open As" combo select "Resource" type
0
 

Author Comment

by:UandI
ID: 2507568
I checked all the stuff again, set all the resource.h id's to the same value, recompiled all the dll's once more and finally got it right with the following code:
      HMENU      hMyMenu;
      hMyMenu = LoadMenu(tmp->GetResHandle(), MAKEINTRESOURCE(IDR_MAIN_MENU));
      ::SetMenu((tmp->GetMainWnd())->m_hWnd, hMyMenu);
0
 
LVL 12

Expert Comment

by:migel
ID: 2507774
Hi:
that is in the MSVC you choose :
File|Open
in the appeared dialog box choose dll you need, and in the "Open As" combo select "Resource" type
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question