Hello all,
I converted to Masm some example that Donkey made in GoAsm, to try to insert it in a little tool I am working on.
Here is it:
It works beautifully but, for the life of me, I cannot understand where that lparam pointing to DRAWITEMSTRUCT, in the DrawStatusParts proc, is comming from.
Any help appreciated.
Best regards,
Bogdan
I converted to Masm some example that Donkey made in GoAsm, to try to insert it in a little tool I am working on.
Here is it:
;##################################################################
; ODStatusBar.Asm
;##################################################################
.386
.model flat,stdcall
option casemap:none
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
DrawStatusParts PROTO :DWORD,:DWORD
include WINDOWS.inc
include Comctl32.inc
include user32.inc
include kernel32.inc
include gdi32.inc
includelib comctl32.lib
includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib
STATUSPARAM struct
pszText DD ?
dwColor DD ?
hIcon DD ?
STATUSPARAM ends
IDD_DLG1 EQU 1000
IDC_SBR1 EQU 1001
.data?
hInstance DD ?
hStatus DD ?
sbParams DB (SIZEOF STATUSPARAM * 3) DUP (?)
.data
sbparts DD 60,120,-1,0,0
sbText1 DB "Part 1",0
sbText2 DB "Part 2",0
sbText3 DB "Part 3",0
.code
start:
invoke GetModuleHandleA, 0
mov hInstance,eax
invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_DLG1,0,offset DlgProc,0
invoke ExitProcess,0
DlgProc proc hwnd,uMsg,wParam,lParam
; mov eax,uMsg
.if uMsg==WM_INITDIALOG
invoke GetDlgItem,hwnd,IDC_SBR1
mov hStatus,eax
invoke SendMessage,hStatus,SB_SETPARTS,3,offset sbparts
push ebx
mov ebx,offset sbParams
mov ,offset sbText1
mov DWORD PTR ,00C08080h
invoke LoadIcon,NULL,IDI_ASTERISK
mov DWORD PTR ,eax
invoke SendMessage,hStatus,SB_SETTEXT,SBT_OWNERDRAW or 0,ebx
add ebx, SIZEOF STATUSPARAM
mov ,offset sbText2
mov DWORD PTR ,0080FFFFh
invoke LoadIcon,NULL,IDI_APPLICATION
mov DWORD PTR ,eax
invoke SendMessage,hStatus,SB_SETTEXT,SBT_OWNERDRAW or 1,ebx
add ebx, SIZEOF STATUSPARAM
mov ,offset sbText3
mov DWORD PTR ,008080FFh
invoke LoadIcon,NULL,IDI_WINLOGO
mov DWORD PTR ,eax
invoke SendMessage,hStatus,SB_SETTEXT,SBT_OWNERDRAW or 2,ebx
pop ebx
.elseif uMsg==WM_DRAWITEM
mov eax,wParam
xor eax,IDC_SBR1
.if ZERO?
invoke DrawStatusParts,wParam,lParam
.endif
.elseif uMsg==WM_CLOSE
INVOKE EndDialog,hwnd,0
mov eax,FALSE
ret
.else
mov eax,FALSE
ret
.endif
mov eax, TRUE
ret
DlgProc endp
DrawStatusParts proc uses ebx edi esi, wParam,lParam
mov ebx, lParam ; Pointer to DRAWITEMSTRUCT
mov edi, ; Pointer to STATUSPARAM for this part
or edi,edi
.if !ZERO?
invoke CreateSolidBrush,
push eax
mov esi,ebx
add esi,DRAWITEMSTRUCT.rcItem
invoke FillRect,,esi,eax
mov eax,
or eax,eax
.if !ZERO?
invoke DrawIconEx,,,,eax,16,16,NULL,NULL,DI_NORMAL
add DWORD PTR ,18
.endif
invoke SetBkMode,,TRANSPARENT
invoke SetTextColor,,0
invoke lstrlen,
invoke DrawText,,,eax,esi,DT_LEFT
pop eax
invoke DeleteObject,eax
.endif
ret
DrawStatusParts endp
end start
It works beautifully but, for the life of me, I cannot understand where that lparam pointing to DRAWITEMSTRUCT, in the DrawStatusParts proc, is comming from.
Any help appreciated.
Best regards,
Bogdan
DlgProc proc hwnd,uMsg,wParam,lParam
and in
.elseif uMsg==WM_DRAWITEM
mov eax,wParam
xor eax,IDC_SBR1
.if ZERO?
invoke DrawStatusParts,wParam,lParam
.endif
You are just passing on the wParam and lParam that windows passes to the DialogProc callback to the DrawStatusParts
Thank you Gunner!
I was curious about before that point, though. As you can see, the DlgProc has the required lparam needed for DrawStatusParts already. Who passed it to DlgProc? The ideea is that, if I would adjust DlgProc, and call it from outside, how the pointer to DRAWITEMSTRUCT (in lparam) is to be passed in?
Best regards,
Bogdan
I was curious about before that point, though. As you can see, the DlgProc has the required lparam needed for DrawStatusParts already. Who passed it to DlgProc? The ideea is that, if I would adjust DlgProc, and call it from outside, how the pointer to DRAWITEMSTRUCT (in lparam) is to be passed in?
Best regards,
Bogdan
Hello again,
I think I figured parts of the answer. AFAIU, for the WM_DRAWITEM (which in thurn will call the proper funtions and lparams) message to be sent, the control has to be OWNERDRAW (SS_OWNERDRAW=0x0000000D). This is the point where I got stuck. In the example above, is nowhere that SS_OWNERDRAW is mentionned or used (including the rc file).
How did Donkey do it?
Thank you in advance!
Best regards,
Bogdan
I think I figured parts of the answer. AFAIU, for the WM_DRAWITEM (which in thurn will call the proper funtions and lparams) message to be sent, the control has to be OWNERDRAW (SS_OWNERDRAW=0x0000000D). This is the point where I got stuck. In the example above, is nowhere that SS_OWNERDRAW is mentionned or used (including the rc file).
How did Donkey do it?
Thank you in advance!
Best regards,
Bogdan
This is solved! Thank you all that inspired me, including Gunner, Donkey and KetilO!
Best regards,
Bogdan
Best regards,
Bogdan
Can you share with us what you came up with?
farrier
farrier
Hi farrier,
It was a simple .if ZERO? instead of !ZERO? mistake, in proccesing the WM_DRAWITEM, so my DrawStatusParts proc was never called. Caught it with Ollydbg.
Best regards,
Bogdan
It was a simple .if ZERO? instead of !ZERO? mistake, in proccesing the WM_DRAWITEM, so my DrawStatusParts proc was never called. Caught it with Ollydbg.
Best regards,
Bogdan