2009-09-07 24 views
1

当用户点击一个主题窗口(widget)的关闭框时,我该如何拦截,以及如何阻止Motif窗口管理器关闭被点击的关闭框上的整个调用应用程序(以便我的应用程序可以关闭Motif应用程序上下文和窗口并继续运行)?我试图用Google,tuts和docs来发现自己,但没有骰子。需要C++。Motif:拦截关闭盒事件并阻止应用程序退出? (C++)

回答

1

这似乎是工作(在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; 
} 

设置这样的回调将阻止应用程序被关闭的关闭事件是手柄是默认的事件处理程序的结果。

0

IIRC,在X11上,当你点击一个窗口的关闭框,窗口管理器将信号发送到您的应用程序,告诉它退出。无论您使用motif还是gtk或Qt都无关紧要,因为关闭框属于WM,而不是您的应用程序。

您需要捕获unix信号以防止应用程序关闭。

+0

我问*怎么做到这一点。我已经知道,我必须以某种方式拦截涉及的事件,并防止默认的退出处理程序被调用。 – karx11erx 2009-09-07 13:46:21

+0

我*已*告诉你如何去做。谷歌“unix信号”,你会得到答案。 – 2009-09-07 14:54:28

+0

你什么都没有。你的提示是毫无价值的。看到我自己给出的答复,这是一个很好的答复。 – karx11erx 2009-09-07 21:45:14

1

vendorShellWidgetClass不会为您做诡计吗?如在,关闭只是图案的应用程序上下文,而不是窗口..