请问C#里怎么用API函数SendMessage来显示标题栏的系统菜单???

shinaterry 2007-01-14 03:47:16
如题...

不明白请查看:http://community.csdn.net/Expert/topic/5293/5293542.xml?temp=.3471643
...全文
308 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shinaterry 2007-03-14
  • 打赏
  • 举报
回复
TO:zswang(伴水清清)(专家门诊清洁工)

太感谢您的乐意帮助!而且为人还这么好!
希望以后还能继续得到您的指点!

还有!谢谢大家的支持...
my_infinity 2007-03-14
  • 打赏
  • 举报
回复
首先你得标题栏的窗口句柄~~ 用FindWindow 和FindWindowEx 比较通用点
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
王集鹄 2007-03-14
  • 打赏
  • 举报
回复
//楼主分散了,别光给我一人...

using System.Runtime.InteropServices;

const uint TPM_LEFTBUTTON = 0;
const uint TPM_RIGHTBUTTON = 2;
const uint TPM_LEFTALIGN = 0;
const uint TPM_CENTERALIGN = 4;
const uint TPM_RIGHTALIGN = 8;
const uint TPM_TOPALIGN = 0;
const uint TPM_VCENTERALIGN = 0x10;
const uint TPM_BOTTOMALIGN = 0x20;
const uint TPM_RETURNCMD = 0x100;
const uint WM_SYSCOMMAND = 0x0112;

#region DllImport
[DllImport("User32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32.dll")]
static extern bool GetCursorPos(out Point lpPoint);
[DllImport("User32.dll")]
static extern int TrackPopupMenu(IntPtr hMenu, uint uFlags,
int x, int y, int nReserved, IntPtr hWnd, out Rectangle prcRect);
[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
#endregion

private void button1_Click(object sender, EventArgs e)
{
Point vPoint;
Rectangle vRect;
GetCursorPos(out vPoint);
SendMessage(Handle, WM_SYSCOMMAND, TrackPopupMenu(
GetSystemMenu(Handle, false),
TPM_RETURNCMD | TPM_LEFTBUTTON, vPoint.X, vPoint.Y,
0, Handle, out vRect), 0);
}
shinaterry 2007-01-18
  • 打赏
  • 举报
回复
还有。。。
这个函数是这样用:
static extern int SendMessage(IntPtr hWnd,int msg,int wParam,ref int lParam);
还是这样子呢?
static extern int SendMessage(IntPtr hWnd,int msg,int wParam,int lParam);
shinaterry 2007-01-17
  • 打赏
  • 举报
回复
我也知道是用这两个函数。。。

但是我查不到他触发时的值是多少。。。

我调试过很久啦。。。

大家帮帮忙吧。。。
superxiaomm 2007-01-14
  • 打赏
  • 举报
回复
也就是上面2个函数了
greennetboy 2007-01-14
  • 打赏
  • 举报
回复
[DllImport("User32.dll")]
static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd,int msg,int wParam,ref int lParam);
用this.Handle得到当前窗口的Handle,然后传递给SendMessage IntPtr 参数,消息编号根据你需要使用的功能自己查阅

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧