Home > Back-end >  Delphi mouse pointer image replacement, there is deviation
Delphi mouse pointer image replacement, there is deviation

Time:09-18

Into the Panel in the mouse, move the mouse pointer to replace their own pictures,

The implementation code is as follows:

Screen. Your Cursors [101] :=LoadCursorFromFile (pChar (v_str + '1. Cur'));
Panel1. Cursor:=101;


Functionality is implemented, but after replacing the pointer to the image with the mouse arrow pictures, coordinates will be a deviation,

Change after the pointer to the picture than the original arrow images to upgrade, 10 pixels, very afflictive,

Ever run into the problem of the great god, deliver ideas...

I tried to modify the image pixels, way of design, can save...

CodePudding user response:

Var
Hcursor: Hicon;
The begin
Hcursor:=loadcursorfromFile (PChar (' C: \ WINDOWS \ your CURSORS \ pen_1 cur '));
SetSystemCursor (hcursor OCR_NORMAl);
end;

The CUR file system at first try, if there is deviation, it ask

Or try SetSystemCursor

I just eliminate the zero reply

CodePudding user response:

 
Var
CurPos: TPoint;
The ADC: HDC;
ARect: TRect;
The begin
The GetCursorPos (CurPos);
The ADC:=GetWindowDC (Self. Handle);
Try
ARect:=the Rect (CurPos. X - Self. Left, CurPos. Y - Self. Top, CurPos. X - Self. Left + 32, CurPos. Y - Self. Top + 32);
InValidateRect (Self. Handle, @ ARect, true);
DrawIconEx (ADC, ARect. Left, ARect. Top, FIcon, 32, 32, 0, 0, DI_NORMAL);
The finally
ReleaseDC (Self. Handle, ADC);
end;
end;


CodePudding user response:

Image source of the problem, change a try

CodePudding user response:

ArtCursors software can set the cursor's Hot Spot, which is relative to the mouse cursor (X, Y) point to the location of the position,

CodePudding user response:

This is a reason, because the mouse resource file, the upper left corner is not the origin, you draw the mouse directly, will naturally appear deviation,
In the mouse resources, there is a xHotspot and yHotspot,
LpIcon: TIconInfoGetIconInfo (lpCur hCursor lpIcon);
DrawIcon or DrawIconEx drawing to remove the deviation value,
  • Related