Can Someone fix this code. It will tell me how to do a LBUTONDOWN Click with-in the WndProc proc. This is from Icz LISTBOX tute. I striped most part and eliminated one of the ListBox Procedure so that I can try to get an LBUTTONDOWN click under the standard WndProc proc and not a ListBox proc. This is something that a have tried to do for a very long time with no success. Heres the whole thing so that its easy to know what I am talking about. I tried the 0FFFFh thing but it only allow you to close the whole window from any clicked point. I think my main problem is that I don't know where and how to use the 0FFFFh in the code. If you click the listbox its suppose to close. Thanks

; ########################################
.386
.model flat, stdcall
option casemap :none ; case sensitive

; ########################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

; ########################################
szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

m2m MACRO M1, M2
push M2
pop M1
ENDM

return MACRO arg
mov eax, arg
ret
ENDM

;=================
; Local prototypes
;=================
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

ListBox PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

.data
szDisplayName db "List Box Demo",0
CommandLine dd 0
hWnd dd 0
hInstance dd 0

hList1 dd 0
lpLstBox1 dd 0

.code

start:
invoke GetModuleHandle, NULL
mov hInstance, eax

invoke GetCommandLine
mov CommandLine, eax

invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax

; #######################################

WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW \
or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground, COLOR_WINDOW+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName
invoke LoadIcon,hInst,500 ; icon ID
mov wc.hIcon, eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hIconSm, 0
invoke RegisterClassEx, ADDR wc
szText szClassName,"Template_Class"

INVOKE CreateWindowEx,WS_EX_WINDOWEDGE,ADDR szClassName,ADDR szDisplayName,\
WS_OVERLAPPEDWINDOW ,100,\
0,300,375,NULL,NULL,hInst,NULL

mov hWnd,eax

invoke LoadMenu,hInst,600 ; menu ID
invoke SetMenu,hWnd,eax

invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd


;===================================
; Loop until PostQuitMessage is sent
;===================================

StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:

return msg.wParam

WinMain endp

; #######################################

WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD

LOCAL hCtl :DWORD

;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

.if uMsg == WM_CREATE

invoke ListBox,21,50,44,25,hWin,501
mov hList1, eax

invoke SetWindowLong,hList1,GWL_WNDPROC,ADDR WndProc
mov lpLstBox1, eax

;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
; mov eax,wParam
; and eax,0FFFFh
; .if eax == static1
; handle static1

;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

.elseif uMsg == WM_COMMAND

.if uMsg == WM_LBUTTONDOWN ;;;@@@ T H E WM_LBUTTONDOWN
mov eax,wParam
mov eax, hList1

.if hList1 == eax

invoke PostQuitMessage,NULL

invoke CallWindowProc,lpLstBox1,hCtl,uMsg,wParam,lParam

ret

.endif
.endif
;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


;======== menu commands ========
.if wParam == 1000
invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL
.endif


.elseif uMsg == WM_CLOSE

.if eax == IDNO
return 0
.endif
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
return 0
.endif

invoke DefWindowProc,hWin,uMsg,wParam,lParam

ret

WndProc endp


; ########################################

ListBox proc a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,hParent:DWORD,ID:DWORD

szText lstBox,"LISTBOX"

invoke CreateWindowEx,WS_EX_WINDOWEDGE,ADDR lstBox,0,
WS_CHILD or WS_VISIBLE or \
WS_BORDER or \
LBS_HASSTRINGS,
a,b,wd,ht,hParent,ID,hInstance,NULL

ret

ListBox endp


; ########################################

end start
Posted on 2001-11-03 20:33:38 by cmax
cmax,
Your code has several problems.


.elseif uMsg == WM_COMMAND
.if uMsg == WM_LBUTTONDOWN ;;;@@@ T H E WM_LBUTTONDOWN
mov eax,wParam
mov eax, hList1
.if hList1 == eax
invoke PostQuitMessage,NULL
invoke CallWindowProc,lpLstBox1,hCtl,uMsg,wParam,lParam
ret
.endif
.endif


First, you never get to the WM_LBUTTONDOWN line
because it is inside the WM_COMMAND handler.

Next, if the uMsg is WM_LBUTTONDOWN, wParam indicates
if any virtualkeys are down, NOT a handle.

Then you move wParam to eax and immediately move hList1 to eax.
when you compare eax to hList1, guess what ? they match ! but
like I said, this code is not getting executed.


The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_LBUTTONDOWN
WPARAM wParam, // key indicator
LPARAM lParam // horizontal and vertical position
);
Parameters
wParam
Indicates whether various virtual keys are down. This parameter can be one or more of the following values. Value Description
MK_CONTROL The CTRL key is down.
MK_LBUTTON The left mouse button is down.
MK_MBUTTON The middle mouse button is down.
MK_RBUTTON The right mouse button is down.
MK_SHIFT The SHIFT key is down.
MK_XBUTTON1 Windows 2000/XP: The first X button is down.
MK_XBUTTON2 Windows 2000/XP: The second X button is down.


lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

Return Values
If an application processes this message, it should return zero.


So to fix this you need to handle WM_LBUTTONDOWN on its own.
Then you could use lParam to see if you are over the listbox and
if you are, then destroy the listbox.

example:


.if uMsg == WM_LBUTTONDOWN
invoke GetClientRect,hList1,addr Rct
mov eax,lParam
and eax,0FFFFh ;mouse X position
mov edx,lParam,
shr edx,16 ; mouse Y position
.if eax >= Rct.left && eax <= Rct.right && edx >= Rct.top && edx <= Rct.bottom
invoke DestroyWindow,hList1
.endif
.elseif uMsg == WM_COMMAND

I did not try this code, but the general idea is correct.
You might have to use the API ScreenToClient to change the
listbox coordinants to match the mouse coordinants

Good Luck !
Posted on 2001-11-04 19:37:31 by anon
Another problem is that clicking on a control sends the WM_LBUTTONDOWN message to the control (gotta remember it's also a window) and not to the parent (enclosing) window. Each control type (class) has its own predefined window proc. That's where the WM_COMMAND and other notification messages are generated.

Most (if not all) controls avoid echoing mouse messages to the parent window. To capture the original mouse button message for a specific control, use subclassing (see Icz). I don't know if using the mouse capture functions will work the way you want them to.
Posted on 2001-11-05 15:26:55 by tank
Hey Guys
I been working with your ideas and it seems feable. I only get error A2166: structure field expected . . . . I tried to follow other programs that had simular coding as above (used in other ways) but could not match it structure field (if I was doing it right) . Anywayl one thing for sure, you guys pointed me in the right direction.

Thanks again
Posted on 2001-11-06 15:21:03 by cmax