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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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

~Aaron
0
GlennDeanCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Hardware

From novice to tech pro — start learning today.