Click to See Complete Forum and Search --> : Making a modeless dialog modal?


Gyannea
July 20th, 2005, 07:41 AM
How does one make a modal dialog box out of a modeless dialog box? I tried checking the 'system modal' style in the dialog box editor style selection options, but it did not work. It DID force the dialog box to always be top level but I could, nevertheless, go to other windows and operate them. Since both 'CReateDialog()' and 'DialogBox()' use 'CreateWIndowEx()' I wonder how windows makes it such that you can't do anything else but operate on the modal dialog box. If I put the handle of the owner to the desktop would that do the trick (though I am not sure how to get the handle of the desktop).

The reason I am doing this is that I have already created a class of modeless dialog boxes and for convenience I would like to make some of them modal without creating (deriving) another class.

Thanks,

Brian

SuperKoko
July 20th, 2005, 07:58 AM
With the normal Win32 API, you can use DialogBox instead of CreateDialog.
When DialogBox is called, the system creates the window (using the parent window specified as third argument as parent window of the dialog box) and all the controls, and disables the parent window.
When a window is disabled, all its child windows are also disabled, so all childs windows (even popup child windows) of the parent window are disabled.

Then the system executes a message loops until EndDialog is called. In that case a flag is set to indicate that the dialog box has terminated its work, and at the next loop of the message loop, it exits the message loop, and the DialogBox function returns after having enabled the parent window.

Note, that a disabled window cannot recieve user's input, but can recieve messages, and treat them.

Gyannea
July 20th, 2005, 08:22 AM
Yes, I understand that, but I have a class that already bakes in the modeless 'CreateDialogParam()' API function and since BOTH that and the DialogBoxParam() API function use 'CreateWindowEx()" to make the dialog box, I was wondering how Windows does that. There must be some generic set of style parameters which are used or perhaps a window class.

It may not be possible to 'convert' a modeless dialog box to a modal dialog box. Setting the 'system modal' style did half the job (it kept the dialog box at top level no matter what you did) but it did not prevent me from working in other windows, including it's parent window (which is the critical part).

So Windows must do more, I just don't know what!

Brian

humptydumpty
July 20th, 2005, 08:33 AM
Yes, I understand that, but I have a class that already bakes in the modeless 'CreateDialogParam()' API function and since BOTH that and the DialogBoxParam() API function use 'CreateWindowEx()" to make the dialog box, I was wondering how Windows does that. There must be some generic set of style parameters which are used or perhaps a window class.

It may not be possible to 'convert' a modeless dialog box to a modal dialog box. Setting the 'system modal' style did half the job (it kept the dialog box at top level no matter what you did) but it did not prevent me from working in other windows, including it's parent window (which is the critical part).

So Windows must do more, I just don't know what!

Brian

As superkoko told you regarding Model and Modeless dialog feature
if you want to make your modeless adialog to modal.
this mean first u don't want to create More then one instance of your dialog
so make your dialog as a singelton class
or make a static variable on InitDialog increment the value and on Destroy decrement the value at the time of dialog creation check if value more then one or eual to just print the error messge and setfocus to previoud dialog again print the here m_iiGetinstanceCount is a static variable used in class.
MyDlg is our dialog class, and objDlg is a Object of class MyDlg

if(MyDlg ::m_iGetinstanceCount < 1)
{
objDlg .Create(::GetDesktopWindow());
objDlg .ShowWindow(SW_SHOW);
return 0;
}
else
{
if(MyDlg ::m_iGetinstanceCount == 1)
{
::MessageBox(NULL,"Application is already running if you want to run a new Application Please Close previos one","Sharing Voilance",MB_OK);
objDlg .SetFocus();
return 0;
}

}


anything else you wann to know.so let me know

Gyannea
July 20th, 2005, 09:23 AM
Yes, I only want to create a single instance of the dialog from a given parent. At first I didn't want to be able to anything but handle that dialog, (not even go to other "parent" windows) but I am not so sure of that now.

In any case, stopping a second instance is perhaps how Windows does it, and if that is the case, there may be no 'style' flag that triggers this action or if there is, I don't know what it is. The 'system modal' flag does not!

Brian

Smasher/Devourer
July 20th, 2005, 10:41 AM
In any case, stopping a second instance is perhaps how Windows does it, and if that is the case, there may be no 'style' flag that triggers this action or if there is, I don't know what it is. The 'system modal' flag does not!
I know this doesn't answer your question, but just as a point of information: the System Modal style is supposed to create a "stronger" version of a modal dialog box. Whereas a modal dialog box prohibits switching to its parent window as long as the dialog box is active, a system modal dialog box is supposed to prohibit switching to any window while it's active. However, this behavior is no longer allowed, not in any 32-bit version of Windows. I think it was possible to create a dialog like this under Windows 3.1, but my Windows programming experience doesn't extend back nearly that far so I couldn't tell you for sure. But that's why checking System Modal doesn't produce modal behavior as you might expect.

Gyannea
July 20th, 2005, 11:11 AM
Well, it should prevent switching back to the parent window (the action taken to create the modal dialog). For example, the good old message box. When you get one of those, you can't go back to the parent window and try to play with another control, you have to press the 'ok' button to continue. You can go to another window, however.

What I was trying to do was a quick and dirty way to convert my modeless dialog box to a modal (such as a message box). But it seems I have to call the DialogBox function instead of the CreateDialog() function. So Windows does something extra to get that behavior, I just don't know what.

Brian

PS: I've only been programming Windows for about 2 years, so I know nothing about the older versions!

humptydumpty
July 20th, 2005, 11:41 PM
Well, it should prevent switching back to the parent window (the action taken to create the modal dialog). For example, the good old message box. When you get one of those, you can't go back to the parent window and try to play with another control, you have to press the 'ok' button to continue. You can go to another window, however.

What I was trying to do was a quick and dirty way to convert my modeless dialog box to a modal (such as a message box). But it seems I have to call the DialogBox function instead of the CreateDialog() function. So Windows does something extra to get that behavior, I just don't know what.

Brian

PS: I've only been programming Windows for about 2 years, so I know nothing about the older versions!

As i told you.how to create a Modeless dialog .and at a single time you can check that no more then one instance running of the application.from upper code you can do this.no need to make system modal or anything else
Second you can take a bool variable .and check if you completed your all work then only set this value 1 and call DestroyWindow.
other wise just return
and keep Set Focus on our first dialog
even on parent click set focus on child if it exist
anything else you want to know

Gyannea
July 21st, 2005, 05:35 AM
Humpty Dumpty: Yes, I understand that what you do is one approach, but I do not know how Windows does it. I believe there must be some flag that tells windows to do whatever technique it uses to accomplish the task since Windows starts with the same APIs. I just wish I knew what it was so I wouldn't have to re-do it.

In my case it's easier just to call DialogBox().