flat assembler
Message board for the users of flat assembler.

Index > Windows > invoking CallWindowProc

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
Hi, people. Yesterday I was fighting Windows heroically for almost 5 hours trying to set button text font and color... I won at last, but still confused. Here's my question:
Microsoft gives an example for subclass procedure:
Code:
// Subclass procedure 
LRESULT APIENTRY EditSubclassProc(
    HWND hwnd, 
    UINT uMsg, 
    WPARAM wParam, 
    LPARAM lParam) 
{ 
    if (uMsg == WM_GETDLGCODE) 
        return DLGC_WANTALLKEYS; 
 
    return CallWindowProc(wpOrigEditProc, hwnd, uMsg, 
        wParam, lParam); 
}    

So, as I understand, wndproc has to return smth. if a message is processed or invoke CallWindowProc if a message is not processed (as stated in SDK)
For example:
Code:
proc ButtonSubclassProc, hWnd, uMsg, wParam, lParam
    mov eax, [uMsg]
    cmp eax, WM_PAINT
    jz .paint
    invoke CallWindowProc, <params>
    ret
  .paint:
    <message processing routine>
    xor eax, eax
    ret
    

But this makes my app crazy. It consumes 90% of CPU, it redraws the entire dialog, it doesn't work. The solution is simple: invoke CallWindowProc in the beginning, and then process messages (if any).
Code:
proc ButtonSubclassProc, hWnd, uMsg, wParam, lParam
    invoke CallWindowProc, <params>
    mov eax, [uMsg]
    cmp eax, WM_PAINT
    jz .paint
  .ret:
    xor eax, eax
    ret
  .paint:
    <message processing routine>
    jmp .ret
    

WHY IS IT SO??? Why should I invoke CallWindowProc and then process messages if Microsoft says to process messages, and invoke CallWindowProc for messages that are not processed???
Post 28 Apr 2006, 07:21
View user's profile Send private message Reply with quote
Kermil



Joined: 26 Oct 2005
Posts: 35
Location: Russia
Kermil
I see only one reason of such behaviour, you transfer wrong parameter to CallWindowProc. You should transfer to CallWindowProc correct address of old window procedure. But I can be mistaken. Show your code completely.
Post 28 Apr 2006, 08:51
View user's profile Send private message ICQ Number Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
here is the complete template:


Description:
Download
Filename: btn.zip
Filesize: 1.83 KB
Downloaded: 41 Time(s)

Post 29 Apr 2006, 10:29
View user's profile Send private message Reply with quote
Kermil



Joined: 26 Oct 2005
Posts: 35
Location: Russia
Kermil
I have looked your code and changed it, look below:

Code:
proc NumPadButtonsProc, hWnd, uMsg, wParam, lParam
    mov esi, [globals]
    mov eax, [uMsg]
    cmp eax, WM_PAINT
    jz .paint
    cmp eax, WM_LBUTTONDOWN
    jz .paint
    cmp eax, WM_LBUTTONDBLCLK
    jz .paint
    cmp eax, WM_LBUTTONUP
    jz .paint
    cmp eax, WM_MOUSEMOVE
    jz .paint
    cmp eax, WM_NCMOUSEMOVE
    jz .paint
    lea eax, [esi+global.lpDefNumPadButtonsProc]
    invoke CallWindowProc, [eax], [hWnd], [uMsg], [wParam], [lParam] ; not handled messages
    ret
.ret:
    mov eax, 1
    ret
.paint:
    lea eax, [esi+global.lpDefNumPadButtonsProc]
    invoke CallWindowProc, [eax], [hWnd], [uMsg], [wParam], [lParam] ; this call needed for drawing the button
    xor ecx, ecx
    mov edx, [hWnd]
    lea esi, [esi+global.hDlgMain_bn0]
  @@:
    lodsd
    cmp eax, edx
    jz .numpad
    inc ecx
    cmp ecx, (BN_SIGN-BN_0)
    jnz @b
    lodsd
    cmp eax, edx
    jnz .ret
  .numpad:
    shl ecx, 1
    lea esi, [ecx+szDlgMain_bn0Caption]
    push 00FF0000h      ;blue color
    push esi
    push eax
    call setButtonTextAndColor
    xor eax, eax
    ret
endp                     
    
Post 02 May 2006, 07:54
View user's profile Send private message ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.