|
-
Jul 6th, 2001, 12:50 AM
#1
Thread Starter
PowerPoster
get the point colour
When somebody clicks on a window or any place in the client area, how do get the color of the point where the mouse if clicked.
Actually, I want to make a color picker.
-
Jul 6th, 2001, 03:44 AM
#2
Frenzied Member
Something like this: (i haven't tested it)
PHP Code:
BUTE Red,Green,Blue;
POINT Mouse;
GetCursorPos(&Mouse);
COLORREF Colors;
Colors = GetPixel(GetWindowDC(ChildWindowFromPoint(WindowFromPoint(Mouse), Mouse)), Mouse.x, Mouse.y);
Red = GetRValue(Colors); //contains red value
Green = GetGValue(Colors); //contains green value
Blue = GetBValue(Colors); //contains blue value
-
Jul 6th, 2001, 09:44 AM
#3
Thread Starter
PowerPoster
But If I put that in a some event like "WM_MOSEMOVE" then I want to write the value that I get so that I know if that code is working. I have tried to show a messagebox with one the values in but it gives me the following error:
Code:
error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'unsigned char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
I used the following code to show a messagebox with the red and blue values in:
Code:
case WM_MOUSEMOVE:
GetCursorPos(&Mouse);
Colors = GetPixel(GetWindowDC(ChildWindowFromPoint(WindowFromPoint(Mouse), Mouse)), Mouse.x, Mouse.y);
Red = GetRValue(Colors); //contains red value
Green = GetGValue(Colors); //contains green value
Blue = GetBValue(Colors); //contains blue value
MessageBox(NULL,Red,"Hi",MB_OK);
return 0;
-
Jul 6th, 2001, 12:13 PM
#4
Frenzied Member
Use the itoa function to use the red var in a messagebox.
Also i think it is not a good idea to pop up a messagebox on the mousemove message.
-
Jul 7th, 2001, 12:45 AM
#5
Thread Starter
PowerPoster
I am using the messageboxes for just testing so that I know I am getting the right value.
Let me test and if it does not work then I will reply again...
-
Jul 7th, 2001, 01:27 AM
#6
Thread Starter
PowerPoster
no, it is not quit right
Here is the code that I use. But I always shows me the value "192" for every color(Red, Green, Blue)
Even if I change my windows' color, it stays the same:
Code:
case WM_LBUTTONDOWN:
Colors = GetPixel(GetWindowDC(ChildWindowFromPoint(WindowFromPoint(Mouse), Mouse)), Mouse.x, Mouse.y);
Red = GetRValue(Colors); //contains red value
Green = GetGValue(Colors); //contains green value
Blue = GetBValue(Colors); //contains blue value
hdc = GetDC(hwnd);
TextOut(hdc, 30,50,itoa(Red, buffer,10), 3);
TextOut(hdc, 80,50,itoa(Blue, buffer1,10), 3);
TextOut(hdc, 130,50,itoa(Green, buffer2,10), 3);
ReleaseDC(hwnd, hdc);
return 0;
I am drawing the text when the left button is clicked. So I also have problem with the PAINT event because whenever I resize my window, it just repaints the whole area and I loose my text.
How can I fix both of these?
-
Jul 26th, 2001, 01:42 PM
#7
Lively Member
DLL?
If you dont mind it, you can write a tiny ActiveX DLL in VB using its "point" function....... Just pass it the x and y.... and it will return pixel color
-
Jul 26th, 2001, 01:50 PM
#8
Monday Morning Lunatic
That kind of defeats the object of using C++ though
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 26th, 2001, 04:42 PM
#9
The GetPixel API is a lot faster than the Point function, and is more efficient when using C++.
Even if you did make a VB DLL, you'd have to include the runtime files.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|