Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Handcursorgrafik (https://www.delphipraxis.net/112319-handcursorgrafik.html)

Nachteule 27. Aug 2008 17:51

Re: Handcursorgrafik
 
Liste der Anhänge anzeigen (Anzahl: 1)
habe das hier gefunden:
// crHandPoint is slightly different from IDC_HAND

// Derived from postings to borland.public.cppbuilder.winapi and
// borland.public.delphi.winapi by CC Chong and MrBaseball34 on
// 18-19 Dec 2000

// Comments from CC Chong:
// "Yes IDC_HAND is the hidden resource of Windows. On Win98 and above (or since
// ActiveDesktop Update in IE4, if I'm not mistaken) Windows has the IDC_HAND
// cursor built in to the system."

// "But it is not the same as Delphi's crHandPoint. Delphi doesn't use Windows'
// IDC_HAND. crHandPoint is Delphi's own inclusion in it's Controls.res (found
// in your Delphi\lib)."
//
// "Delphi copies crHandPoint into your exe during linking.:
//
// Below, crHandpoint has a black "wrist band" that is not present with IDC_HAND.



Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

const
   // Declare the cursor constant that contains the resource identifier
   // of the system Hand cursor.

  IDC_HAND = MakeIntResource(32649);

  // Declare the cursor constant for our own use. Constant value must
  // not conflict with any existing Delphi cursor constant.

  NIDC_HAND = 32649;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  // oder on FormCreate
  Screen.Cursors[NIDC_HAND] := LoadCursor(0, IDC_HAND);
 
  Screen.Cursor := NIDC_HAND
end;

end.
so funzt es prima unter WinXP SP3

blackdrake 27. Aug 2008 18:53

Re: Handcursorgrafik
 
Hallo.

Vielen Dank für den Code! Ich hatte meine Recherchen bereits über Tage partiell verteilt, aber nie etwas passendes gefunden.

Hier der vereinfachte Code:

Delphi-Quellcode:
const
  crWindowsHand = 32649;
  IDC_HAND = MakeIntResource(crWindowsHand);

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.Cursors[crWindowsHand] := LoadCursor(0, IDC_HAND);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Panel1.Cursor := crWindowsHand;
end;
(Huch? TCursor kompatibel mit Integer Cardinal? :o )

Ich werde noch prüfen, wie das Verhalten bei Windows 95 sein wird (ich möchte keine Exceptions haben).

Eventuell müsste ich prüfen, ob das LoadCursor fehlschlägt (wie?) und dann auf crHandPoint zurückspringen. Wenn ich ein Ergebnis habe, werde ich es hier und in der CodeLib posten.

Gruß
blackdrake

blackdrake 27. Aug 2008 19:20

Re: Handcursorgrafik
 
So müsste es nun eigentlich funktionieren. Ich teste es morgen auf meinem 95-Testpc

Delphi-Quellcode:
const
  NIDC_HAND = 32649;
  IDC_HAND = MakeIntResource(NIDC_HAND);

var
  crWindowsHand: TCursor;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Screen.Cursors[NIDC_HAND] := LoadCursor(0, IDC_HAND);

  if Screen.Cursors[NIDC_HAND] = NULL then
  begin
    crWindowsHand := crHandPoint;
  end
  else
  begin
    crWindowsHand := NIDC_HAND;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Panel1.Cursor := crWindowsHand;
end;
Mich ärgert, dass ich crWindowsHand nun als Variable machen musste. Andernfalls hätte ich nicht auf crHandPoint zurückspringen können (da Konstanten unveränderbar sind). Oder gibt es eine elegantere Lösung?

Gruß
blackdrake

Nachteule 27. Aug 2008 19:30

Re: Handcursorgrafik
 
könnte man nicht einfach den crHandPoint überschreiben?

blackdrake 27. Aug 2008 19:36

Re: Handcursorgrafik
 
crHandPoint ist eine Konstante. Eigentlich sollte mein crWindowsHand, das crHandPoint substituieren soll, auch eine Konstante sein, ansonsten kann ja jeder das Teil verändern und damit ungültig machen. :|

blackdrake 28. Aug 2008 00:11

Re: Handcursorgrafik
 
Sowohl

Delphi-Quellcode:
if Screen.Cursors[NIDC_HAND] = NULL then
als auch

Delphi-Quellcode:
if Screen.Cursors[NIDC_HAND] = 0 then
sind unter Windows 95 (kein IDC_HAND) unwahr. (Erwartet: wahr)

Zumindestens kommt keine Exception o.ä., sondern der Zeiger bleibt normal.

Ich würde eben gerne eine Fallback-Methode haben, die bei Nicht-Verfügbarkeit von IDC_HAND auf crHandPoint umspringt (möglichst ohne crWindowsHand als Variable zu haben, sofern das überhaupt möglich ist)

Hat jemand eine Idee?

(Anmerkung: In der Onlinehilfe steht, dass LoadCursor im Fehlerfall NULL ausgeben sollte... Irgendwie stimmt das aber hier nicht ganz.

Gruß
blackdrake

// Edit: Ich habe eine Lösung gefunden (die sogar ganz banal ist). Und das mit dem crHandPoint überschreiben ging irgendwie tatsächlich, wenn auch die Konstante unverändert blieb :wink: Weiteres habe ich hier http://www.delphipraxis.net/internal...=932775#932775


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:33 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz