Again: AfxSetResourceHandle() and non modal dialog boxes

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.
Who is Participating?
danyellConnect With a Mentor Commented:
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.

I don't think it is possible.
Oops I forgot to check the e-mail notification box! There...
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

atariAuthor Commented:
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.

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.
atariAuthor Commented:
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
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 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.

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 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.

atariAuthor Commented:
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,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.