How can i get the coordinates and size of an dialog item which is placed somewhere in a dialogbox. i want code a dialog with drag & drop support for some dialog items.
i tried to use GetWindowRect and GetClientRect, but they recieve the position and size of the dialog window and not the dialog item...
i tried to use GetWindowRect and GetClientRect, but they recieve the position and size of the dialog window and not the dialog item...
...
.elseif eax==WM_DROPFILES
push BTN_OK ;item ID
push hwnd ;dialog handle
push wparam ;hDrop
call DragInControl
.if eax==1
invoke MessageBox,hwnd,chr$("File was dropped into item"),chr$("DROP"),MB_OK
.endif
...
align 4
DragInControl proc _hdrop:dword,_dlg_handle:dword,_control_id:dword
LOCAL local_retvalue :byte
LOCAL item_rect :RECT
LOCAL pt :POINT
pushad
lea esi,item_rect
lea ebx,pt
assume esi:ptr RECT
assume ebx:ptr POINT
mov local_retvalue,0
invoke GetDlgItem,_dlg_handle,_control_id ;get handle of item
invoke GetWindowRect,eax,esi ;get x,y position and size of the item (doesnt work!!!)
invoke DragQueryPoint,_hdrop,ebx
invoke PtInRect,esi,.x,.y
.if eax
mov local_retvalue,1 ;file was dropped into this item
.endif
assume esi:nothing
assume ebx:nothing
popad
movzx eax,local_retvalue ;1=dragged into control else 0
ret
DragInControl endp
you have some errors in your code, try this
1.
2.
1.
BtnProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax == WM_DROPFILES
nop
.endif
invoke CallWindowProc,BtnDefWndProc,hWnd,uMsg,wParam,lParam
ret
BtnProc endp
DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hWnd,BTN_OK
invoke DragAcceptFiles,eax,TRUE
invoke GetDlgItem,hWnd,BTN_OK
invoke SetWindowLong,eax,GWL_WNDPROC,offset BtnProc
mov BtnDefWndProc,eax
...
2.
DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL rc:RECT,pt:POINT
...
.elseif eax == WM_DROPFILES
invoke GetDlgItem,hWnd,BTN_OK
lea edx,rc
invoke GetWindowRect,eax,edx
invoke GetCursorPos,addr pt
invoke PtInRect,addr rc,pt.x,pt.y
.if eax
nop
.endif
...
1.
Code:
BtnProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax == WM_DROPFILES
nop
.endif
invoke CallWindowProc,BtnDefWndProc,hWnd,uMsg,wParam,lParam
ret
BtnProc endp
DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hWnd,BTN_OK
invoke DragAcceptFiles,eax,TRUE
invoke GetDlgItem,hWnd,BTN_OK
invoke SetWindowLong,eax,GWL_WNDPROC,offset BtnProc
mov BtnDefWndProc,eax
...
Code:
BtnProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax == WM_DROPFILES
nop
.endif
invoke CallWindowProc,BtnDefWndProc,hWnd,uMsg,wParam,lParam
ret
BtnProc endp
DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
mov eax,uMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hWnd,BTN_OK
invoke DragAcceptFiles,eax,TRUE
invoke GetDlgItem,hWnd,BTN_OK
invoke SetWindowLong,eax,GWL_WNDPROC,offset BtnProc
mov BtnDefWndProc,eax
...
doesnt work, itried this method already before...
but this one works fine:
DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL rc:RECT,pt:POINT
...
.elseif eax == WM_DROPFILES
invoke GetDlgItem,hWnd,BTN_OK
lea edx,rc
invoke GetWindowRect,eax,edx
invoke GetCursorPos,addr pt
invoke PtInRect,addr rc,pt.x,pt.y
.if eax
nop
.endif
...
LOCAL rc:RECT,pt:POINT
...
.elseif eax == WM_DROPFILES
invoke GetDlgItem,hWnd,BTN_OK
lea edx,rc
invoke GetWindowRect,eax,edx
invoke GetCursorPos,addr pt
invoke PtInRect,addr rc,pt.x,pt.y
.if eax
nop
.endif
...
thank you very much drizz. i am just confused why the "DragQueryPoint" function exist...
code 1. works for me, i have no idea why it didnt work for you
DragQueryPoint is client relative
DragQueryPoint is client relative
invoke DragQueryPoint,wParam,addr pt
invoke ClientToScreen,hWnd,addr pt
DragQueryPoint is client relative
invoke DragQueryPoint,wParam,addr pt
invoke ClientToScreen,hWnd,addr pt
hmm, i just didnt know that i have to use it in combination of ClientToScreen. Anyway, i already implented this feature in my tool. its very comfortable... ;D