Hi, can someone give me an idea on how to prevent a window from being dragged around by its title bar? I am sure there is a message to ignore or change but I can't figure it out. A general link towards tricks with messages would be great too :U
I'm off to read some more Petzold...
Regards, Don.
Use WM_NCLBUTTONDOWN and WM_NCLBUTTONDBLCLK
WM_NCLBUTTONDOWN will let you know what area of the non client area you are in via wParam (HITTEST). I assume want to inhibit people from invoking the control box, because that can be done by clicking on the control box or double clicking in the caption area, hence the need to test WM_NCLBUTTONDBLCLK
Try this thread, too: http://www.masm32.com/board/index.php?topic=8229.0
Don,
have a look at the windows style WS_POPUP without a tile bar. No title bar no movement from the title bar.
The WM_MOVING message is designed to do this.
cmp D[uMsg], WM_MOVING
jne >.NXTMSG
mov ecx, [lParam]
mov eax, [rcFixedRect.Left]
mov [ecx+RECT.Left], eax
mov eax, [rcFixedRect.Top]
mov [ecx+RECT.Top], eax
mov eax, [rcFixedRect.Right]
mov [ecx+RECT.Right], eax
mov eax, [rcFixedRect.Bottom]
mov [ecx+RECT.Bottom], eax
xor eax,eax
inc eax
ret
rcFixedRect is a RECT structure filled with the co-ordinates of the windows fixed position.
Donkey
Another message you could handle is WM_GETMINMAXINFO.
As a note, the examples given here except for hutch's assumes you want your window to have a sizing border, but yet inhibit that function.
If this is not the case then creating a window as per hutch's example is the most expedient method
That being said, one can amply see how important it is to understand each of the window's messages and it nuances as there are many ways to skin a cat.
Quote from: donkey on January 29, 2008, 12:18:32 AM
mov eax, [rcFixedRect.Bottom]
rcFixedRect is a RECT structure filled with the co-ordinates of the windows fixed position.
Donkey
Attention, Donkey uses his own assembler, and "Bottom" will throw an error in MASM. Below a snippet showing how these structures can be used. "bottom", all lowercase, would work.
include \masm32\include\masm32rt.inc
.data?
rc2 RECT <?>
.data
rc RECT <12,13,14,15>
.code
AppName db "Test",0
start:
mov eax, rc.right
mov ecx, offset rc2
mov [ecx+RECT.right], eax
invoke MessageBox, 0, str$(rc2.right), addr AppName, MB_OK
invoke ExitProcess,0
end start
and you could also use mov [ecx.RECT.right]. eax too, which to me reads better.. each to their own tho
Hi everyone, thanks for all of the tips. To clear things up a bit:
My aim is to display a window with a title bar in the centre of the screen . I would like the window it to have a window title but no control icons (min, max, etc.). All of this I have achieved without incident. To prevent it from moving I have tried Donkey's suggestion regarding WM_MOVING but my application crashes after about 20 clicks on the title bar (I do enjoy testing :bg). Here is the code I am using:
.elseif uMsg == WM_MOVING
mov eax, WinXPos
mov [lParam+RECT.left], eax
add eax, cWinWidth
mov [lParam+RECT.right], eax
mov eax, WinYPos
mov [lParam+RECT.top], eax
add eax, cWinHeight
mov [lParam+RECT.bottom], eax
xor eax,eax
inc eax
ret
WinXPos and WinYPos are calculated earlier. cWinWidth and cWinHeight are constants that are used to create the window. lParam is passed into the proc and not changed prior to handling the message.
I did find that ReleaseCapture worked quite well but there is an annoying flicker of the window:
.elseif uMsg == WM_MOVING
invoke ReleaseCapture
xor eax,eax
inc eax
ret
Please hit me with a clue stick quick :lol
You need to move lParam into a register (just like Donkey did) and use that in your mov statements - at the moment you are corrupting the stack.
Cheers,
Zooba :U
Thanks Zooba, consider the clue stick well and truly embedded.
And thanks to all of you for taking the time to answer - I was completely stumped by all of the WM_ possibilities. I am very comfortable with CLI apps but this new fangled windows thing takes a bit of getting used to :U
Regards, Don.