|
-
Oct 31st, 2000, 07:29 PM
#1
This...
Code:
GetCursorPos(&Mouse);
Colors = GetPixel(GetWindowDC(ChildWindowFromPoint(WindowFromPoint(Mouse), Mouse)), Mouse.x, Mouse.y);
Red = GetRValue(Colors);
Green = GetGValue(Colors);
Blue = GetBValue(Colors);
SetDlgItemInt(hMainDialog, ID_EDIT_RED, Red, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_GREEN, Green, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_BLUE, Blue, FALSE);
Or
This...
Code:
GetCursorPos(&Mouse);
Window = WindowFromPoint(Mouse);
Window = ChildWindowFromPoint(Window, Mouse);
Hdc = GetWindowDC(Window);
Colors = GetPixel(Hdc, Mouse.x, Mouse.y);
//Extract RGB values
Red = GetRValue(Colors);
Green = GetGValue(Colors);
Blue = GetBValue(Colors);
//Set the edit boxes
SetDlgItemInt(hMainDialog, ID_EDIT_RED, Red, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_GREEN, Green, FALSE);
SetDlgItemInt(hMainDialog, ID_EDIT_BLUE, Blue, FALSE);
-
Oct 31st, 2000, 09:06 PM
#2
Frenzied Member
I'd guess the first one, because it doesn't involve the three assignments for the second, third and fourth function calls. Why do you ask?
Harry.
"From one thing, know ten thousand things."
-
Oct 31st, 2000, 10:40 PM
#3
Thats what i was thinking to0, but does anyone know for sure? I want to know cuz if it is, ill start coding that way.
-
Oct 31st, 2000, 10:44 PM
#4
Frenzied Member
We're talking about a difference of a few microseconds; those three assignments will boil down to maybe 10 or 20 CPU cycles. Compared to the function calls it makes a miniscule difference. I'd say stick to whatever makes your code clearer.
Besides, with compilers optimising code like they do, they might be identical once compiled anyway,
Harry.
"From one thing, know ten thousand things."
-
Oct 31st, 2000, 11:53 PM
#5
Well that code goes into the msg loop, so its called like every time. So even a few microseconds every time it loops will speed it up alot.
-
Nov 1st, 2000, 12:28 AM
#6
Frenzied Member
I'm quite sure it won't. A microsecond is a millionth of a second. It depends on your CPU anyway. It's maybe 20 CPU cycles. 3 ASM instructions. How many cycles do you think a function like ChildWindowFromPoint() takes? A lot compared to an assignment.
I doubt if it makes a difference of 1% quite frankly.
Harry.
"From one thing, know ten thousand things."
-
Nov 1st, 2000, 01:51 PM
#7
Monday Morning Lunatic
Time to be controversial...
They'll take exactly the same time, because the compiler will create temporary variables, since from an ASM point of view, you can only do it the second way.
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
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
|