Solved

Again: AfxSetResourceHandle() and non modal dialog boxes

Posted on 1998-07-21
9
513 Views
Last Modified: 2013-11-20
Hi, I post this question again, because you cannot login to the old question !!!

Question was:
In my program I can load dynamically by clicking some selfmade menu entries in menu an extern resource dll for updating my menus and dialog boxes to a foreign language. Everything works great, all the updating of menus, tooltips, dialog boxes and so on. I call AfxSetResourceHandle(languagedll) after loading my language dll. But if there is a non modal dialog box displayed, how can I refresh this dialog box to switch to the loaded language without destroying the dialog box and displaying it again ?

Is there any possibility to do so ?
Thanks a lot.
0
Comment
Question by:atari
  • 3
  • 3
  • 3
9 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1319492
I don't think it is possible.
0
 
LVL 2

Accepted Solution

by:
danyell earned 200 total points
ID: 1319493
I assume the open modeless dialog is created in your own code (not in some DLL you cannot modify). There are a couple ways I can think of to do what you want, here are two:

1. Subclass the controls in your dialog to accept an additional control message that forces them to reload, e.g., text strings from the current resource handle (this makes each control smart so you can do it selectively) - you can then use the MFC function that sends a command message to all controls in a dialog (I forget the name off the top of my head); or

2. You can clone some MFC code (the part that binds dialog controls to MFC objects) and rewrite it to accomplish this at the dialog level -- that is, destroy every control in the dialog and recreate it at the same position with the (new) current res handle. Then add a custom (WM_USER + N) message handler to the dialog window (C++) class itself that invokes this control-recreate logic.

I would probably go with the 2nd approach for most applications but I'm presenting both since you know your app's requirements and I don't. In one app where I needed this kind of redraw capability, I actually settled for destroy+(re)create the entire dialog and the user feedback was that that was OK.

I realize this is somewhat sketchy, let me know if you need more detail.

0
 
LVL 2

Expert Comment

by:danyell
ID: 1319494
Oops I forgot to check the e-mail notification box! There...
0
 
LVL 1

Author Comment

by:atari
ID: 1319495
Whom shall I believe now, chensu with so much points or danyell ? I think, that is the limit of AfxSetResourceHandle(), the only choice is to save the settings of your dialogbox in some local variables, then destroy the dialog box and create it again and put all the settings back. Yes, you could give an ID to every item in the dialog box, but there are a lot of IDC_STATICS.

Reduce points, because I believe, what chensu said.

Thanks.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 23

Expert Comment

by:chensu
ID: 1319496
First, don't have blind faith in my points. Nobody is proficient in every area. I might be wrong.

Regarding danyell's solution, I am wondering how to get the resource for each control in the dialog box and recreate it according to the resource. I would say that is very tough if possible. It seems that I am talking about each dialog box with a dialog template while danyell is saying each control in a dialog box is responsible for its own resources. And the layout (each control's position and size) of a dialog box in one language might be different from the one in another language.
0
 
LVL 1

Author Comment

by:atari
ID: 1319497
Think, we don't get any answer any more, because I spend the points, and the problem was, that I could not reduce the points. Sorry, I would have given the points to you, but then I had to give the question free for others to answer, but in between I discussed to some other with the above problem, and they also said, that there is no solution for it. So I wanted to free the question from discussion-board.

Thanks, chensu
atari
0
 
LVL 2

Expert Comment

by:danyell
ID: 1319498
I seem to remember an MS knowledgebase article on this subject, regarding resource-management techniques for localization. The broader question atari is asking, in a way, is about using dynamic dialog boxes combined with resource templates.

chensu makes a good point about layout potentially changing from one language/locale to another. A better way to address the broader issue, perhaps, is to develop a custom MFC class for the client area of the dialog-box window. You may also consider creating your own window class that *simulates* modeless dialog boxes as far as persistence, z-order and other features go, but would still in fact be regular windows with regular message-pump access in every other respect. This is not absolutely necessary but I'm guessing it would simplify code overall if you choose to implement the custom client-area window class.

I actually used the above technique on a video editing application with a complex GUI, with considerable success.

As far as knowledge goes, it is clear that chensu is very qualified, however his points on this site prove only that chensu has been active on experts-exchange.com longer than I have. I only started using this site 3 days ago! But, I have been developing MFC apps since MS C 6.0 -- that's the version before Visual C++ 1.0. So, I'm sorry I couldn't help more in this case, but for your own benefit you should try not to jump to conclusions about people's expertise based solely on their points in this system.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319499
If you really don't want to destroy the dialog box and recreate it, danyell's solution is very good for you.


>however his points on this site prove only that chensu has been active on experts-exchange.com longer than I have.

Yes, I think so. I always think that the points system is unfair for newcomers. But as long as you insist on it, you will be the top one.

>I have been developing MFC apps since MS C 6.0 -- that's the version before Visual C++ 1.0.

Microsoft C 6.0 didn't come with MFC, it was a C compiler not C++ compiler. What you wanted to say is Microsoft C/C++ 7.0, which came with MFC 1.0.

>for your own benefit you should try not to jump to conclusions about people's expertise based solely on their points in this system.

I fully agree.

0
 
LVL 1

Author Comment

by:atari
ID: 1319500
Haven't seen that the discussion is going on. Where it all started was the codeguru-website. There is an interesting sample program called 'scribble multilanguage'. So far we had written our resource-dll's and could switch only at program start to the desired language by reading a flag somewhere in the .ini-file. Implementing parts of the above example I was possible to switch dynamically by selecting a menu entry to the desired language. But the problems occured afterwards, because the above example wasn't complete. I came to the problem with non modal dialog boxes. And because the texts for example in English are sometimes shorter than for example texts in German (my home country) it isn't so simple only to change all the texts in dialog box, you have also update the positions of all texts, therefore the resource-template of the dialog box taken from the language dll. I have only 1 year experience with mfc, the above discussion was on a very high level, but very theoretically for a beginner, so where can I find any example for a 'custom client-area window class', or how can I write my own class for simulating modal dialogboxes. Are there any examples on the internet available ? It sounds very hard, maybe so hard as to subclass the CFileDialog for implementing image-previews or inserting own controls.

>for your own benefit you should try not to jump to conclusions about people's expertise based
   solely on their points in this system.

I think, I should, because it seems to me very logically, the lot of points are resulting not from nowhere. But I think you could also have experience in programming if you don't have so much points. Look at me, I'm a newcomer to mfc, but I have over 10 years programming experience in writing technical software for a company.

The customer are very unfair, because a lot of them don't grade the answers, that were given. And it is allowed to look inside all the locked answers for free, so it is possible to get good answers for free. Also you have only a choice to get much points, if you are online for a lot of time and not only for a few hours.

Thanks so far,
bye,
atari
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now