Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 图书馆;X11/Xlib.h“的&引用;X11/Xutil.h“&引用;unistd.h“的;窗户_C_Windows_Visual Studio_Xlib_Unistd.h - Fatal编程技术网

C 图书馆;X11/Xlib.h“的&引用;X11/Xutil.h“&引用;unistd.h“的;窗户

C 图书馆;X11/Xlib.h“的&引用;X11/Xutil.h“&引用;unistd.h“的;窗户,c,windows,visual-studio,xlib,unistd.h,C,Windows,Visual Studio,Xlib,Unistd.h,我已经完成了一个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> #includ

我已经完成了一个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);
}
#包括
#包括
#包括
#包括
#包括
#包括
void getimage(XColor c,Display*d,int*rgb,int x,int y){
XImage*图像;
image=XGetImage(d,根窗口(d,默认屏幕(d)),
x、 y,1,1,所有平面,XYPixmap);
c、 像素=XGetPixel(图像,0,0);
XFree(图像);
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。此处描述了以下功能:(下面的链接)

#包括
...
DWORD WINAPI GetSysColor(
_In_uint nIndex
);
要使用该函数,必须链接到User32.dll中实现的User32.lib

可以访问
GetSysColor(…)
等的描述。此函数是许多支持类似功能的函数之一,但是警告,使用方法将类似于一种完全不同的语言。Windows编程很少与Linux编程相似

Windows相关图形/图像编程的其他起点:


您已经编写了一个X11程序。X是除OSX以外的类UNIX系统上图形显示的一致标准(但OSX也免费提供)

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


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

这些是标题,而不是库。标题是文本源文件,告诉编译器什么是可用的;除非你有一个库本身的实现,否则它们是无用的。这些特定的头文件和库在很大程度上特定于类Unix系统。有针对Windows的Unix仿真层,例如Cygwin。或者,您可以使用Windows提供的标题和库编写具有等效功能的代码;结果将会非常不同。还有一些跨平台的库可以抽象这些差异;wxWidgets就是一个例子。这是一个编译器错误,而不是崩溃。如果你的编译器因为缺少标题而崩溃,你应该在调试器中运行它,并提交一份包含所有详细信息的错误报告。谢谢你的回答!最后,我安装了cygwin。标题现在可以工作了,但我发现了另一个问题:Display*d=XOpenDisplay((char*)NULL);由于函数的参数不正确,因此不工作。在Linux中,(char*)NULL是默认显示的环境变量,但在windows中不是。你知道在这里写什么吗?谢谢你的回答!最后,我安装了cygwin。标题现在可以工作了,但我发现了另一个问题:Display*d=XOpenDisplay((char*)NULL);由于函数的参数不正确,因此不工作。在Linux中,(char*)NULL是默认显示的环境变量,但在windows中不是。你知道在这里写什么吗?@Sergio,如果机器上没有运行X服务器——除非你安装了X服务器,否则你可以确定没有——没有可连接的显示器。尽管您已成功构建程序,但它无法在当前环境中运行。如果X服务器正在运行,那么显示名称字符串的形式类似于
“:0”
,但我重复一遍:您最好根据Windows API重写程序。是的,我会这样做。谢谢谢谢你的回答!最后,我安装了cygwin。标题现在可以工作了,但我发现了另一个问题:Display*d=XOpenDisplay((char*)NULL);由于函数的参数不正确,因此不工作。在Linux中,(char*)NULL是默认显示的环境变量,但在windows中不是。你知道在这里写什么吗?
#include <Windows.h>  
...
DWORD WINAPI GetSysColor(
  _In_ int nIndex
);