适用于 Linux 的类似 Windows 的消息框 - 这个 C++/Motif 实现可以工作吗?
我想要一个类似于 Windows 的 Linux 消息框:它应该弹出,显示一些文本,当用户单击“确定”按钮时,它应该消失并将控制权返回给调用函数。
即使根本没有应用程序窗口,消息框也应该可以工作。因此,它创建一个应用程序上下文,通过 XmCreate*Dialog 将一个对话框绑定到它,当用户单击“对话框确定”按钮时,告诉应用程序上下文主循环退出。
这会像预期的那样工作吗? 这是否会自动销毁在此过程中创建的所有小部件和应用程序上下文(如果不是,那必须如何完成?)?
这是代码:
static XtAppContext appContext;
static Widget topWidget;
void XmCloseMsgBox (Widget w, XtPointer clientData, XmPushButtonCallbackStruct *cbs)
{
appContext.exit_flag = 1;
}
void XmMessageBox (const char* pszMsg, bool bError)
{
Widget msgBox;
XmString xmString = XmStringCreateLocalized (const_cast<char*>(pszMsg));
Arg args [1];
topWidget = XtVaAppInitialize (&appContext, "Application Name", NULL, 0,
&gameData.app.argC, gameData.app.argV, NULL, NULL);
// setup message box text
XtSetArg (args [0], XmNmessageString, xmString);
// create and label message box
xMsgBox = bError
? XmCreateErrorDialog (topWidget, "Error", args, 1)
: XmCreateWarningDialog (topWidget, "Warning", args, 1);
// remove text resource
XmStringFree (xmString);
// remove help and cancel buttons
XtUnmanageChild (XmMessageBoxGetChild (xMsgBox, XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild (XmMessageBoxGetChild (xMsgBox, XmDIALOG_HELP_BUTTON));
XtAddCallback (xMsgBox, XmNokCallback, XmCloseMsgBox, NULL);
XtRealizeWidget (topWidget);
// display message box
//XtManageChild (xMsgBox);
XtAppMainLoop (app);
}
I want a message box for Linux similar to the Windows one: It should pop up, display some text, and when the user clicks the Ok button, it should disappear and return control to the calling function.
The message box should work even if there is no application window yet at all. So it creates an application context, ties a dialog via XmCreate*Dialog to it, and when the user clicks the dialogs Ok button, tells the app contexts main loop to exit.
Would this work like intended?
Would this automatically destroy all widgets and the app context that got created in the process (if no, how would that have to be done?)?
Here's the code:
static XtAppContext appContext; static Widget topWidget; void XmCloseMsgBox (Widget w, XtPointer clientData, XmPushButtonCallbackStruct *cbs) { appContext.exit_flag = 1; } void XmMessageBox (const char* pszMsg, bool bError) { Widget msgBox; XmString xmString = XmStringCreateLocalized (const_cast<char*>(pszMsg)); Arg args [1]; topWidget = XtVaAppInitialize (&appContext, "Application Name", NULL, 0, &gameData.app.argC, gameData.app.argV, NULL, NULL); // setup message box text XtSetArg (args [0], XmNmessageString, xmString); // create and label message box xMsgBox = bError ? XmCreateErrorDialog (topWidget, "Error", args, 1) : XmCreateWarningDialog (topWidget, "Warning", args, 1); // remove text resource XmStringFree (xmString); // remove help and cancel buttons XtUnmanageChild (XmMessageBoxGetChild (xMsgBox, XmDIALOG_CANCEL_BUTTON)); XtUnmanageChild (XmMessageBoxGetChild (xMsgBox, XmDIALOG_HELP_BUTTON)); XtAddCallback (xMsgBox, XmNokCallback, XmCloseMsgBox, NULL); XtRealizeWidget (topWidget); // display message box //XtManageChild (xMsgBox); XtAppMainLoop (app); }如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为以下代码可能就是我所要求的:
I think the following code could be what I asked for: