CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: winap Dialogbox ..

  1. #1
    Join Date
    Jul 2013
    Posts
    161

    winap Dialogbox ..

    so from the book I'm reading... windows programming, charles petzold ...
    HTML Code:
    -a dialog box procedure returns a BOOL.
    -a dialogbox procedure does not need to process a WM_PAIN or WM_DESTROY messages. A dialog box procedure will  not receive a WM_CREATE message. Instead the dialogbox procedure performs initialization during the special WM_INITDIALOG message.
    but the sample source code I'm using to garner some little experience is going against the rules...
    Code:
    static INT_PTR CALLBACK mainDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
      switch(msg)
      {
        case WM_INITDIALOG: 
        {
         
        }
    
        case WM_DESTROY: // this should not be possible from the definition no???
        {
         
        }
    
        case WM_CLOSE: 
        {
          
        }
    
        case WM_COMMAND: 
        {
          
          }
         
        }
    
        default:
          return FALSE;
      }
      
      return TRUE;
    }
    and we can clearly noticed the dialogprocedure is not returning a BOOL..
    SO WHAT IS WHAT AND WHAT IS WHAT NOT??? thanks in advance to all who help...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,797

    Re: winap Dialogbox ..

    Quote Originally Posted by TheLionKing View Post
    so from the book I'm reading... windows programming, charles petzold ...
    HTML Code:
    -a dialog box procedure returns a BOOL.
    -a dialogbox procedure does not need to process a WM_PAIN or WM_DESTROY messages. A dialog box procedure will  not receive a WM_CREATE message. Instead the dialogbox procedure performs initialization during the special WM_INITDIALOG message.
    but the sample source code I'm using to garner some little experience is going against the rules...
    Code:
    static INT_PTR CALLBACK mainDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    ...
        default:
          return FALSE;
      }
      
      return TRUE;
    }
    and we can clearly noticed the dialogprocedure is not returning a BOOL..
    SO WHAT IS WHAT AND WHAT IS WHAT NOT??? thanks in advance to all who help...
    As you can see from the code snippet you have posted the dialogprocedure is returning a BOOL (eiter FALSE or TRUE)
    If you are uncertain about the mainDialogProc signature (INT_PTR9 then you have to accept that in Win32 (as long as in the plain C) there is no such a "special" type as boolean, so the #typedef is used to define BOOL as to be INT (or just INT_PTR) in the case when only two possible return values are assumed: TRUE (something that is not 0) or FALSE (0)
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2013
    Posts
    161

    Re: winap Dialogbox ..

    thanks master VictorN, do you have an explanation for the case WM_DESTROY in a dialogprocedure???
    thanks

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: winap Dialogbox ..

    From where was this brilliant piece of sample code obtained? Why static? You don't even need to process WM_CLOSE. See https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

  5. #5
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: winap Dialogbox ..

    2kaud, it's alright to have it as a static. I've tossed my old Petzold book in the bin many years ago so I don't know how it was done there but I remember having it static most times during my years of plain C win32 programming.

    It's many years since I did anything in windows using plain C but I guess that in most cases the Window/DialogProc is in the same file as the call to CreateWindow/Dialog and also specific that that particular window so it doesn't have to be visible to the outside world.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,607

    Re: winap Dialogbox ..

    Quote Originally Posted by TheLionKing View Post
    do you have an explanation for the case WM_DESTROY in a dialogprocedure???
    The explanation is rather simple: semantically, "does not need" is not equivalent to "not possible". However, I would make sure the messages are really delivered to dialog procedure. You know, anybody may write silly things in public samples, but OS lives its own life and has its own laws.

    As to BOOL vs INT_PTR. It depends on what version of Petzold's book you refer to. In Win16 and Win32 early ages BOOL was a right choice. Contemporary Win32 adopts both 32- and 64-bit architectures, so INT_PTR is the right choice nowadays. Read books, but refer to MSDN.
    Last edited by Igor Vartanov; April 13th, 2016 at 10:10 AM.
    Best regards,
    Igor

  7. #7
    Join Date
    Jul 2013
    Posts
    161

    Re: winap Dialogbox ..

    infact later I assumed this Idea, ie..does not need does not exclude not possible...thanks for comfirming it...

    well the petzold's book I'm using is very very old...thats what I could managed to find on torrents sites...any link to a more updated
    one for free ? :P lool
    thanks for you time Master Igor Vartanov

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,267

    Re: winap Dialogbox ..

    any link to a more updated one for free ?
    See the MSDN link in my post #4.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.4)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)