Getting the color that the mouse is over - by joewnn

Discussion in 'Archives' started by Six, May 12, 2007.

Getting the color that the mouse is over - by joewnn
  1. Unread #1 - May 12, 2007 at 11:25 AM
  2. Six
    Joined:
    Jan 21, 2007
    Posts:
    1,482
    Referrals:
    4
    Sythe Gold:
    12

    Six Guru

    Getting the color that the mouse is over - by joewnn

    K this is just an easy tutorial of how to show the color that the mouse is over in a label.
    First make a new project then add a label. Delete the caption and turn autosize off. Make it fairly big.

    Now go to the system tab and add a timer, set the interval to about 50.

    Now in implementation (in your code, where all of the procedures are) add this function-

    Code:
    function GetColor(x, y: Integer; Handle: Cardinal): TColor;
    var DC: HDC;
    begin
      DC := GetWindowDC(Handle);
      result := TColor(GetPixel(DC, x, y));
      ReleaseDC(Handle, DC);
    end;
    The first line gets the dc of the specified handle.
    The second gets the color using the dc and the specified coords. Then the last line gets rid of the dc. Wink

    Now double click your timer and add the var "pnt:tPoint;".

    Now in the code, add this-

    Code:
    pnt := mouse.cursorpos;
    label1.Color := GetColor(pnt.x, pnt.y, GetDeskTopWindow);
    Thanks cruel for mentioning "mouse.cursorpos", otherwise I would have used getcursorpos. Wink
    The first line gets the position of the mouse. It assigns the coordinates to "pnt". Then the second line changes the color of the label to the color the mouse is over. The x value is pnt.x and the y value is pnt.y. GetDeskTopWindow just uses the desktop as the handle. (You can also put 0 instead of that, it works the same)

    That is it. If you had any problems then you are a complete noob.
     
< selling a def pure | Awsome lvl 51 mauler pure 1 month P2P!! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site