Display XOpenDisplay(0) 和 XOpenDisplay(NULL) 有什么区别?
#include <X11/Xlib.h>
struct MwmHints
{
unsigned long flags;
unsigned long functions;
unsigned long decorations;
long input_mode;
unsigned long status;
};
enum
{
MWM_HINTS_FUNCTIONS = (1L << 0),
MWM_HINTS_DECORATIONS = (1L << 1),
MWM_FUNC_ALL = (1L << 0),
MWM_FUNC_RESIZE = (1L << 1),
MWM_FUNC_MOVE = (1L << 2),
MWM_FUNC_MINIMIZE = (1L << 3),
MWM_FUNC_MAXIMIZE = (1L << 4),
MWM_FUNC_CLOSE = (1L << 5)
};
extern "C"
{
void borderless(Window window)
{
Display *display = XOpenDisplay(0);
Atom mwmHintsProperty = XInternAtom(display,"_MOTIF_WM_HINTS",0);
struct MwmHints hints;
hints.flags = MWM_HINTS_DECORATIONS;
hints.decorations = 0;
XChangeProperty(display,window,mwmHintsProperty,mwmHintsProperty,32,
PropModeReplace,(unsigned char *)&hints,5);
XCloseDisplay(display);
}
}
在上面的代码中,我为 Linux 编写了一个 *.SO 库,在调用时删除指定窗口的窗口装饰。在该代码行中显示:
Display *display = XOpenDisplay(0);
我试过将其替换为:
Display *display = XOpenDisplay(NULL);
这两种用法似乎都成功地移除了我正在测试的 Ubuntu 16.04 LTS 笔记本电脑上的窗口装饰。
我在某处(我不记得在哪里)读到过,根据您使用 XOpenDisplay 的方式,如果有多个显示器连接到您的计算机,它会有不同的 react 。我没有多个显示器可以测试,所以我需要知道使用 0 与使用 NULL 是否有任何不同,这引出了我的下一个问题,我将把它作为一个单独的问题发布。
谢谢。
最佳答案
没有任何区别
NULL
is defined as 0 (possibly casted to void *
in C, but not in C++) .这两个调用实际上是相同的。
关于c++ - XOpenDisplay(0) 和 XOpenDisplay(NULL) 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45002305/