Dialog Box Problems

This is a discussion on Dialog Box Problems within the Windows Programming forums, part of the Platform Specific Boards category; Alright I am trying to put a dilog box in my program. At first, it wasn't accepting my resource file. ...

  1. #1
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109

    Dialog Box Problems

    Alright I am trying to put a dilog box in my program. At first, it wasn't accepting my resource file. Now, I have everything working right, and the dialog box ins't appearing.

    Here is all my dialog box code:

    Resourse (dialogs.rc)
    Code:
    #include "hdandn.hpp"
    
    IDD_DLGJOIN DIALOG 260, 200, 188, 95
    STYLE DS_MODALFRAME | WS_CHILD | WS_CAPTION | WS_TOPMOST | WS_SETFOREGROUND | WS_VISIBLE
    CAPTION "Join a Game"
    FONT 8, "Courier New"
    BEGIN
        DEFPUSHBUTTON   "OK", ID_DLGOK, 130, 10, 50, 14
    END
    DialogBox Call
    Code:
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLGJOIN), dlghwnd, reinterpret_cast<DLGPROC>(DlgProc));
    DlgProc
    Code:
    LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(Msg)
    	{
        case WM_CREATE:
             break;
    	case WM_INITDIALOG:
    		return TRUE;
        case WM_COMMAND:
    		switch(wParam)
    		{
    		    case IDOK:
    			    EndDialog(hWndDlg, 0);
    			    return TRUE;
    		}
    		break;
    	}
    
    	return FALSE;
    }
    Misc:

    Predifinition (forget word):
    Code:
    LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam); // Dialog Box
    Header definitions:
    Code:
    #define IDD_DLGJOIN      100
    #define ID_DLGOK         101
    That is all the code I have that pretains to the dialog boxes. I don't see anything wrong, yet when I click the button to get the DialogBox to appear, nothing happens. I know that the button works, I have tested it with regular message boxes.

    I am using Dev-C++ 4.9.9.2

    Thanks in advance for all help and suggestions .
    Sic vis pacum para bellum. If you want peace, prepare for war.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I'm guessing the problem is that you are giving your dialog the WS_CHILD style. You probably dont want your dialog box as a child window.

  3. #3
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    Thanks. I got rid of that, and it didn't help. I added in WS_POPUP instead, and that didn't help either
    Sic vis pacum para bellum. If you want peace, prepare for war.

  4. #4
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    Could someone please explain the reason for the 'reinterpret_cast' in the dialog box call? I don't understand why it would be neccessary.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  5. #5
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    That is just how the tutorial i read told me to do it. I've seen it work with and without. I just put in a regular typecast and it doesnt change a thing
    Last edited by Morgul; 05-28-2005 at 10:39 PM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    try...
    a normal cast to (DLGPROC)DlgProc. Looks a bad mix of C++ and C.
    and return FALSE to the Init msg.

    Put a break point in the DlgProcs WM_INITDIALOG case.
    This will tell if the dialog is being created.
    If not the error is in the DialogBox() call (probably in the resource script).
    "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

  7. #7
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    I changed the return true to a break, and have a normal cast now. Still, nothing happens.

    Here is my resource code currently:

    Code:
    #include "hdandn.hpp"
    
    IDD_DLGJOIN DIALOG 260, 200, 188, 95
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_TOPMOST | WS_SETFOREGROUND | WS_VISIBLE
    CAPTION "Join a Game"
    FONT 8, "Courier New"
    BEGIN
        DEFPUSHBUTTON   "OK", ID_DLGOK, 130, 10, 50, 14
    END
    I don't see anything wrong with it but maybe it is something I don't know about.

    Also: would it be better just to use those custom templates where i program the buttons and so on myself? If I did that, would that allow me to change settings about like background color and transperancy?
    Sic vis pacum para bellum. If you want peace, prepare for war.

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Still, nothing happens<<

    Is the return value of your DialogBox call zero?

    If it is, have you tried to find out why with GetLastError?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    There is no such thing as WS_TOPMOST or WS_SETFOREGROUND - unless you've difined them yourself.

    I don't recommend casting any function parameters. The correct signature will be
    BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM)
    or
    INT_PTR CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM)
    depending on your version of the SDK.

    Get rid of WS_CHILD and WS_POPUP and the 3rd parameter to DialogBox() should be 0.

    For WM_COMMAND, you need to switch on LOWORD(wParam) and case on ID_DLGOK, not IDOK.

    gg

  10. #10
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    I changed the Dlgproc to INT_PTR (bool wasn't accepted), I got rid of WS_POPUP, I changed the third parameter of DialogBox() to 0, I fixed the WM_COMMAND in Dlgproc (I was going to eventually anyway), and none of this helped. It still doesn't work.

    Also, I got WS_TOPMOST and WS_SETFOREGROUND off of msdn, I have used them before and they work fine.



    Could the problems be because my program uses OpenGL? Could there be something I have to set first so that it will let me use a Dialogbox?
    Last edited by Morgul; 05-29-2005 at 11:11 AM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  11. #11
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    >> Also, I got WS_TOPMOST and WS_SETFOREGROUND off of msdn
    No you didn't, because they do not exist - unless you have defined them in your own source.
    I doubt that your resrouce script even compiles.

    Quote Originally Posted by Ken Fitlike
    >>Still, nothing happens<<

    Is the return value of your DialogBox call zero?

    If it is, have you tried to find out why with GetLastError?
    gg
    Last edited by Codeplug; 05-29-2005 at 01:43 PM.

  12. #12
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    Yes I did:

    uType
    [in] Specifies the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.
    To indicate the buttons displayed in the message box, specify one of the following values.
    MB_ABORTRETRYIGNORE
    The message box contains three push buttons: Abort, Retry, and Ignore.
    MB_CANCELTRYCONTINUE
    Microsoft Windows 2000/XP: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.
    MB_HELP
    Windows 95/98/Me, Windows NT 4.0 and later: Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner.
    MB_OK
    The message box contains one push button: OK. This is the default.
    MB_OKCANCEL
    The message box contains two push buttons: OK and Cancel.
    MB_RETRYCANCEL
    The message box contains two push buttons: Retry and Cancel.
    MB_YESNO
    The message box contains two push buttons: Yes and No.
    MB_YESNOCANCEL
    The message box contains three push buttons: Yes, No, and Cancel.
    To display an icon in the message box, specify one of the following values.
    MB_ICONEXCLAMATION
    An exclamation-point icon appears in the message box.
    MB_ICONWARNING
    An exclamation-point icon appears in the message box.
    MB_ICONINFORMATION
    An icon consisting of a lowercase letter i in a circle appears in the message box.
    MB_ICONASTERISK
    An icon consisting of a lowercase letter i in a circle appears in the message box.
    MB_ICONQUESTION
    A question-mark icon appears in the message box.
    MB_ICONSTOP
    A stop-sign icon appears in the message box.
    MB_ICONERROR
    A stop-sign icon appears in the message box.
    MB_ICONHAND
    A stop-sign icon appears in the message box.
    To indicate the default button, specify one of the following values.
    MB_DEFBUTTON1
    The first button is the default button.
    MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.

    MB_DEFBUTTON2
    The second button is the default button.
    MB_DEFBUTTON3
    The third button is the default button.
    MB_DEFBUTTON4
    The fourth button is the default button.
    To indicate the modality of the dialog box, specify one of the following values.
    MB_APPLMODAL
    The user must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the user can move to the windows of other threads and work in those windows.
    Depending on the hierarchy of windows in the application, the user may be able to move to other windows within the thread. All child windows of the parent of the message box are automatically disabled, but popup windows are not.

    MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.

    MB_SYSTEMMODAL
    Same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.
    MB_TASKMODAL
    Same as MB_APPLMODAL except that all the top-level windows belonging to the current thread are disabled if the hWnd parameter is NULL. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the calling thread without suspending other threads.
    To specify other options, use one or more of the following values.
    MB_DEFAULT_DESKTOP_ONLY
    Windows NT/2000/XP: Same as MB_SERVICE_NOTIFICATION except that the system will display the message box only on the default desktop of the interactive window station. For more information, see Window Stations.
    Windows NT 4.0 and earlier: If the current input desktop is not the default desktop, MessageBox fails.

    Windows 2000/XP: If the current input desktop is not the default desktop, MessageBox does not return until the user switches to the default desktop.

    Windows 95/98/Me: This flag has no effect.

    MB_RIGHT
    The text is right-justified.
    MB_RTLREADING
    Displays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
    MB_SETFOREGROUND
    The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
    MB_TOPMOST
    The message box is created with the WS_EX_TOPMOST window style.
    MB_SERVICE_NOTIFICATION
    Windows NT/2000/XP: The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.
    Terminal Services: If the calling thread has an impersonation token, the function directs the message box to the session specified in the impersonation token.

    If this flag is set, the hWnd parameter must be NULL. This is so the message box can appear on a desktop other than the desktop corresponding to the hWnd.

    For more information on the changes between Microsoft Windows NT 3.51 and Windows NT 4.0, see Remarks.

    MB_SERVICE_NOTIFICATION_NT3X
    Windows NT/2000/XP: This value corresponds to the value defined for MB_SERVICE_NOTIFICATION for Windows NT version 3.51.
    For more information on the changes between Windows NT 3.51 and Windows NT 4.0, see Remarks.
    Do cntrl+f (find) on this page and search for WS_TOPMOST and WS_SETFOREGROUND

    Everything compiles, I have even rebuilt the project. I go to make the dialog box appears, and nothing happens.

    I'm going to test GetLastError, ill edit with my results...

    --------- edit----------

    I got an error code of 1812. This is:

    ERROR_RESOURCE_DATA_NOT_FOUND
    1812
    The specified image file did not contain a resource section.
    This means that my resource is screwed up. However, it seems to be compiling fine. I don't see anything wrong with my resource, I even tried taking out the WS_TOPMOST and WS_SETFOREGROUND, and it didn't help.

    Resource (just to make sure I have the most up-to-date version here):
    Code:
    #include "hdandn.hpp"
    
    IDD_DLGJOIN DIALOG 260, 200, 188, 95
    STYLE DS_MODALFRAME | WS_CAPTION | WS_TOPMOST | WS_SETFOREGROUND | WS_VISIBLE
    CAPTION "Join a Game"
    FONT 8, "Courier New"
    BEGIN
        DEFPUSHBUTTON   "OK", ID_DLGOK, 130, 10, 50, 14
    END
    Last edited by Morgul; 05-29-2005 at 02:50 PM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

  13. #13
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,669
    >> Do cntrl+f (find) on this page and search for WS_TOPMOST and WS_SETFOREGROUND
    And yet the're nowhere to be found within your quote. Trust in your own ctrl-f skillz - they don't exist.

    This works as expected in VC++ 6.0 and Dev-C++ 4.9.8.0:
    Code:
    IDD_DLGJOIN DIALOG 260, 200, 188, 95
    STYLE DS_MODALFRAME | WS_CAPTION | WS_VISIBLE
    CAPTION "Join a Game"
    FONT 8, "Courier New"
    BEGIN
        DEFPUSHBUTTON   "OK", ID_DLGOK, 130, 10, 50, 14
    END
    So what makes you think your resource is actually compiling?

    gg

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Yes I did:<<

    That looks to be the msdn description for the MessageBox function. I searched through what you've posted and didn't find either WS_TOPMOST nor WS_SETFOREGROUND styles. I also searched through the linked CreateWindow page you provided and didn't find anything there either.

    There is an extended window style (see CreateWindowEx, dwExStyle parameter description) of WS_EX_TOPMOST, though, which is maybe where you're getting confused. But to use extended styles in resource generated dialogs you need to use the DIALOGEX resource definition statement in your resource script and not DIALOG as you have done. There's also MB_SETFOREGROUND and MB_TOPMOST flags listed for the MessageBox function but neither of these are window styles.

    Although MessageBoxes are essentially dialog boxes it's probably best not to mix them up in the way you are implying.

    Since you seem to be using undefined constants in your project and that project compiles without error, it may be that the resource script is somehow not being included in the build; if it was windres, the resource compiler used by Dev-Cpp, would be emitting its legendary and ambiguous 'parse' errors.

    Did you try this?
    Quote Originally Posted by Ken Fitlike
    >>Still, nothing happens<<

    Is the return value of your DialogBox call zero?

    If it is, have you tried to find out why with GetLastError?
    edit: Well beaten by Codeplug.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  15. #15
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    Well, you have proven me wrong. I now see my error. I am thinking of MB_TOPMOST and MB_SETFOREGROUND. This however proves that the resource is not being included in compilation.

    If you read my above edit, I did get the last error:

    I got an error code of 1812. This is:


    Quote:
    ERROR_RESOURCE_DATA_NOT_FOUND
    1812
    The specified image file did not contain a resource section.

    This means that my resource is screwed up.
    So my resource is not being used. I don't understand how this is possible, but it is happening. So, I am going to make a new resource file, remove the old one from the project, and use the same resource code for it. This might not help however.

    ----------- edit-----------------

    I copied the stuff into a new resource file and named it something else. It doesn't compile now.

    I get this error:

    [Resource error] Day_: No such file or directory
    C:\Dev-Cpp\OpenGL\Day & Night\Makefile.win [Build Error] [Day_&_Night_private.res] Error 1
    Last edited by Morgul; 05-29-2005 at 09:10 PM.
    Sic vis pacum para bellum. If you want peace, prepare for war.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Display text in a Dialog Box
    By Dark_Phoenix in forum Windows Programming
    Replies: 9
    Last Post: 01-02-2009, 05:30 AM
  2. Dialog Box (Compile Problem)
    By Vicious in forum Windows Programming
    Replies: 6
    Last Post: 08-31-2004, 03:29 PM
  3. problem with the open dialog box
    By stallion in forum Windows Programming
    Replies: 13
    Last Post: 02-19-2003, 07:28 AM
  4. Context Menu & Dialog Box :: MFC
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 08-11-2002, 10:01 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21