Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DialogBox fuction not executing its procedure [SOLVED]

DialogBox fuction not executing its procedure [SOLVED]

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiohelpdebugginglearning
27 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C coco243

    Richard MacCutchan wrote:

    I told you how to fix it, copy the code from my previous message into your DialogProc.

    I have a lot of respect for people who waste their time to help me, so obviously I tryied what you had said to me.

    Richard MacCutchan wrote:

    If it still does not work for you then there is something else that you are not showing us.

    I don't have nothing to not show, so I started over again: I had created a new "empty" VC++ w32 project and added just these files below(those file are all I got to show :) ): .cpp file:

    //
    // Walk_Directories.cpp
    //

    //#include "CmnHdr.h"
    #include // tipul BOOL este definit in windows.h
    #include "resource.h"
    #include "WindowsX.h"

    BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam)
    {
    RECT rc;

    // Associate an icon with the dialog box.
    //chSETDLGICONS(hwnd, IDI\_DIRWALK, IDI\_DIRWALK);
     SendMessage(hwnd, WM\_SETICON, TRUE, (LPARAM)LoadIcon(GetWindowInstance(hwnd),MAKEINTRESOURCE(IDI\_DIRWALK)));                    
     SendMessage(hwnd, WM\_SETICON, FALSE, (LPARAM)LoadIcon(GetWindowInstance(hwnd),MAKEINTRESOURCE(IDI\_DIRWALK)));                    
    
    GetClientRect(hwnd, &rc);
    SetWindowPos(GetDlgItem(hwnd, IDC\_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP\_NOZORDER);
    
    return(TRUE);
    

    }

    void Dlg_OnSize ( HWND hwnd, UINT state, int cx, int cy)
    {
    SetWindowPos(GetDlgItem(hwnd, IDC_TREE), NULL, 0, 0, cx, cy, SWP_NOZORDER);
    }

    INT_PTR CALLBACK Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch (uMsg)
    {
    case WM_INITDIALOG:
    HANDLE_WM_INITDIALOG(hwnd, wParam, lParam, Dlg_OnInitDialog);
    break;
    case WM_COMMAND:
    if (LOWORD(wParam) == IDCANCEL)
    {
    EndDialog(hwnd, IDCANCEL);
    break;
    }
    return FALSE;
    default:
    return FALSE;

    }
    
    return TRUE;
    

    }

    int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE hinstPrev, LPSTR pszCmdLine, int nCmdShow)
    {

    DialogBox(hinstExe, MAKEINTRESOURCE(IDD_DIRWALK), NULL, Dlg_Proc);

    return(0);
    }

    .rc file:

    // Microsoft Visual C++ generated resource script.
    //
    #include "resource.h"

    #define APSTUDIO_READONLY_SYMBOLS
    /////////////////////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"

    /////////////////////////////////////////////////////////////////////////////
    #undef APST

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #18

    One thing I did notice in your Dialog resource definition was the use of the style value LBX_NOINTEGRAL_HEIGHT. I cannot find a definition of that value anywhere in the Windows header file; I suspect it should be **LBS**_NOINTEGRAL_HEIGHT. I don't have time to look at the rest of the above code today, but may be able to get to it tomorrow or next week.

    C 1 Reply Last reply
    0
    • L Lost User

      One thing I did notice in your Dialog resource definition was the use of the style value LBX_NOINTEGRAL_HEIGHT. I cannot find a definition of that value anywhere in the Windows header file; I suspect it should be **LBS**_NOINTEGRAL_HEIGHT. I don't have time to look at the rest of the above code today, but may be able to get to it tomorrow or next week.

      C Offline
      C Offline
      coco243
      wrote on last edited by
      #19

      I would be grateful. Thank you,

      L 1 Reply Last reply
      0
      • C coco243

        I would be grateful. Thank you,

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #20

        I just built your program from the code in your previous message. I had to add a couple of minor things in the .rc file because of changes in the Win32 libraries. After building the code it runs successfully; i.e. it shows the main dialog with an empty ListView.

        C 1 Reply Last reply
        0
        • L Lost User

          I just built your program from the code in your previous message. I had to add a couple of minor things in the .rc file because of changes in the Win32 libraries. After building the code it runs successfully; i.e. it shows the main dialog with an empty ListView.

          C Offline
          C Offline
          coco243
          wrote on last edited by
          #21

          Can you please tell me where these adjustments were? So I can take a look at me? Teach me how to fix that problems, where to look. Because it can be from the dialog resource to not load properly the DialogBox and not to go to the Dialog procedure from that reason. Where can be the problem on me? ( I am using VS 2010 and I did't had problems with it until now). Thank you,

          L 1 Reply Last reply
          0
          • C coco243

            Can you please tell me where these adjustments were? So I can take a look at me? Teach me how to fix that problems, where to look. Because it can be from the dialog resource to not load properly the DialogBox and not to go to the Dialog procedure from that reason. Where can be the problem on me? ( I am using VS 2010 and I did't had problems with it until now). Thank you,

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #22

            I do not think they will help since they are just there to simulate what is provided by VS2010. However you can add them to the beginning of the .rc file to see what happens:

            #include #define APSTUDIO_INVOKED
            #define LBX_NOINTEGRAL_HEIGHT LBS_NOINTEGRALHEIGHT

            C 1 Reply Last reply
            0
            • L Lost User

              I do not think they will help since they are just there to simulate what is provided by VS2010. However you can add them to the beginning of the .rc file to see what happens:

              #include #define APSTUDIO_INVOKED
              #define LBX_NOINTEGRAL_HEIGHT LBS_NOINTEGRALHEIGHT

              C Offline
              C Offline
              coco243
              wrote on last edited by
              #23

              Hmmm.... When I am creating a new empty project, when I choose to add a new .rc file, in this .rc file it's added automatically some code in that file, I was glad to see that, BUT!!! :mad:, it's appears that somewhere here was some problems or I wasn't pay attention on something, now I have copied exactly the content of the .rc file provided with the book, and now when I run the project, it's appearing an empty dialog box, it is emty, without the ListWiew, but it's a great start. I will put tomorrow the content of the file from the book because I am very tired now, and for shure we will see the critical diferences and for shure I will learn from that. Whoa, I am so glad, we will find and figure out what the clue is, thank you Richard for your patience. Thank you,

              C 1 Reply Last reply
              0
              • C coco243

                Hmmm.... When I am creating a new empty project, when I choose to add a new .rc file, in this .rc file it's added automatically some code in that file, I was glad to see that, BUT!!! :mad:, it's appears that somewhere here was some problems or I wasn't pay attention on something, now I have copied exactly the content of the .rc file provided with the book, and now when I run the project, it's appearing an empty dialog box, it is emty, without the ListWiew, but it's a great start. I will put tomorrow the content of the file from the book because I am very tired now, and for shure we will see the critical diferences and for shure I will learn from that. Whoa, I am so glad, we will find and figure out what the clue is, thank you Richard for your patience. Thank you,

                C Offline
                C Offline
                coco243
                wrote on last edited by
                #24

                Comed back with the differences: Automated .rc file produced by VC with code introduced by me in bad position:

                // Microsoft Visual C++ generated resource script.
                //
                #include "resource.h"

                #define APSTUDIO_READONLY_SYMBOLS
                /////////////////////////////////////////////////////////////////////////////
                //
                // Generated from the TEXTINCLUDE 2 resource.
                //
                #include "afxres.h"

                /////////////////////////////////////////////////////////////////////////////
                #undef APSTUDIO_READONLY_SYMBOLS

                /////////////////////////////////////////////////////////////////////////////
                // English (United States) resources

                #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
                LANGUAGE 9, 1

                #ifdef APSTUDIO_INVOKED

                // Icon
                // Icon with the lowest ID value placed first to ensure
                // application icon remains consistent on all systems.
                IDI_DIRWALK ICON DISCARDABLE "DirWalk.Ico"
                <---*******THIS BOLDED TEXT IS IN THE APSTUDIO_INVOKED DEFINITION
                <---***** it shouln not be here
                <---***** THIS WAS THE FATAL ERROR
                |
                |
                V
                // Dialog
                IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
                STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|
                WS_VISIBLE| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | DS_MODALFRAME
                CAPTION "Directory Walk"
                FONT 8, "System"
                BEGIN
                LISTBOX IDC_TREE,0,0,0,0,NOT LBS_NOTIFY |
                LBX_NOINTEGRAL_HEIGHT | NOT WS_BORDER |
                WS_VSCROLL | WS_HSCROLL | WS_GROUP |
                WS_TABSTOP
                END

                /////////////////////////////////////////////////////////////////////////////
                //
                // TEXTINCLUDE
                //

                1 TEXTINCLUDE
                BEGIN
                "resource.h\0"
                END

                2 TEXTINCLUDE
                BEGIN
                "#include ""afxres.h""\r\n"
                "\0"
                END

                3 TEXTINCLUDE
                BEGIN
                "\r\n"
                "\0"
                END

                #endif // APSTUDIO_INVOKED

                #endif // English (United States) resources
                /////////////////////////////////////////////////////////////////////////////

                #ifndef APSTUDIO_INVOKED
                ////////////////////////////

                L 2 Replies Last reply
                0
                • C coco243

                  Comed back with the differences: Automated .rc file produced by VC with code introduced by me in bad position:

                  // Microsoft Visual C++ generated resource script.
                  //
                  #include "resource.h"

                  #define APSTUDIO_READONLY_SYMBOLS
                  /////////////////////////////////////////////////////////////////////////////
                  //
                  // Generated from the TEXTINCLUDE 2 resource.
                  //
                  #include "afxres.h"

                  /////////////////////////////////////////////////////////////////////////////
                  #undef APSTUDIO_READONLY_SYMBOLS

                  /////////////////////////////////////////////////////////////////////////////
                  // English (United States) resources

                  #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
                  LANGUAGE 9, 1

                  #ifdef APSTUDIO_INVOKED

                  // Icon
                  // Icon with the lowest ID value placed first to ensure
                  // application icon remains consistent on all systems.
                  IDI_DIRWALK ICON DISCARDABLE "DirWalk.Ico"
                  <---*******THIS BOLDED TEXT IS IN THE APSTUDIO_INVOKED DEFINITION
                  <---***** it shouln not be here
                  <---***** THIS WAS THE FATAL ERROR
                  |
                  |
                  V
                  // Dialog
                  IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
                  STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|
                  WS_VISIBLE| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | DS_MODALFRAME
                  CAPTION "Directory Walk"
                  FONT 8, "System"
                  BEGIN
                  LISTBOX IDC_TREE,0,0,0,0,NOT LBS_NOTIFY |
                  LBX_NOINTEGRAL_HEIGHT | NOT WS_BORDER |
                  WS_VSCROLL | WS_HSCROLL | WS_GROUP |
                  WS_TABSTOP
                  END

                  /////////////////////////////////////////////////////////////////////////////
                  //
                  // TEXTINCLUDE
                  //

                  1 TEXTINCLUDE
                  BEGIN
                  "resource.h\0"
                  END

                  2 TEXTINCLUDE
                  BEGIN
                  "#include ""afxres.h""\r\n"
                  "\0"
                  END

                  3 TEXTINCLUDE
                  BEGIN
                  "\r\n"
                  "\0"
                  END

                  #endif // APSTUDIO_INVOKED

                  #endif // English (United States) resources
                  /////////////////////////////////////////////////////////////////////////////

                  #ifndef APSTUDIO_INVOKED
                  ////////////////////////////

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #25

                  I just added your corrected .rc file to the project I have and it builds correctly. And when I run it, it shows the (empty) ListBox as expected.

                  1 Reply Last reply
                  0
                  • C coco243

                    Comed back with the differences: Automated .rc file produced by VC with code introduced by me in bad position:

                    // Microsoft Visual C++ generated resource script.
                    //
                    #include "resource.h"

                    #define APSTUDIO_READONLY_SYMBOLS
                    /////////////////////////////////////////////////////////////////////////////
                    //
                    // Generated from the TEXTINCLUDE 2 resource.
                    //
                    #include "afxres.h"

                    /////////////////////////////////////////////////////////////////////////////
                    #undef APSTUDIO_READONLY_SYMBOLS

                    /////////////////////////////////////////////////////////////////////////////
                    // English (United States) resources

                    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
                    LANGUAGE 9, 1

                    #ifdef APSTUDIO_INVOKED

                    // Icon
                    // Icon with the lowest ID value placed first to ensure
                    // application icon remains consistent on all systems.
                    IDI_DIRWALK ICON DISCARDABLE "DirWalk.Ico"
                    <---*******THIS BOLDED TEXT IS IN THE APSTUDIO_INVOKED DEFINITION
                    <---***** it shouln not be here
                    <---***** THIS WAS THE FATAL ERROR
                    |
                    |
                    V
                    // Dialog
                    IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
                    STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|
                    WS_VISIBLE| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | DS_MODALFRAME
                    CAPTION "Directory Walk"
                    FONT 8, "System"
                    BEGIN
                    LISTBOX IDC_TREE,0,0,0,0,NOT LBS_NOTIFY |
                    LBX_NOINTEGRAL_HEIGHT | NOT WS_BORDER |
                    WS_VSCROLL | WS_HSCROLL | WS_GROUP |
                    WS_TABSTOP
                    END

                    /////////////////////////////////////////////////////////////////////////////
                    //
                    // TEXTINCLUDE
                    //

                    1 TEXTINCLUDE
                    BEGIN
                    "resource.h\0"
                    END

                    2 TEXTINCLUDE
                    BEGIN
                    "#include ""afxres.h""\r\n"
                    "\0"
                    END

                    3 TEXTINCLUDE
                    BEGIN
                    "\r\n"
                    "\0"
                    END

                    #endif // APSTUDIO_INVOKED

                    #endif // English (United States) resources
                    /////////////////////////////////////////////////////////////////////////////

                    #ifndef APSTUDIO_INVOKED
                    ////////////////////////////

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #26

                    I have now modified the Dlg_OnInitDialog function as below and the ListBox gets populated with file and directory names.

                    BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
                    {
                    RECT rc;
                    char szPath[MAX_PATH]; // reserve space for the path

                    // Associate an icon with the dialog box.
                    //chSETDLGICONS(hwnd, IDI\_DIRWALK, IDI\_DIRWALK);
                    SendMessage(hwnd, WM\_SETICON, TRUE, (LPARAM)LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI\_DIRWALK)));
                    SendMessage(hwnd, WM\_SETICON, FALSE, (LPARAM)LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI\_DIRWALK)));
                    
                    GetClientRect(hwnd, &rc);
                    SetWindowPos(GetDlgItem(hwnd, IDC\_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP\_NOZORDER);
                    
                    **strcpy(szPath, "< path to the directory to search >");
                    DlgDirList(hwnd, szPath, IDC\_TREE, 0, DDL\_DIRECTORY | DDL\_READWRITE); // populate the ListBox**
                    return(TRUE);
                    

                    }

                    Note that the DlgDirList function needs to write into szPath so it must be created in the way I have shown.

                    C 1 Reply Last reply
                    0
                    • L Lost User

                      I have now modified the Dlg_OnInitDialog function as below and the ListBox gets populated with file and directory names.

                      BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
                      {
                      RECT rc;
                      char szPath[MAX_PATH]; // reserve space for the path

                      // Associate an icon with the dialog box.
                      //chSETDLGICONS(hwnd, IDI\_DIRWALK, IDI\_DIRWALK);
                      SendMessage(hwnd, WM\_SETICON, TRUE, (LPARAM)LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI\_DIRWALK)));
                      SendMessage(hwnd, WM\_SETICON, FALSE, (LPARAM)LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI\_DIRWALK)));
                      
                      GetClientRect(hwnd, &rc);
                      SetWindowPos(GetDlgItem(hwnd, IDC\_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP\_NOZORDER);
                      
                      **strcpy(szPath, "< path to the directory to search >");
                      DlgDirList(hwnd, szPath, IDC\_TREE, 0, DDL\_DIRECTORY | DDL\_READWRITE); // populate the ListBox**
                      return(TRUE);
                      

                      }

                      Note that the DlgDirList function needs to write into szPath so it must be created in the way I have shown.

                      C Offline
                      C Offline
                      coco243
                      wrote on last edited by
                      #27

                      Yes, My Listbox was empty and I was't observed that it was a Listbox. Thank you, see you soon with new topics.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups