I am curious if someone can give me clue how to prevent a form from be moved or dragged with the caption bar. I have the form set to be centered, but need it to be unmovable, other than minimize or maximize.
Thanks,
Gary
In firefly, Trap %WM_NCHITTEST and reply with 1.
CASE %WM_NCHITTEST
FUNCTION = 1
I think....
Elias,
Thanks for the reply. I am still confused ??? where to put the code you suggested.
Gary
go to the CUSTOM handler for the dialog you want... and insert this code inside the function:
Select case wMsg
CASE %WM_NCHITTEST
FUNCTION = 1
end select
Ok.... I added the code to the FORM CUSTOM area. It compiles ok with no errors, but still allows the form to be moved.
Here is what I have
Function FRMHEADHOUSE_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %WM_NCHITTEST
Function = 1
End Select
End Function
I just made a test here and it works. Maybe you are doing something else with the message pump?
or catching the notification somewhere else? Is FRMHEADHOUSE a child dialog in another? Are you
receiving correctly the notification?
Can you do a small test with an empty form and see what happens? Preferably in a new project.
Just delete the Size/Move options from the system menu of the Form:
Quote
'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ ' optional user defined Long value
) As Long
Dim hMenu As Dword
hMenu = GetSystemMenu(hWndForm, 0)
DeleteMenu hMenu, %SC_SIZE, %MF_BYCOMMAND
DeleteMenu hMenu, %SC_MOVE, %MF_BYCOMMAND
End Function
I just had a brain fart ;D It took a little nap for me to realize what I had done ;D The form where I added the code is a tab form and not the main form....duh
Once I put the code in the right place, it did keep the form from being moved. What I am noticing now though is that I am not able to close the form with the X or minimize or maximize the form. It seems that nothing on the caption bar does anything.
Any ideas on that?
Thanks again,
Gary
Using Elias' code you would have to specifically check for where the non-client hit test is being actioned.
'--------------------------------------------------------------------------------
Function FORM1_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Select Case wMsg
Case %WM_NCHITTEST
Select Case DefWindowProc( hWndForm, wMsg, wParam, lParam)
Case %HTSYSMENU, %HTMINBUTTON, %HTMAXBUTTON, %HTCLOSE ' allow these
Case Else ' don't allow anything else
Function = 1
End Select
End Select
End Function
If you allow access to %HTSYSMENU then you still have the problem of the user being able to access "Size" and "Move" from that menu. My solution that I posted earlier that removes the size and Move from the system menu works perfectly. The user can not drag or resize the Form via mouse or keyboard. Simple, and no hit testing needed.
:)
Paul and Elias,
Thanks for the help.... the code you supplied worked great. I wish I understood more about the API and what all is available there. It still seems like a big mystery to me. :o
Thanks again,
Gary
Hi Gary,
I can recommend 'Appleman's book. Big book, great book. Written for VB but once you understand it you can apply it in basically any language that allows sending and intercepting Windows messages.
Wilko
Wish I would have seen this earlier, I do this stuff all the time. I probably would have posted code just like Paul's. I don't think I have a single program where I don't edit the Sys Menu. Even making the frame not sizable I still like removing the entry in the menu just to clean up clutter. Pretty cool adding your own items there too like sending to the tray, etc. Lookup %SC_ in the API inc file for all kinds of other fun ones you can add like Screensaver and such. I even use it in .Net since it doesn't have a way to lock the Window. The hit test message I usually use for mouse cursor stuff or for windows where I may not have a titlebar and trick Windows into thinking I'm clicking the titlebar when I click the client area so I can drag the window still.