On 11/1/2011 11:25 PM, Jorgen Grahn wrote:
> On Tue, 2011-11-01, Victor Bazarov wrote:
>> On 11/1/2011 7:44 AM, Jorgen Grahn wrote:
>>> On Mon, 2011-10-31, Paul N wrote:
>>>> I have a style question. In my code, I have a function that receives
>>>> messages, and deals with some of them while passing others on to a
>>>> further function. For instance:
>>>>
>>>> LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
>>>> LPARAM lParam)
>>>> {
>>>
>>> Speaking of style, one easy way of increasing readability would be to
>>> give meaningful names to those types, those parameters, and that
>>> function. They may not be under your control, but I have to say they
>>> are among the worst I've seen.
>>
>> For those who don't dabble in Windows API and messaging: the meaning of
>> 'wParam' and 'lParam' varies widely depending on the _value_ of
>> 'message'. Hence the generic names. It's been like this for some
>> thirty years, and I have never seen anybody manage to improve on that
>> much, or even enough for a mention. Some frameworks, like MFC, attempt
>> to lay out some structure over that system, and not totally
>> unsuccessfully, methinks, but for a generic message handler like the one
>> described by the OP there is no real hope. Perhaps the OP should look
>> into using one of those frameworks...
>
> I've never used these APIs (obviously) but I think I would break out
> of the crazy world of UINT and void* (if that is what's behind WPARAM
> and LPARAM) as soon as possible. I.e. call my own functions with more
> specific types as soon as I see what the callback is about.
That's exactly what those (MFC et al.) frameworks do. They define their
own generic handler and inside they have a rather large and convoluted
switch statement to dispatch the message to specific handlers that are
all declared with more specific types of arguments with more meaningful
names and often re-wrapped into more specific values of more meaningful
types (both Windows-SDK-defined and newly introduced by those frameworks).
> The inner structure (or lack thereof) of WndProc() seems less important.
Well, "WndProc" has been the workhorse of the Windows messaging API, and
it's how we all used to write Windows applications before those complete
frameworks came to be. It's primitive. It's simplistic. It gets the
job done. Keep in mind, Windows was running on a personal computer, in
real memory mode... As for programming, it was often recommended to
write your own class framework, but the basis was still the WndProc
functions (which you had to introduce in order to tie into Windows UI,
etc.) Absence of structure was not a concern at all because the purpose
was clear and the method was simple to grasp and easy to follow AFA
implementation goes. Besides, there were so many examples, and they all
looked very similar to what Charles Petzold put in his book^.
But I have digressed...
V
^ - Programming Windows by Charles Petzold, Microsoft Press, 1988.
--
I do not respond to top-posted replies, please don't ask
|