Winapi Windows GetPixel typedef C++;
如何定义GetPixel的类型和/或使用GetPixel还缺少什么Winapi Windows GetPixel typedef C++;,winapi,Winapi,如何定义GetPixel的类型和/或使用GetPixel还缺少什么 #include <windows.h> class PollPixelArray { public: PollPixelArray(HDC hdcMonitor, LPRECT lprcMonitor); unsigned long createHex(int r, int g, int b); private: PollPixelArray(); }; PollPixelArray::P
#include <windows.h>
class PollPixelArray
{
public:
PollPixelArray(HDC hdcMonitor, LPRECT lprcMonitor);
unsigned long createHex(int r, int g, int b);
private:
PollPixelArray();
};
PollPixelArray::PollPixelArray(HDC hdcMonitor, LPRECT lprcMonitor)
{
GetPixel(hdcMonitor, 50, 100);
}
unsigned long createHex(int r, int g, int b){
return (((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff));
}
#包括
类像素阵列
{
公众:
PollPixelArray(HDC HDC监视器、LPRECT lprcMonitor);
无符号长createHex(int r,int g,int b);
私人:
像素阵列();
};
PollPixelArray::PollPixelArray(HDC hdcMonitor、LPRECT lprcMonitor)
{
GetPixel(hdcMonitor,50100);
}
无符号长createHex(int r,int g,int b){
return(((r&0xff)这与typedefs毫无关系,GetPixel
工作正常。对于您观察到的行为,有两种合理的解释:
设备上下文无效,或
您传递的坐标超出设备的边界
看看你的代码,两者都可能是这样
EnumDisplayMonitors
的hdc
参数的文档说明:
如果此参数为NULL,则传递给回调函数的hdcMonitor参数将为NULL,可见的关注区域是包含桌面上所有显示的虚拟屏幕
GetPixel
的文档说明:
如果像素位于当前剪裁区域之外,则返回值为CLR_无效(Wingdi.h中定义了0xFFFFFF)
抱歉,我不明白。返回类型是ColorRef。当我打印它时,它总是具有相同的值,无论位置像素是什么,一定缺少什么。我做了一些研究,建议“typedef WINAPI GetPixel(hdc hdc,int posX,int posY)”将修复。GetPixel似乎无法在ATM上工作。您没有存储,该代码应该做什么?GetPixel
工作正常。错误之处在于您编写的代码中。坐标在剪裁矩形之外,或者DC无效。但请务必知道GetPixel
可以工作。因此,您需要看看你自己调用它的代码。它确实返回了屏幕分辨率的正确值,因此看起来设备上下文是合法的:虽然我不知道0-40、0-40等的坐标是如何离开屏幕的?当你调试它时,你会看到我上面说的是正确的。事实上,这两个问题都可能发生。选项1是f第一个要克服的障碍。一旦你克服了这个障碍,就要认识到设备上下文可能没有0,0
作为其原点。如果我通过lprcRECT的结果动态设置坐标,如下所示:x=(lprcMonitor->right-lprcMonitor->left);y=(lprcMonitor->bottom-lprcMonitor->top);tempX=x/2;tempY=y/2;结果是相同的,应该始终显示在屏幕上,不是吗?是的,hdcMonitor为空。如何选择要连接的监视器?文档中对此进行了解释。我想我已经回答了您提出的问题。
while (tempX<40){
COLORREF tempREF = GetPixel(hdcMonitor, tempX, tempY); //COLORREF | unsigned long |
unsigned int dummy = GetRValue(tempREF);
std::cout << "RGB: " << ("%d", dummy);
dummy = GetGValue(tempREF);
std::cout << "," << ("%d", dummy);
dummy = GetBValue(tempREF);
std::cout << "," << ("%d", dummy);
std::cout << " at " << ("%d", tempX) << ", " << ("%d", tempY) << std::endl;
tempX++;
tempY++;
}
#include <windows.h>
#include "pollpixelarray.h"
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
PollPixelArray::PollPixelArray(hdcMonitor, lprcMonitor);
return true;
}
void main()
{
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, 0);
std::cin.get();
}