Thread: Wm_paint/dialog

  1. #1
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312

    Wm_paint/dialog

    I fixed the menu! But new problems keep coming!!!

    - When does the Window procedure get the WM_PAINT message?
    - Dialog:

    in resources.rc file:

    Code:
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                        IDC_STATIC,16,18,144,33
    END
    nothing about the dialog in the resource.h file

    in part of main code:

    Code:
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    } // is the dialog procedure
    
    
    case WM_COMMAND: // WM_COMMAND message in windows procedure
            switch(LOWORD(wParam))
            {
                case ID_FILE_EXIT:
                    PostMessage(hwnd, WM_CLOSE, 0, 0);
                break;
                case ID_HELP_ABOUT:
                {
                int ret = DialogBox(GetModuleHandle(NULL), 
                    MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                if(ret == IDOK){
                    MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                        MB_OK | MB_ICONINFORMATION);
                }
                else if(ret == IDCANCEL){
                    MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                        MB_OK | MB_ICONINFORMATION);
                }
                else if(ret == -1){
                    MessageBox(hwnd, "Dialog failed!", "Error",
                        MB_OK | MB_ICONINFORMATION);
                }
                }
                break;
                case ID_STUFF_GO:
                    hdc = BeginPaint (hwnd, &ps) ;
                    GetClientRect (hwnd, &rect) ;
                    DrawText (hdc, TEXT ("You pressed the leftmouse button!"), -1, &rect,
                          DT_SINGLELINE | DT_LEFT | DT_BOTTOM) ;
                    EndPaint (hwnd, &ps) ;
                break;
            }
            break;
    It says: main1.cpp:50: `IDD_ABOUT' undeclared (first use this function)

    How can I fix this problem?
    Last edited by Ideswa; 03-16-2006 at 12:52 PM.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    you could just add IDD_ABOUT to resource.h followed by a number that is greater that the greatest number currently in resource.h. Make sure there is no two numbers being the same.

    The IDD_ snd IDC_ are only mappings kind of like #define. Hope it helps
    Amish

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>- When does the Window procedure get the WM_PAINT message?

    When you call for it or when the OS calls for it due to your window being covered / uncovered by another window.

    To call for you own paint use

    InvalidateRect() //send paint msg
    UpdateWindow() //post directly to the apps msg que bypassing the OS que for faster drawing
    "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
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    I put the

    Code:
    #define IDD_ABOUT 100001
    in my resource.h file,
    but it says (Messagebox) Dialog failed, because

    Code:
    int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                    if(ret == IDOK){
                        MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                        MB_OK | MB_ICONINFORMATION);
                    }
                    else if(ret == IDCANCEL){
                        MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                        MB_OK | MB_ICONINFORMATION);
                    }
                    else if(ret == -1){
                        MessageBox(hwnd, "Dialog failed!", "Error",
                        MB_OK | MB_ICONINFORMATION);
                    }
    What can I do to fix it?
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    change the return TRUEs to return FALSEs.

    Look up DefWindowProc()
    "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
    Jun 2008
    Posts
    1

    Im having the same problem

    Hi guys.

    this is my first post to this forum.

    im having the same problem as ideswa with regards to the dialog box.

    i have the following code


    Code:
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
            
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
                    
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        } 
        return TRUE;
    }

    ^^ thats in the main .cpp file

    Code:
    case WM_COMMAND:
               { 
                switch(LOWORD(wParam))
                {
                  case ID_HELP_ABOUT:
            {
                int ret = DialogBox(GetModuleHandle(NULL), 
                    MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                if(ret == IDOK){
                    MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                        MB_OK | MB_ICONINFORMATION);
                }
                else if(ret == IDCANCEL){
                    MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                        MB_OK | MB_ICONINFORMATION);
                }
                else if(ret == -1){
                    MessageBox(hwnd, "error", "Error",
                        MB_OK | MB_ICONINFORMATION);
                        
                        
                }
            }
            break;   
            }
            }
    ^^ also in main.cpp

    Code:
    #include "resource.h"
    #include "windows.h"
    
    IDR_MYMENU MENU
    BEGIN
        POPUP "&File"
        BEGIN
            MENUITEM "E&xit", ID_FILE_EXIT
        END
    
        POPUP "&Help"
        BEGIN
            MENUITEM "&About The Program", ID_HELP_ABOUT
            MENUITEM "G&Help", 0, GRAYED
        END
    END
    
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                        IDC_STATIC,16,18,144,33
    END
    ^^ my only resource file resource.rc


    the problem is that when i press the about menu item. instead of the dialog box showing up i just get the error message box. that means

    Code:
    DialogBox(GetModuleHandle(NULL), 
                    MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
    is returning -1. ive been looking into this and heard that it could be a problem with the resource files but i dont think it is in this case because the menu works and that relies on the resource file. possibly somthing wrong with the IDD_ABOUT entry in the resource file. any ideas would be greatly appretiated. Oh and do i have to declare this at the start of the program?

    Code:
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
    Liam

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Place a break point in the About box's InitDlg handler and default case. I think the dlg is failing after it creates.

    I would.......

    Change the catch all 'return TRUE' to a 'return FALSE' to show you did not process that msg.

    Return the result from a call to DefWndProc() in your 'default' case in the about box's callback (to get windows to process all msgs you don't have code for).
    "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

Popular pages Recent additions subscribe to a feed