|
#1
|
|||
|
|||
|
Setting focus to a message box
Hi ,
I am creating a message box for the following scenario. One s/w is getting installed.During installation a pop up message box is coming asking whether to add some feature.The message box is having only 2 options.Yes/No.The problem happens over here.The message box is getting displayed.But the focus is still in the parent window.I have tried Setfocus(::GetActiveWindow());But its not working.Any suggestions? |
|
#2
|
||||
|
||||
|
What code are you using to display the message box?
__________________
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section. ![]() Please use [Code]your code goes in here[/Code] tags when posting code. Before posting your question, did you look here? Got a question on Linux? Visit our Linux sister site. Modifications Required For VB6 Apps To Work On Vista ![]() Microsoft MVP 2005/2006/2007/2008/2009 |
|
#3
|
|||
|
|||
|
The code I have used is as below
Code:
MessageBox( ::GetActiveWindow(),strSoftInstMSg,strCaption, MB_YESNO|MB_SYSTEMMODAL |MB_DEFBUTTON1 ) |
|
#4
|
|||
|
|||
|
A normal message box is normally modal, unless the program is doing something odd to prevent this (always on top main window, borderless or unmovable windows, certain thread like activity, or, well, odd stuff!).
A simple MessageBox("Hit Yes and stuff!"); *should*, if everything is normal, pop up a message box "modally" (that means it jacks control and the only thing you can do is move the message box around until you hit yes or no) that behaves the way you expect. You should not need all those fancy parameters to accomplish this task. If that does not work, we have to figure out why first. Lets get that far, and we can worry about system modal after. System modal is normally bad, you reserve it for extremely critical things. Word's message about saving your file over the old one should not prevent you from opening your internet browser, and thats what system modal does, it makes un-related programs affect each other, in a very bad way. Are you sure you want to do this? Last edited by jonnin; 11-04-2009 at 10:52 AM. |
|
#5
|
|||
|
|||
|
But here what you have specified about system modal is not exactly what it does in my program.Its not behaving as "save as a file" window which exactly what I need.I tried to figure out why its not working in many ways and tried putting the handle of the installation window as the first parameter in messagebox.It was working for the first time but later it gave memory leak errors.The following is the change that I made in the code.
[code] HWND hWind=NULL; hWind = GetActiveWindow(); MessageBox( hWind,strSoftInstMSg,strCaption, MB_YESNO | MB_SYSTEMMODAL );[\Code] I am new in MFC.I might be wrong in the usage of certain parameters.Please correct me if I am wrong. |
|
#6
|
|||
|
|||
|
It looks fine to me. How do you know it has a memory leak? There should not be one caused by this code, but certain memory check tools may be confused by your void * being assigned and not freed (which is correct, it should NOT be freed).
If this code works for you, it should be fine. If you really believe the tool that it causes a memory leak, trace it out to see (this is extremely frustrating and time consuming). You may have one (perhaps the strings used in the messagebox are broken or something) but I do not see one from the small code sample you gave. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MSN Message Box | THL | C++ | 0 | 10-13-2005 03:18 AM |
| Setting focus to a text box | cmoore | Web | 1 | 06-21-2001 11:25 AM |
| Setting focus to a text box | cmoore | Web | 1 | 06-20-2001 05:19 PM |
| Postmessage function - Program focus message?? | Chris L. | VB Classic | 2 | 04-14-2001 03:38 PM |
| Postmessage function - Program focus message?? | Chris L. | VB Classic | 0 | 04-14-2001 12:41 PM |