"X11/Xlib.h"、"X11/Xutil.h"、"unistd.h" Windows 的图书馆

Libraries "X11/Xlib.h", "X11/Xutil.h", "unistd.h" for Windows

我已经编写了一个 C 程序,它获取屏幕像素的 RGB 值 (0-255),知道它的位置 (x,y)。它在 Linux 中工作,但是当我尝试在 Visual Studio (Windows) 中编译它时,崩溃,因为库 X11/Xlib.h,X11/Xutil.h,unistd.h不存在。

这是代码:

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>

void getimage(XColor c, Display* d, int* rgb, int x, int y) {
    XImage* image;
    image = XGetImage(d, RootWindow(d, DefaultScreen(d)),
        x, y, 1, 1, AllPlanes, XYPixmap);
    c.pixel = XGetPixel(image, 0, 0);
    XFree(image);
    XQueryColor(d, DefaultColormap(d, DefaultScreen(d)), &c);
    rgb[0] = c.red / 256;
    rgb[1] = c.green / 256;
    rgb[2] = c.blue / 256;
}

int main () {
    int rgb[3], x, y;
    XColor c;
    Display* d = XOpenDisplay((char*)NULL);
    getimage(c, d, rgb, x, y);
}

如何在 Windows 中将此应用到 运行?

您的问题的一小部分答案可能是搜索 MSDN。那里描述了以下功能:(下面的link)

#include <Windows.h>  
...
DWORD WINAPI GetSysColor(
  _In_ int nIndex
);

要使用该功能,您必须 link 到 User32.lib 已在 User32.dll

中实现

GetSysColor(...)等的描述。阿尔。可访问 here。此功能是支持类似功能的众多功能之一,但警告,使用方法将像完全不同的语言。 Windows 编程很少与 Linux 编程相似。

Windows 相关graphical/image 编程的其他起点:
capturing an image
Create your own Snipping tool

您已经编写了一个 X11 程序。 X 是类 UNIX 系统 上图形显示的共识标准 除了 OS X(但它也可免费用于 OS X).

Windows 使用完全不同的图形显示 API。可以想象,您可以找到在 Windows 上运行的 X 实现,但 Microsoft 肯定没有提供。由于您的程序很短,您最好的选择可能是 重写 它使用 Windows API.

至于 unistd.h(和 time.h),我在您的程序中没有看到任何依赖它的东西。如果您不打算重写程序,只需删除有问题的 #include 语句即可解决这部分问题。