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.
  • L Lost User

    I think you are missing the DS_MODALFRAME style from your dialog template. And your message handlers could contain anything - we cannot see the code. As I already suggested to you, get rid of these big defines and put the source in your handler. You will then at least have a chance of finding out what is wrong, as will we. And a better place to learn how to code for Dialogs is at About Dialog Boxes - Win32 apps | Microsoft Docs[^.

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

    Thank you for your response, unfortunately not DS_MODALEFRAME is the problem The problem is ( I think ), that when DialogBox function is called in WinMain, its associated procedure function Dlg_ProcDlg_Proc isn't executed.

    Richard MacCutchan wrote:

    And your message handlers could contain anything - we cannot see the code.

    Are you reffering to Dlg_OnInitDialog as message handlers? It's code is:

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

    // Associate an icon with the dialog box.
    chSETDLGICONS(hwnd, IDI\_DIRWALK, IDI\_DIRWALK);
    
    // here is some code that I didn't got to, or have patience to write
    
    GetClientRect(hwnd, &rc);
    SetWindowPos(GetDlgItem(hwnd, IDC\_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP\_NOZORDER);
    
    return(TRUE);
    

    }

    And the macro for chSETDLGICONS(hwnd, IDI_DIRWALK, IDI_DIRWALK); :D is:

    #define chINITSTRUCT(structure, fInitSize) \
    (ZeroMemory(&(structure), sizeof(structure)), \
    fInitSize ? (*(int*) &(structure) = sizeof(structure)) : 0)

    // Dialog Box Icon Setting Macro
    // The call to SetClassLong is for Windows NT 3.51 or less.
    // The WM_SETICON messages are for Windows NT 4.0 and Win 95
    #define chSETDLGICONS(hwnd, idiLarge, idiSmall) \
    { \
    OSVERSIONINFO VerInfo; \
    chINITSTRUCT(VerInfo, TRUE); \
    GetVersionEx(&VerInfo); \
    if ((VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && \
    (VerInfo.dwMajorVersion <=3 && \
    VerInfo.dwMinorVersion <= 51)) \
    { \
    SetClassLong(hwnd, GCL_HICON, (LONG) \
    LoadIcon(GetWindowInstance(hwnd), \
    MAKEINTRESOURCE(idiLarge))); \
    } \
    else \
    { \
    SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM) \
    LoadIcon(GetWindowInstance(hwnd), \
    MAKEINTRESOURCE(idiLarge))); \
    SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM) \
    LoadIcon(GetWindowInstance(hwnd),

    L 1 Reply Last reply
    0
    • C coco243

      Thank you for your response, unfortunately not DS_MODALEFRAME is the problem The problem is ( I think ), that when DialogBox function is called in WinMain, its associated procedure function Dlg_ProcDlg_Proc isn't executed.

      Richard MacCutchan wrote:

      And your message handlers could contain anything - we cannot see the code.

      Are you reffering to Dlg_OnInitDialog as message handlers? It's code is:

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

      // Associate an icon with the dialog box.
      chSETDLGICONS(hwnd, IDI\_DIRWALK, IDI\_DIRWALK);
      
      // here is some code that I didn't got to, or have patience to write
      
      GetClientRect(hwnd, &rc);
      SetWindowPos(GetDlgItem(hwnd, IDC\_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP\_NOZORDER);
      
      return(TRUE);
      

      }

      And the macro for chSETDLGICONS(hwnd, IDI_DIRWALK, IDI_DIRWALK); :D is:

      #define chINITSTRUCT(structure, fInitSize) \
      (ZeroMemory(&(structure), sizeof(structure)), \
      fInitSize ? (*(int*) &(structure) = sizeof(structure)) : 0)

      // Dialog Box Icon Setting Macro
      // The call to SetClassLong is for Windows NT 3.51 or less.
      // The WM_SETICON messages are for Windows NT 4.0 and Win 95
      #define chSETDLGICONS(hwnd, idiLarge, idiSmall) \
      { \
      OSVERSIONINFO VerInfo; \
      chINITSTRUCT(VerInfo, TRUE); \
      GetVersionEx(&VerInfo); \
      if ((VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && \
      (VerInfo.dwMajorVersion <=3 && \
      VerInfo.dwMinorVersion <= 51)) \
      { \
      SetClassLong(hwnd, GCL_HICON, (LONG) \
      LoadIcon(GetWindowInstance(hwnd), \
      MAKEINTRESOURCE(idiLarge))); \
      } \
      else \
      { \
      SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM) \
      LoadIcon(GetWindowInstance(hwnd), \
      MAKEINTRESOURCE(idiLarge))); \
      SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM) \
      LoadIcon(GetWindowInstance(hwnd),

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

      coco243 wrote:

      But the program dosen't reach the Dlg_OnInitDialog, I placed a breakpoint there.

      Where is the code for chHANDLE_DLGMSG? I keep telling you to get rid of these ridiculous #define statements; they are just making it more difficult to see what is happening.

      C 1 Reply Last reply
      0
      • L Lost User

        coco243 wrote:

        But the program dosen't reach the Dlg_OnInitDialog, I placed a breakpoint there.

        Where is the code for chHANDLE_DLGMSG? I keep telling you to get rid of these ridiculous #define statements; they are just making it more difficult to see what is happening.

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

        Here it is the code: ( it was in the first post too, I will modify de macros )

        #define chHANDLE_DLGMSG(hWnd, message, fn) \
        case (message): \
        return (SetDlgMsgResult(hwnd, uMsg, HANDLE_##message((hwnd), (wParam), (lParam), (fn))))

        Thank you,

        L 1 Reply Last reply
        0
        • C coco243

          Here it is the code: ( it was in the first post too, I will modify de macros )

          #define chHANDLE_DLGMSG(hWnd, message, fn) \
          case (message): \
          return (SetDlgMsgResult(hwnd, uMsg, HANDLE_##message((hwnd), (wParam), (lParam), (fn))))

          Thank you,

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

          So you have a macro inside a macro which just makes it worse. I suggest you throw this code (and that book) away and write a proper inline handler. I have just tested your template and it loads the dialog and handles the WM_INITDIALOG message:

          INT\_PTR CALLBACK DlgProc(
          	HWND	hDlg,
          	UINT	uMessage,
          	WPARAM	wParam,
          	LPARAM	lParam
          )
          {
          	switch (uMessage)
          	{
          	case WM\_INITDIALOG:
          		return OnInitDialog(hDlg, (HWND)wParam, lParam); // calls the initialization function
          
          	case WM\_COMMAND:
          		return OnCommand(hDlg, LOWORD(wParam), (HWND)lParam, HIWORD(wParam)); // handles any button etc. messages
          
          	}
          
          	return false; // default processing
          }
          
          C 1 Reply Last reply
          0
          • L Lost User

            So you have a macro inside a macro which just makes it worse. I suggest you throw this code (and that book) away and write a proper inline handler. I have just tested your template and it loads the dialog and handles the WM_INITDIALOG message:

            INT\_PTR CALLBACK DlgProc(
            	HWND	hDlg,
            	UINT	uMessage,
            	WPARAM	wParam,
            	LPARAM	lParam
            )
            {
            	switch (uMessage)
            	{
            	case WM\_INITDIALOG:
            		return OnInitDialog(hDlg, (HWND)wParam, lParam); // calls the initialization function
            
            	case WM\_COMMAND:
            		return OnCommand(hDlg, LOWORD(wParam), (HWND)lParam, HIWORD(wParam)); // handles any button etc. messages
            
            	}
            
            	return false; // default processing
            }
            
            C Offline
            C Offline
            coco243
            wrote on last edited by
            #7

            I changed the Dlg_Proc as you have said to me. But my problem is that the program doesn't reach to the DlgProc function to be called. I don't know why, what to do? but DialogBox function from WinMain doesn't call DlgProc. I think that here is the problem. When I play the program it doesn't do any thing. Just execute, nothing displaied, and that's it.

            C 1 Reply Last reply
            0
            • C coco243

              I changed the Dlg_Proc as you have said to me. But my problem is that the program doesn't reach to the DlgProc function to be called. I don't know why, what to do? but DialogBox function from WinMain doesn't call DlgProc. I think that here is the problem. When I play the program it doesn't do any thing. Just execute, nothing displaied, and that's it.

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

              Ok. Let's start over. I have elimiated the macros. So: .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:
              SetDlgMsgResult(hwnd, uMsg, HANDLE_WM_INITDIALOG(hwnd, wParam, lParam, Dlg_OnInitDialog));
              //return Dlg_OnInitDialog(hwnd, (HWND)wParam, lParam);
              break;
              //chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
              //chHANDLE_DLGMSG(hwnd, WM_SIZE, Dlg_OnSize);

              }
              
              return(FALSE);
              

              }

              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 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"

              // Dialog
              IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
              STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|

              D L 3 Replies Last reply
              0
              • C coco243

                Ok. Let's start over. I have elimiated the macros. So: .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:
                SetDlgMsgResult(hwnd, uMsg, HANDLE_WM_INITDIALOG(hwnd, wParam, lParam, Dlg_OnInitDialog));
                //return Dlg_OnInitDialog(hwnd, (HWND)wParam, lParam);
                break;
                //chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
                //chHANDLE_DLGMSG(hwnd, WM_SIZE, Dlg_OnSize);

                }
                
                return(FALSE);
                

                }

                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 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"

                // Dialog
                IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
                STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #9

                In your Dlg_Proc() handler, all messages are returning FALSE. Handled messages should return TRUE.

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                1 Reply Last reply
                0
                • C coco243

                  Ok. Let's start over. I have elimiated the macros. So: .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:
                  SetDlgMsgResult(hwnd, uMsg, HANDLE_WM_INITDIALOG(hwnd, wParam, lParam, Dlg_OnInitDialog));
                  //return Dlg_OnInitDialog(hwnd, (HWND)wParam, lParam);
                  break;
                  //chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
                  //chHANDLE_DLGMSG(hwnd, WM_SIZE, Dlg_OnSize);

                  }
                  
                  return(FALSE);
                  

                  }

                  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 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"

                  // Dialog
                  IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
                  STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|

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

                  Change this:

                  	SetDlgMsgResult(hwnd, uMsg, HANDLE\_WM\_INITDIALOG(hwnd, wParam, lParam, Dlg\_OnInitDialog));
                  

                  to this

                  	HANDLE\_WM\_INITDIALOG(hwnd, wParam, lParam, Dlg\_OnInitDialog);
                      return TRUE;
                  

                  You only need to set a dialog result when you exit for the last time. And unless you need the result in your calling code then it is best to do nothing. I think this book is so far behind the times that it is teaching you the wrong things, and the wrong way to do things.

                  C 1 Reply Last reply
                  0
                  • C coco243

                    Ok. Let's start over. I have elimiated the macros. So: .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:
                    SetDlgMsgResult(hwnd, uMsg, HANDLE_WM_INITDIALOG(hwnd, wParam, lParam, Dlg_OnInitDialog));
                    //return Dlg_OnInitDialog(hwnd, (HWND)wParam, lParam);
                    break;
                    //chHANDLE_DLGMSG(hwnd, WM_INITDIALOG, Dlg_OnInitDialog);
                    //chHANDLE_DLGMSG(hwnd, WM_SIZE, Dlg_OnSize);

                    }
                    
                    return(FALSE);
                    

                    }

                    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 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"

                    // Dialog
                    IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
                    STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|

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

                    Here is the definitive guide: Dialog Boxes (Dialog Boxes) - Win32 apps | Microsoft Docs[^]

                    1 Reply Last reply
                    0
                    • L Lost User

                      Change this:

                      	SetDlgMsgResult(hwnd, uMsg, HANDLE\_WM\_INITDIALOG(hwnd, wParam, lParam, Dlg\_OnInitDialog));
                      

                      to this

                      	HANDLE\_WM\_INITDIALOG(hwnd, wParam, lParam, Dlg\_OnInitDialog);
                          return TRUE;
                      

                      You only need to set a dialog result when you exit for the last time. And unless you need the result in your calling code then it is best to do nothing. I think this book is so far behind the times that it is teaching you the wrong things, and the wrong way to do things.

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

                      In my opinion I can change the content of the Dlg_Proc for infinite because I don't know why, the program just don't get to that Function Procedure. And I don't know why you are ignoring me when I am telling you that my DialogBox function from WinMain doesn't starts the Dlg_Proc procedure never. Please explain me that because I don't understand. All I want to do for now is to see that my program stops at a breakpoint on the Dlg_Proc. Are VC project settings? This is all the code that I have. I am missing something? Just please explain me why the DialogBox doesn't starts its procedure. I know to implplement dialog boxes, I have implemented a few, the problem in this topic is that I can't aproach this kind of message handling procedure. And I am sorry if I repeat myself and you try to explain me and I am not able to understand but... "Why the DialogBox from WinMain doesn't start the Dlg_Proc afferent procedure?" Thank you,

                      L 1 Reply Last reply
                      0
                      • C coco243

                        In my opinion I can change the content of the Dlg_Proc for infinite because I don't know why, the program just don't get to that Function Procedure. And I don't know why you are ignoring me when I am telling you that my DialogBox function from WinMain doesn't starts the Dlg_Proc procedure never. Please explain me that because I don't understand. All I want to do for now is to see that my program stops at a breakpoint on the Dlg_Proc. Are VC project settings? This is all the code that I have. I am missing something? Just please explain me why the DialogBox doesn't starts its procedure. I know to implplement dialog boxes, I have implemented a few, the problem in this topic is that I can't aproach this kind of message handling procedure. And I am sorry if I repeat myself and you try to explain me and I am not able to understand but... "Why the DialogBox from WinMain doesn't start the Dlg_Proc afferent procedure?" Thank you,

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

                        The DialogBox does start, but because your code is invalid it terminates (almost) immediately. I have changed your DialogProc to the following just to make it work:

                        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;
                        

                        }

                        But that is just to get the dialog to start and be able to close it. To do anything useful would require a lot of rewriting, or better still, start clean with up to date code.

                        C 1 Reply Last reply
                        0
                        • L Lost User

                          The DialogBox does start, but because your code is invalid it terminates (almost) immediately. I have changed your DialogProc to the following just to make it work:

                          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;
                          

                          }

                          But that is just to get the dialog to start and be able to close it. To do anything useful would require a lot of rewriting, or better still, start clean with up to date code.

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

                          Richard MacCutchan wrote:

                          The DialogBox does start, but because your code is invalid it terminates (almost) immediately. I have changed your DialogProc to the following just to make it work:

                          The DialogBox does start, but it's procedure Dlg_Proc doesn't start, you can modify this procedeure over and over for one thousand times, is not the problem there. How invalid the code will be, if I put a break point inside of Dlg_Proc should stop there, but the program never goes there. Please listen to me, help me to understand why the MessageBox doesn't start DlgProc procedeure. Maybe are project setings or I don't know. The problem is that the Dlg_Proc is never reched and never executed. Please take my code where I copied all my file apart .cpp .rc the resource file to see that I am right. Something is missing to me, I don't know why. Maybe somwthing more is need it but please listen on what I am saying, the problem is that the MessageBox function doesn't start the Dlg_Proc

                          L 2 Replies Last reply
                          0
                          • C coco243

                            Richard MacCutchan wrote:

                            The DialogBox does start, but because your code is invalid it terminates (almost) immediately. I have changed your DialogProc to the following just to make it work:

                            The DialogBox does start, but it's procedure Dlg_Proc doesn't start, you can modify this procedeure over and over for one thousand times, is not the problem there. How invalid the code will be, if I put a break point inside of Dlg_Proc should stop there, but the program never goes there. Please listen to me, help me to understand why the MessageBox doesn't start DlgProc procedeure. Maybe are project setings or I don't know. The problem is that the Dlg_Proc is never reched and never executed. Please take my code where I copied all my file apart .cpp .rc the resource file to see that I am right. Something is missing to me, I don't know why. Maybe somwthing more is need it but please listen on what I am saying, the problem is that the MessageBox function doesn't start the Dlg_Proc

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

                            I told you how to fix it, copy the code from my previous message into your DialogProc. I know that works because I have tested it. If it still does not work for you then there is something else that you are not showing us.

                            C 1 Reply Last reply
                            0
                            • C coco243

                              Richard MacCutchan wrote:

                              The DialogBox does start, but because your code is invalid it terminates (almost) immediately. I have changed your DialogProc to the following just to make it work:

                              The DialogBox does start, but it's procedure Dlg_Proc doesn't start, you can modify this procedeure over and over for one thousand times, is not the problem there. How invalid the code will be, if I put a break point inside of Dlg_Proc should stop there, but the program never goes there. Please listen to me, help me to understand why the MessageBox doesn't start DlgProc procedeure. Maybe are project setings or I don't know. The problem is that the Dlg_Proc is never reched and never executed. Please take my code where I copied all my file apart .cpp .rc the resource file to see that I am right. Something is missing to me, I don't know why. Maybe somwthing more is need it but please listen on what I am saying, the problem is that the MessageBox function doesn't start the Dlg_Proc

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

                              I ran a further test and discovered that the resource compiler did not generate the correct output file. The resulting resource object was missing the dialog, so that was why your code immediately terminated. However, I cannot reproduce your environment as I do not have the old version of Visual Studio. So the corrections I made are to make use of the Visual Studio 2022 environment. As I keep saying, stop wasting time with this out of date code (and book) and move on to the latest version of Visual Studio, and the associated documentation.

                              1 Reply Last reply
                              0
                              • L Lost User

                                I told you how to fix it, copy the code from my previous message into your DialogProc. I know that works because I have tested it. If it still does not work for you then there is something else that you are not showing us.

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

                                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 1 Reply Last reply
                                0
                                • 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
                                          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