Click here to Skip to main content
15,888,454 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Know when a child popup dialog is opened Pin
Jochen Arndt12-Dec-16 2:06
professionalJochen Arndt12-Dec-16 2:06 
GeneralRe: Know when a child popup dialog is opened Pin
_Flaviu13-Dec-16 0:08
_Flaviu13-Dec-16 0:08 
GeneralRe: Know when a child popup dialog is opened Pin
Jochen Arndt13-Dec-16 0:25
professionalJochen Arndt13-Dec-16 0:25 
QuestionRe: Know when a child popup dialog is opened Pin
David Crow12-Dec-16 3:15
David Crow12-Dec-16 3:15 
AnswerRe: Know when a child popup dialog is opened Pin
_Flaviu12-Dec-16 5:24
_Flaviu12-Dec-16 5:24 
GeneralRe: Know when a child popup dialog is opened Pin
Victor Nijegorodov12-Dec-16 7:46
Victor Nijegorodov12-Dec-16 7:46 
GeneralRe: Know when a child popup dialog is opened Pin
_Flaviu12-Dec-16 23:48
_Flaviu12-Dec-16 23:48 
AnswerRe: Know when a child popup dialog is opened Pin
leon de boer13-Dec-16 16:47
leon de boer13-Dec-16 16:47 
Can I say I have never seen such a ridiculously convoluted way to do this. Doing an atomic string search is first slow, and secondly mildly dangerous and unreliable.

There are two MUCH SAFER standard windows ways to do such a thing and both require you to put code on the dialog handler

1.) In the dialog itself on the WM_INITDIALOG message either post back a message dialog is open, or even just set a global variable to the dialog window. In the WM_DESTROY of the dialog post back a closed message or just zero the global variable to the dialog window.

Something like this is probably the simplest for you
HWND MyDialog = 0;    // You can make this global or declare it extern on your .h or have a function to access it.

// Your dialog message handler
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
        ...

       case WM_INITDIALOG:
             ...
             MyDialog = hDlg;        // Hold the handle to yourself for others
             break;
       case WM_DESTROY:
             ...
             MyDialog = 0;           // Dialog about to destroy stop others accessing
             break;
     ...

2.) In the dialog handler itself respond back to a user WM_APP message with your handle. The message will be enumerated to all windows in your application and you will be the only responder.
// Your dialog message handler
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
        ...

       case WM_APP + 100:             // Some user app number
             ...
             return (hDlg);          // Return your handle in response to the message
     ...

Method 1 you simply need to look at the global variable MyDialog to know if the dialog is open or not and what it's handle is. Method 2 you use SendMessage(0, WM_APP+100, 0, 0) and if your dialog is open you will get a response back which will the handle to your dialog. If you get 0 back the dialog is not open because no other window will respond to WM_APP + 100.
In vino veritas


modified 13-Dec-16 23:17pm.

GeneralRe: Know when a child popup dialog is opened Pin
_Flaviu15-Dec-16 23:24
_Flaviu15-Dec-16 23:24 
QuestionProper declaration of array with volatile values inside it? Pin
arnold_w7-Dec-16 3:30
arnold_w7-Dec-16 3:30 
AnswerRe: Proper declaration of array with volatile values inside it? Pin
Jochen Arndt7-Dec-16 4:22
professionalJochen Arndt7-Dec-16 4:22 
AnswerRe: Proper declaration of array with volatile values inside it? Pin
leon de boer7-Dec-16 6:39
leon de boer7-Dec-16 6:39 
QuestionTree Ctrl Object Selection Pin
raajpatel4-Dec-16 20:57
raajpatel4-Dec-16 20:57 
GeneralRe: Tree Ctrl Object Selection Pin
Richard MacCutchan4-Dec-16 21:16
mveRichard MacCutchan4-Dec-16 21:16 
GeneralRe: Tree Ctrl Object Selection Pin
raajpatel5-Dec-16 1:20
raajpatel5-Dec-16 1:20 
GeneralRe: Tree Ctrl Object Selection Pin
Peter_in_27805-Dec-16 1:36
professionalPeter_in_27805-Dec-16 1:36 
QuestionMutex WaitForSingleObject does not Signal Pin
ForNow1-Dec-16 13:14
ForNow1-Dec-16 13:14 
AnswerRe: Mutex WaitForSingleObject does not Signal Pin
Richard MacCutchan1-Dec-16 21:39
mveRichard MacCutchan1-Dec-16 21:39 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
ForNow2-Dec-16 2:25
ForNow2-Dec-16 2:25 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
Richard MacCutchan2-Dec-16 3:01
mveRichard MacCutchan2-Dec-16 3:01 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
ForNow10-Dec-16 15:12
ForNow10-Dec-16 15:12 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
Richard MacCutchan10-Dec-16 20:46
mveRichard MacCutchan10-Dec-16 20:46 
AnswerRe: Mutex WaitForSingleObject does not Signal Pin
Munchies_Matt9-Dec-16 2:52
Munchies_Matt9-Dec-16 2:52 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
ForNow10-Dec-16 15:07
ForNow10-Dec-16 15:07 
GeneralRe: Mutex WaitForSingleObject does not Signal Pin
Munchies_Matt10-Dec-16 21:01
Munchies_Matt10-Dec-16 21:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.