Mega Code Archive

 
Categories / Delphi / Examples
 

Cursorcoloured

(*---------------------------------------------------------------------------------- Description : creates a new mouse cursor using an Icon handle. Returns the handle of the newly created cursor Parameters : -- hIco : HICON Handle of the icon to use for creating the cursor. It might come from a TImage or an icon resource. ie: Image1.Picture.Icon.Handle or LoadIcon(hInstance, PChar(sCursorName) -- idxCursor : integer The index the of the newly create cursor into the Screen.Cursors. Pass the index you want here. For more info check TCursor and TScreen.Cursors -- Control : TControl The function can set the newly created cursor as the cursor of a control immediately. Pass the control here or leave it nil Tested : Delphi 5, Win2K Uses : Windows, Forms, Controls Example call : 1. NewCursor(Image1.Picture.Icon.Handle, 1, Form1); 2. NewCursor(Image1.Picture.Icon.Handle, crDrag, nil); Error checking : ? Notes : if you load the icon from a resource using something like hIco := LoadIcon(hInstance, PChar(sCursorName); you should call DestroyIcon(hIco); when you don't need the cursor anymore. Author : Theo Bebekis - bebekis@otenet.gr -----------------------------------------------------------------------------------*) function NewCursor(hIco: HICON; idxCursor: integer; Control: TControl): HICON; var pIcoInfo : PIconInfo; begin GetMem(pIcoInfo, SizeOf(TIconInfo)); try GetIconInfo(hIco, pIcoInfo^); Result := CreateIconIndirect(pIcoInfo^); Screen.Cursors[idxCursor] := Result; if Control <> nil then Control.Cursor := idxCursor; finally FreeMem(pIcoInfo); end; end; ----------------------------------- Theo Bebekis Thessaloniki, Greece bebekis@otenet.gr ----------------------------------- _______________________________________________ Delphi mailing list -> Delphi@elists.org http://elists.org/mailman/listinfo/delphi ******************************************************************* > Anyone have any code to get at the image of the current cursor as a bitmap? > I'd like to be able to blit the current cursor to another image. A fairly straightforward inversion of the logic will let you do that: procedure TForm1.Button2Click(Sender: TObject); var Icon : TIcon; begin if OpenDialog2.Execute then begin Icon := TIcon.Create; // load a cursor file, pretend it's an icon Icon.Handle := LoadCursorFromFile(PChar(OpenDialog2.FileName)); Image1.Picture.Bitmap.Height := Icon.Height; Image1.Picture.Bitmap.Width := Icon.Width; Image1.Canvas.Draw(0, 0, Icon); Icon.Free end; end; procedure TForm1.Button3Click(Sender: TObject); begin if SaveDialog1.Execute then begin // save as bitmap Image1.Picture.SaveToFile(SaveDialog1.FileName); end; end; Do note: as with Icons, that when you save off the cursor to a bitmap, any transparency info it may have contained is lost.