PC Review


Reply
Thread Tools Rate Thread

Controlbox menu in custom form

 
 
Glenn Nilsson
Guest
Posts: n/a
 
      11th Dec 2003
I have a custom drawn form with FormWindowBorder.None, and I would like
to be able to show the standard menu when the user clicks the control
box in the upper left corner of the form. Is this possible without
creating the menu by myself? The Move item feels a bit complicated

I haven't found a way to get hold of the menu in .NET but I found
GetSystemMenu in User32.dll, but I don't know what to do with the result
of that function.

Thank you all for existing

--
http://wailqill.com/
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      11th Dec 2003
* Glenn Nilsson <(E-Mail Removed)> scripsit:
> I have a custom drawn form with FormWindowBorder.None, and I would
> like to be able to show the standard menu when the user clicks the
> control box in the upper left corner of the form. Is this possible
> without creating the menu by myself? The Move item feels a bit
> complicated


You will have to use p/invoke, a VB6 sample can be found here:

<http://groups.google.com/groups?selm=01bca546%24a4635bc0%240202a8c0%40bapi>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Glenn Nilsson
Guest
Posts: n/a
 
      11th Dec 2003
Thanks for that!

But, I'm sorry to say, I don't get it to work :/

Problem 1: hMenu only gets a non-zero value if I have a controlbox
visible, and that I don't want, since I have a custom drawn form.
Problem 2: lRet never gets any other value than 0.

Can you or anyone else understand why this is?

code follows:


Win32.POINT p = new Win32.POINT(e.X, e.Y);
IntPtr hMenu = new IntPtr(Win32.GetSystemMenu(this.Handle, 0));
int lRet = Win32.TrackPopupMenu(hMenu, Win32.TPM_LEFTALIGN |
Win32.TPM_LEFTBUTTON | Win32.TPM_NONOTIFY | Win32.TPM_RETURNCMD, p.X,
p.Y, 0, this.Handle, 0);
if (lRet > 0)
{
Win32.SendMessage(this.Handle, Win32.WM_SYSCOMMAND, lRet, IntPtr.Zero);
}
-------

public class Win32
{
[DllImport("user32")] public static extern int SendMessage(HWND hwnd,
int wMsg, int wParam, IntPtr lParam);
[DllImport("user32")] public static extern int TrackPopupMenu(HANDLE
hMenu, int wFlags, int x, int y, int nReserved, HWND hwnd, int lprc);
[DllImport("user32")] public static extern int GetSystemMenu(HWND hwnd,
int bRevert);

public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public struct POINT
{
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
public int X;
public int Y;
}

public const int TPM_CENTERALIGN = 0x4;
public const int TPM_LEFTALIGN = 0x0;
public const int TPM_LEFTBUTTON = 0x0;
public const int TPM_RIGHTALIGN = 0x8;
public const int TPM_RIGHTBUTTON = 0x2;
public const int TPM_NONOTIFY = 0x80;
public const int TPM_RETURNCMD = 0x100;
public const int WM_SYSCOMMAND = 0x112;
}

at 2003-12-11 17:07, Herfried K. Wagner [MVP] mumbled something like:

> * Glenn Nilsson <(E-Mail Removed)> scripsit:
>> I have a custom drawn form with FormWindowBorder.None, and I would
>> like to be able to show the standard menu when the user clicks the
>> control box in the upper left corner of the form. Is this possible
>> without creating the menu by myself? The Move item feels a bit
>> complicated

>
> You will have to use p/invoke, a VB6 sample can be found here:
>
> <http://groups.google.com/groups?selm=01bca546%24a4635bc0%240202a8c0%40bapi>
>


--
http://wailqill.com/
 
Reply With Quote
 
Ying-Shen Yu[MSFT]
Guest
Posts: n/a
 
      12th Dec 2003
Hi Glenn,

You may also try this way,
implement your own context menu , then post WM_SYSCOMMAND messages to your
main form like this:

<code>
private void button1_Click(object sender, System.EventArgs e)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MAXIMIZE = 0xF030;
const int SC_MINIMIZE = 0xF020;
const int SC_MOVE = 0xF010;
const int SC_CLOSE = 0xF060;//from winuser.h
PostMessage(this.Handle,WM_SYSCOMMAND,SC_MINIMIZE,0);
}

[
DllImport("user32.dll")
]
private static extern IntPtr PostMessage(IntPtr hWnd,
int Msg,int wParam,int lParam);
</code>

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Items to the ControlBox Menu? Joe Cool Microsoft VB .NET 2 26th Mar 2007 03:42 AM
Controlbox MDI form Sylo Microsoft VB .NET 13 24th Jun 2004 11:53 AM
Controlbox MDI form Sylo Microsoft Dot NET Framework Forms 13 24th Jun 2004 11:53 AM
How to modify the ControlBox(system menu) of a Form? Yuan Ze Microsoft Dot NET Framework Forms 2 5th Jun 2004 05:01 PM
Form.ControlBox and Alt/F4 Ron James Microsoft C# .NET 0 16th Aug 2003 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:26 PM.