Nazgulled Posted December 18, 2004 Posted December 18, 2004 What I basically want to do is not to allow the user to move the form window around... For the whole WndProc Function I had the following code before: This is just the constantes I use so you know cause I may be doing something wrong with them: Private Const WM_NCRBUTTONDOWN As Integer = &HA4 Private Const WM_QUERYENDSESSION As Integer = &H11 Private Const WM_NCHITTEST As Integer = &H84 Private Shared HTCLIENT As New IntPtr(1) Private Shared HTCAPTION As New IntPtr(2) If (m.Msg = WM_NCHITTEST) Then MyBase.WndProc(m) If (IntPtr.op_Equality(m.Result, HTCAPTION)) Then m.Result = HTCLIENT End If ElseIf (m.Msg = WM_QUERYENDSESSION) Then exitApp = True Me.notifyIcon.Visible = False MyBase.WndProc(m) Else MyBase.WndProc(m) End If but then I realized I could still move the windo right clicking on the titlbar and choose "Move" from the menu... so what I thought to "fix" tha was to disable that menu and to disable that I could disable the rightclick on the titlebar with the following code: If (m.Msg = WM_NCRBUTTONDOWN) Then Return ElseIf (m.Msg = WM_NCHITTEST) Then MyBase.WndProc(m) If (IntPtr.op_Equality(m.Result, HTCAPTION)) Then m.Result = HTCLIENT End If ElseIf (m.Msg = WM_QUERYENDSESSION) Then exitApp = True Me.notifyIcon.Visible = False MyBase.WndProc(m) Else MyBase.WndProc(m) End If However, that code doesn't work. It doesn't matter if I right click on the titlebar, the code will go through the If (m.Msg = WM_NCRBUTTONDOWN) directly to ElseIf (m.Msg = WM_NCHITTEST). That's why I tried to change from WM_NCHITTEST to WM_NCLBUTTONDOWN as you could see in my other replys, cause doing it that way he would go to the first If because one was for the right click and the other to left click but I had some other problems wich are making me go back to this code I had before. So, my real problem is, how to disable the rightclick menu on the titlebar? How can I make it respond to the If (m.Msg = WM_NCRBUTTONDOWN) before going directly to ElseIf (m.Msg = WM_NCHITTEST)? I hope I didn't make any confusion... Quote
neodammer Posted December 18, 2004 Posted December 18, 2004 Use directx coding or you could get clever and somewhat simple by just making a timer set to like oh i dont know 1 just keep the window at one position on the screen like 250,250 that way nobody could really move it. Quote Enzin Research and Development
Nazgulled Posted December 18, 2004 Author Posted December 18, 2004 nevermind, I just fixed it with something like this: Select Case (m.Msg) Case WM_NCRBUTTONDOWN If (m.WParam.ToInt32() = HTCAPTION) Then Return Case WM_NCLBUTTONDOWN If (m.WParam.ToInt32() = HTCAPTION) Then Me.Activate() Return End If End Select Quote
Leaders dynamic_sysop Posted December 19, 2004 Leaders Posted December 19, 2004 you could always remove the ' Move ' MenuItem from your Form , so that the menu option to move it is gone , eg: Private Declare Function GetSystemMenu Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal bRevert As Int32) As Int32 Private Declare Function RemoveMenu Lib "user32.dll" (ByVal hMenu As Int32, ByVal nPosition As Int32, ByVal wFlags As Int32) As Int32 Private Const MF_BYPOSITION As Int32 = &H400I Private Const MF_DISABLED As Int32 = &H2I Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim hMenu As Int32 = GetSystemMenu(MyBase.Handle, 0) If (hMenu > 0) Then Dim MOVEMENU As Int32 = 1 '/// this is the normal index of the ' Move ' menuitem RemoveMenu(hMenu, MOVEMENU, MF_BYPOSITION Or MF_DISABLED) End If End Sub ;) Quote
Nazgulled Posted December 19, 2004 Author Posted December 19, 2004 thx, but I think they way I did it is simpler and has less lines of code and besides. I have an option on my app that if it's active then the user can't move the form if it's not then he can freely move it and it's easier to make that validation. anyway thx. how do you do that vb.net syntax here in the forum? Quote
Leaders dynamic_sysop Posted December 19, 2004 Leaders Posted December 19, 2004 the vb syntax is done by [ vb ] --- code --- [ /vb ] without the spaces. the menu thing , what you must consider is, if you want to make a form that doesn't move, but it has a menu option to move it, it might not look to professional ( just my personnal opinion ) :-\ Quote
Leaders dynamic_sysop Posted December 19, 2004 Leaders Posted December 19, 2004 I forgot to mention , try pressing ' Alt & Space ' , then you can select the ' Move ' menuitem using the Arrow keys on your keyboard and still move the Form using the WndProc Method you are using ;) another good reason to remove the MenuItem i guess :) hope it helps :cool: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.