Modeless dialog
-
Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan
-
Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan
Usually disapears because the scope of variable swRem is finished. The best way is the first solution and on WM_CLOSE message (should be more) try a "delete this" It should work. regards, /REMUS
-
Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan
I suspect that your code : CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); is in some function. Once the function returns, static local variables are automattically destroyed. (in your case , msg and swRem). One thing to try is to make these variable global by putting the lines : CString msg("Message"); CShowMessage swRem(msg); at the top of your CPP file.
-
Usually disapears because the scope of variable swRem is finished. The best way is the first solution and on WM_CLOSE message (should be more) try a "delete this" It should work. regards, /REMUS
Actually, the
delete this;
call should go in an override ofPostNcDestroy()
. -
I suspect that your code : CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); is in some function. Once the function returns, static local variables are automattically destroyed. (in your case , msg and swRem). One thing to try is to make these variable global by putting the lines : CString msg("Message"); CShowMessage swRem(msg); at the top of your CPP file.
I assume that the CShowMessage constructor stores the parameter (msg) as a member variable for itself, so making it global is not necessary and would probably not accomplish anything even if it were global; the constructor does not use the variable, it uses the parameter. Also, C++ classes usually make it unnecessary to use global variables, so: CShowMessage swRem(msg); could be a member variable in the class where it is being used.
-
Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan
The documentation for modeless dialogs has been inadequate so I wrote some notes that might help people. See: http://home.socal.rr.com/samhobbs/VC/ModelessDialogs.html In that page I reference a MS KB article that was written after I wrote my notes.