gpt4 book ai didi

c++ - Motif:拦截关闭框事件并阻止应用程序退出? (C++)

转载 作者:行者123 更新时间:2023-11-30 04:40:25 24 4
gpt4 key购买 nike

当用户单击主题窗口(小部件)的关闭框时,如何拦截,以及如何防止 Motif 窗口管理器在单击关闭框时关闭整个调用应用程序(以便我的应用程序可以关闭Motif 应用程序上下文和窗口并继续运行)?我试图通过 Google、tuts 和 docs 来了解自己,但没有成功。需要 C++。

最佳答案

这似乎有效(在 inet 上找到):

#include <Xm/Protocols.h>

Boolean SetCloseCallBack (Widget shell, void (*callback) (Widget, XtPointer, XtPointer))
{
extern Atom XmInternAtom (Display *, char *, Boolean);

if (!shell)
return False;
Display* disp = XtDisplay (shell);
if (!disp)
return False;
// Retrieve Window Manager Protocol Property
Atom prop = XmInternAtom (disp, const_cast<char*>("WM_PROTOCOLS"), False);
if (!prop)
return False;
// Retrieve Window Manager Delete Window Property
Atom prot = XmInternAtom (disp, const_cast<char*>("WM_DELETE_WINDOW"), True);
if (!prot)
return False;
// Ensure that Shell has the Delete Window Property
// NB: Necessary since some Window managers are not
// Fully XWM Compilant (olwm for instance is not)
XmAddProtocols (shell, prop, &prot, 1);
// Now add our callback into the Protocol Callback List
XmAddProtocolCallback (shell, prop, prot, callback, NULL);
return True;
}

设置这样的回调将防止应用程序因关闭事件被默认事件处理程序处理而关闭。

关于c++ - Motif:拦截关闭框事件并阻止应用程序退出? (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1389414/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com