Thread: DoModal() problem --> pls help.

  1. #1
    Registered User intruder's Avatar
    Join Date
    Nov 2002
    Posts
    48

    DoModal() problem --> pls help.

    Hi friends,
    This question of mine is related to VC++ but since this forum is for C++ i m sure there might be people knowing VC++.

    ok my question is .. i have developed a dialog based application. Its an application which is called thru methiod DoModal().

    But now the problem is When my applicatoin is running at that time if i click on ome hter window .. my application screen goes white totally .. Hence i want some functoin which will allow me to do focus change.. i should be able to change the window using ctrl + tab and also with my mouse. ??

    pls help .. is there any other method apart from DoModal() ?

    Thanks in advance.

    intruder.

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    This question of mine is related to VC++ but since this forum is for C++ i m sure there might be people knowing VC++.
    The fact that you refer to VC++ as a language implies that you don't know enough C++ to be doing a GUI application VC++ is an IDE, or in other words it's the compiler/debugger/code editor that you use to program C++. Anyway, in case you really do know what you're doing (which I don't, by the way), it sounds that the problem is that your application isn't redrawing its window properly. Try looking into InvalidateRect() or UpdateWindow(), as well as the WM_PAINT window message. There's not much chance that those functions will help you since you seem to be using MFC or something, but it's worth a shot anyways. Anyway, I believe you're talking about Alt-Tab instead of ctrl And there are plenty of ways to do GUI without DoModal() whatever it is. Look into Windows API and CreateDialog().
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    DoModal() creates a dialog that MUST be dealt with before the user can move to another task ie a critical error, log on screen ect. Therefore you should not be able to switch to another dialog/application until you have closed the modal one.

    Use Create() member of CDialog and a member variable instead

    ie
    if(! m_dlgNotModal.Create( MAKEINTRESOURCE(IDD_NOTMODAL), this) )
    //handle error
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    DoModal() creates a dialog that MUST be dealt with before the user can move to another task ie a critical error, log on screen ect. Therefore you should not be able to switch to another dialog/application until you have closed the modal one.
    Incorrect. All MFC dialog applications are modal by default, and switching to another dialog/application is no problem at all.

    Intruder, maybe you could post the CDialog derived class that is giving you trouble.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >> Incorrect. All MFC dialog applications are modal by default, and switching to another dialog/application is no problem at all.<<

    OK. My experience tells me otherwise.
    AFAIK;
    Any WIN32 (MFC) application is not modal/modeless.
    The apps windows/dialogs are created modal or modeless. For example the 'About' dialog created with all MFC apps is modal.

    MSDN under CDialog :: DoModal()

    “This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.”

    Again from MSDN
    “You can use class CDialog to manage two kinds of dialog boxes:

    Modal dialog boxes, which require the user to respond before continuing the program

    Modeless dialog boxes, which stay on the screen and are available for use at any time but permit other user activities “
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    OK. My experience tells me otherwise.
    I'm sorry, but your experience must be telling you wrong

    Simple test:
    Create a new MFC dialog application, keep all the default settings. Now look at the source code, and verify that the dialog is indeed calling DoModal(). Compile the MFC dialog application, and run it as is. Now look how easily you can switch between the application and other running applications.

    A MFC Modal dialog box (as the MSDN article you quoted says) halts only the application which created the modal dialog.

    Now maybe your confusion comes from the fact that you are not experienced with MFC. MFC modal and modeless dialogs are different from those which do not use MFC. MFC never calls the DialogBox API function call, because MFC uses it's own message pump for its dialog boxes.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The original posters level of knowledge seemed limited. As such I tailored my answer to their level, glossing over/ignoring what I considered unimportant. Your input only servered to complicate the issue.

    I also answered their question. Did you notice what the ACTUAL question was?


    I was incorrect about other applications (as I use maximised style as a default and hide the taskbar in windows)

    You were incorrect about windows within the application (which are disabled when a modal dialog is displayed).



    ALL dialogs in MFC are created with CreateDlgIndirect() (as they use a resource template).

    All use a PeekMessage( no remove) to scan messages before the main loop uses a GetMessage() to remove the msg from the que, all very inefficent.

    The major difference between modal and modeless is ultimately a call to EnableWindow() using the parents handle (and of course setting the WF_CONTINUEMODAL and the frames OnEnableModeless() flags).

    The way these dlgs are destroyed is also a major factor, and I suspect the cause of the posters problem.


    >>Now maybe your confusion comes from the fact that you are not experienced with MFC.

    LOL!
    I have only written comercial apps with MFC for five years. Much less than I have with WIN32 based C and C++.

    I would bet I recorded my first app on cassette tape before you were born.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I also answered their question. Did you notice what the ACTUAL question was?
    Yes I noticed what the question was. Since a simple modal dialog does not give the kind of results he was experiencing, I asked him to post his code. You on the other hand posted:

    DoModal() creates a dialog that MUST be dealt with before the user can move to another task ie a critical error, log on screen ect. Therefore you should not be able to switch to another dialog/application until you have closed the modal one.
    There isnt a single line in that above quote which is true.

    You were incorrect about windows within the application.(which are disabled when a modal dialog is displayed).
    Where did I mention windows within the application? But even your above quote isnt totally true. Only other windows running on the same thread as the modal dialog are disabled.

    I would bet I recorded my first app on cassette tape before you were born.
    very relevant.

    Look, I didnt mean to upset you or step on any toes. I simply pointed out the inaccurate information, and I guess it came across as rude. For that I apologize.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 12:12 PM
  2. WSAD Problem Pls Help
    By Ti22 in forum Game Programming
    Replies: 1
    Last Post: 01-16-2005, 11:24 AM
  3. pls help i cant find the problem :(((
    By condorx in forum C Programming
    Replies: 3
    Last Post: 11-07-2002, 09:05 AM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. Spot the problem..a test question, pls help!
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2002, 01:40 AM