CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Making a modeless dialog modal?

    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

  2. #2
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Making a modeless dialog modal?

    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.

  3. #3
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Making a modeless dialog modal?

    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

  4. #4
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: Making a modeless dialog modal?

    Quote Originally Posted by Gyannea
    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
    Code:
    	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
    Last edited by humptydumpty; July 20th, 2005 at 08:40 AM.

  5. #5
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Making a modeless dialog modal?

    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

  6. #6
    Join Date
    May 2005
    Location
    United States
    Posts
    526

    Re: Making a modeless dialog modal?

    Quote Originally Posted by Gyannea
    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.

  7. #7
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Making a modeless dialog modal?

    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!

  8. #8
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: Making a modeless dialog modal?

    Quote Originally Posted by Gyannea
    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

  9. #9
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Making a modeless dialog modal?

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured