如何取消打开应用程序的系统菜单? [英] How I could cancel opening the system menu of an application?

查看:84
本文介绍了如何取消打开应用程序的系统菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种在用户单击时隐藏或取消打开系统菜单的方法(完全禁用菜单是我的最后选择,我希望将其隐藏)

I need a way to hide or cancel opening the system menu when the user makes click on it (completely disable the menu is my last resort, I preffer to hide it)

在MSDN中搜索有关此信息,我已经看到DestroyMenu API函数:

Searching info about this in MSDN I've seen the DestroyMenu API function: http://msdn.microsoft.com/en-us/library/windows/desktop/ms647631%28v=vs.85%29.aspx

<DllImport("user32.dll")>
Private Shared Function DestroyMenu(
    ByVal hMenu As IntPtr)
End Function

但是当我尝试使用它时,应用程序的系统菜单会松开样式",而不会销毁"(删除).

But when I try it the system menu of the application loose the "Style" and is not "destroyed" (deleted).

无论如何,我都会记住,我想做的是隐藏菜单或避免菜单打开而不是完全禁用它.

Anyways I will keep in mind that what I would like to do is hide the menu or avoid the menu openning instead of completely disable it.

推荐答案

您可以禁用左键单击图标,以及右键单击标题栏中的任意位置.

You can disable left clicking the icon, and right clicking anywhere in the title bar.

Dim WM_SYSCOMMAND As Integer = &H112
Dim WM_NCRBUTTONDOWN As Integer = &HA4
Dim WM_NCRBUTTONUP As Integer = &HA5

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

    'disables right clicking on title bar
    If m.Msg = WM_NCRBUTTONDOWN Then
        m.Result = IntPtr.Zero
        Return
    End If
    If m.Msg = WM_NCRBUTTONUP Then
        m.Result = IntPtr.Zero
        Return
    End If

    'disables left click on icon in title bar
    If m.Msg = WM_SYSCOMMAND Then
        If m.WParam = &HF093 Then
            m.Result = IntPtr.Zero
            Return
        End If
    End If

    MyBase.WndProc(m)
End Sub

这篇关于如何取消打开应用程序的系统菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆