Getpixel

Hi,

I have loaded bitmap on the formview. I want the pixel color of bitmap where i left click the mouse button?

I wrote the following code in Lbuttondown() function but it is not working

COLORREF ref;
CDC *pDC = GetDC();
ref = GetPixel(point.x, point.y);

let me know what is the problem and Answer

bye
Arora
AroraAsked:
Who is Participating?
 
GlennDeanConnect With a Mentor Commented:
From the code you listed, your using the WIN32 API function
  GetPixel(HDC hdc,int xPos,int yPos).
You want to use the CDC function
   GetPixel(int x,int y).
So, instead write
   ref = pDC->GetPixel(point.x,point.y);
0
 
AroraAuthor Commented:
Edited text of question.
0
 
arnondCommented:
better post this question in the windows programming area. you'd get much more traffic. After doing this, delete this question.

Arnon David.
0
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
BudVVeezerCommented:
your problem isn't so much where you post it(I know a LOT of programmers come to this section, including myself), it's with the GetDC call.  Try this:

COLORREF c;
HDC dc = GetDC(hWnd);

c = GetPixel(x, y);

you can use point.x, point.y also if you choose, depends on how you handle the message.  If this doesn work, send me the whole program, I'll figure it out!  =)

~Aaron
0
 
BudVVeezerCommented:
OOPS!  I forgot one thing, GetPixel(dc, x, y);  LoL, tiny mistake.  ;-P

~Aaron
0
 
AroraAuthor Commented:

Hi,

Ever I used HDC of the window as follows
 HDC DC;
DC = GetDC(m_hWnd);
 GetPixel( DC,point.x, point,Y);
 still the GetPixel function is not succeeding.


bye
Arora
0
 
GlennDeanCommented:
Arora:
  Can you get the above code to even compile?  IF you're in your LBUTTONDOWN handler, then the compiler "thinks" the
line
   DC = GetDC(m_hWnd);
is trying to call the CDC class's GetDC function and won't compile.  BUT, if you write
   DC = ::GetDC(m_hWnd);
then it compiles fine because the compiler now knows you want the WIN32 API function GetDC.  
   The code I listed in my proposed answer works (on my computer), BUT if you want to use the WIN32 API functions then write:
   HDC DC;
   DC = ::GetDC(m_hWnd);
   COLORREF color = ::GetPixel(point.x,point.y);
   This works on my computer.
         Glenn
0
 
GlennDeanCommented:
OOPS!  Change the above line to
   COLORREF color = ::GetPixel(DC,point.x,point.y);
0
All Courses

From novice to tech pro — start learning today.