-
April 6th, 2016, 04:01 PM
#1
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...
-
April 6th, 2016, 04:18 PM
#2
Re: winap Dialogbox ..
Originally Posted by TheLionKing
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
-
April 6th, 2016, 04:34 PM
#3
Re: winap Dialogbox ..
thanks master VictorN, do you have an explanation for the case WM_DESTROY in a dialogprocedure???
thanks
-
April 7th, 2016, 06:19 AM
#4
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
April 12th, 2016, 02:22 PM
#5
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.
-
April 13th, 2016, 10:04 AM
#6
Re: winap Dialogbox ..
Originally Posted by TheLionKing
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
-
April 13th, 2016, 10:12 AM
#7
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
-
April 13th, 2016, 01:49 PM
#8
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++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|