Qt如何设置隐藏QDialog的关闭按钮和标题栏
展开全部
关闭按钮无法删除,但是可以禁用,方法如下:
首先在你的窗体类中引入一些Windows API需要的定义
const uint SC_CLOSE = 0xf060;
const uint MF_GRAYED = 0x01;
const uint MF_BYCOMMAND = 0x0;
[DllImport("user32.dll")]
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem,
uint uEnable);
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
然后可以在窗体的Load事件中加入下列初始化代码
IntPtr hSysMenu;
hSysMenu = GetSystemMenu(this.Handle, false);
EnableMenuItem(hSysMenu, SC_CLOSE, MF_GRAYED);
RemoveMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
首先在你的窗体类中引入一些Windows API需要的定义
const uint SC_CLOSE = 0xf060;
const uint MF_GRAYED = 0x01;
const uint MF_BYCOMMAND = 0x0;
[DllImport("user32.dll")]
static extern bool EnableMenuItem(IntPtr hMenu, uint uIDEnableItem,
uint uEnable);
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("user32.dll")]
static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);
然后可以在窗体的Load事件中加入下列初始化代码
IntPtr hSysMenu;
hSysMenu = GetSystemMenu(this.Handle, false);
EnableMenuItem(hSysMenu, SC_CLOSE, MF_GRAYED);
RemoveMenu(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询