wolwil
February 15th, 2009, 02:09 PM
Could anyone point me in the right direction on an easy way to pick a color off the screen and return an RGB value for it. I made a color pallet using and now I want to know how I can mouse over the color and have it give me a value like (255,0,0) for red and so on.
Thanks.
I am using Visual C++ 2008 Express. I found this code here on the forums but I cant get it to work.
CDC *dc = GetDC();
COLORREF rgb = dc->GetPixel();
this->lblRGBNumber->Text = rgb;
Here are the errors I am getting in reference to the winuser.h:
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(46) : error C2146: syntax error : missing ';' before identifier 'HDWP'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(47) : error C2146: syntax error : missing ';' before identifier 'MENUTEMPLATEA'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(54) : error C2146: syntax error : missing ';' before identifier 'LPMENUTEMPLATEA'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : error C2065: 'CALLBACK' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : error C2065: 'WNDPROC' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : fatal error C1903: unable to recover from previous error(s); stopping compilation
UPDATE:
Now I tried this:
#include <windows.h>
#include <winuser.h>
#include <fstream>
POINT pos;
GetCursorPos (&pos);
HDC hScreenDC = ::GetDC (NULL);
COLORREF rgb = ::GetPixel (hScreenDC, pos.x, pos.y);
::ReleaseDC (NULL, hScreenDC);
UINT red = GetRValue (rgb);
UINT green = GetGValue (rgb);
UINT blue = GetBValue (rgb);
char RedBuf[16];
sprintf(RedBuf, "%u", red);
String^ Red1 = Convert::ToString(RedBuf);
this->lblRGBNumber->Text = Red1;
Now I get this Error:
1>Linking...
1>Project.obj : error LNK2028: unresolved token (0A000018) "extern "C" int __stdcall ReleaseDC(struct HWND__ *,struct HDC__ *)" (?ReleaseDC@@$$J18YGHPAUHWND__@@PAUHDC__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2028: unresolved token (0A000019) "extern "C" unsigned long __stdcall GetPixel(struct HDC__ *,int,int)" (?GetPixel@@$$J212YGKPAUHDC__@@HH@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2028: unresolved token (0A00001A) "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2028: unresolved token (0A00001B) "extern "C" int __stdcall GetCursorPos(struct tagPOINT *)" (?GetCursorPos@@$$J14YGHPAUtagPOINT@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ReleaseDC(struct HWND__ *,struct HDC__ *)" (?ReleaseDC@@$$J18YGHPAUHWND__@@PAUHDC__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall GetPixel(struct HDC__ *,int,int)" (?GetPixel@@$$J212YGKPAUHDC__@@HH@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetCursorPos(struct tagPOINT *)" (?GetCursorPos@@$$J14YGHPAUtagPOINT@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>C:\Users\User\Documents\Visual Studio 2008\Projects\Project\Project\Debug\Project.exe : fatal error LNK1120: 8 unresolved externals
Thanks.
I am using Visual C++ 2008 Express. I found this code here on the forums but I cant get it to work.
CDC *dc = GetDC();
COLORREF rgb = dc->GetPixel();
this->lblRGBNumber->Text = rgb;
Here are the errors I am getting in reference to the winuser.h:
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(46) : error C2146: syntax error : missing ';' before identifier 'HDWP'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(47) : error C2146: syntax error : missing ';' before identifier 'MENUTEMPLATEA'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(54) : error C2146: syntax error : missing ';' before identifier 'LPMENUTEMPLATEA'
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : error C2065: 'CALLBACK' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : error C2065: 'WNDPROC' : undeclared identifier
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winuser.h(62) : fatal error C1903: unable to recover from previous error(s); stopping compilation
UPDATE:
Now I tried this:
#include <windows.h>
#include <winuser.h>
#include <fstream>
POINT pos;
GetCursorPos (&pos);
HDC hScreenDC = ::GetDC (NULL);
COLORREF rgb = ::GetPixel (hScreenDC, pos.x, pos.y);
::ReleaseDC (NULL, hScreenDC);
UINT red = GetRValue (rgb);
UINT green = GetGValue (rgb);
UINT blue = GetBValue (rgb);
char RedBuf[16];
sprintf(RedBuf, "%u", red);
String^ Red1 = Convert::ToString(RedBuf);
this->lblRGBNumber->Text = Red1;
Now I get this Error:
1>Linking...
1>Project.obj : error LNK2028: unresolved token (0A000018) "extern "C" int __stdcall ReleaseDC(struct HWND__ *,struct HDC__ *)" (?ReleaseDC@@$$J18YGHPAUHWND__@@PAUHDC__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2028: unresolved token (0A000019) "extern "C" unsigned long __stdcall GetPixel(struct HDC__ *,int,int)" (?GetPixel@@$$J212YGKPAUHDC__@@HH@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2028: unresolved token (0A00001A) "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2028: unresolved token (0A00001B) "extern "C" int __stdcall GetCursorPos(struct tagPOINT *)" (?GetCursorPos@@$$J14YGHPAUtagPOINT@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ReleaseDC(struct HWND__ *,struct HDC__ *)" (?ReleaseDC@@$$J18YGHPAUHWND__@@PAUHDC__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall GetPixel(struct HDC__ *,int,int)" (?GetPixel@@$$J212YGKPAUHDC__@@HH@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Project.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetCursorPos(struct tagPOINT *)" (?GetCursorPos@@$$J14YGHPAUtagPOINT@@@Z) referenced in function "private: void __clrcall Project::Form1::Click_Me(class System::Object ^,class System::EventArgs ^)" (?Click_Me@Form1@Project@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>C:\Users\User\Documents\Visual Studio 2008\Projects\Project\Project\Debug\Project.exe : fatal error LNK1120: 8 unresolved externals