Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cursors

Posted on 1998-03-31
8
Medium Priority
?
370 Views
Last Modified: 2010-04-06
Does anyone how I can make a cursor at run time with the arrow in the top left hand corner and about five characters at the bottom (similar or exactly like MS Exlorer when doing a drag and drop)???

This is what I mean....

I have two listboxes.  One list is filled, the other is empty.  When I drag an item from one to the other, I want to create a new cursor with the arrow in the top lh corner (just like the crDrag cursor) and with the first few letters from the target item included under the cursor.

   |\
    \
    Filename

I dunno if this is possible or not.  MS have done it for years - maybe they are smarter than they look :)
0
Comment
Question by:Stuart_Johnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:mvz121697
ID: 1361141
screen.cursor:=crAppStart ?

0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1361142
Edited text of question
0
 

Expert Comment

by:BigMadDrongo
ID: 1361143
Try creating a lable, setting the text to the letters you want to display, and then move the label whenever the OnMouseMove event is fired.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1361144
Umm... Its a bit messy.  I actually want to create a new cursor.

Can anyone tell me if a cursor has a canvas at all?  I cant find anything about them so it makes it difficult.

Maybe I could create a resource at runtime and use LoadResource and assign it to the cursor??
0
 
LVL 5

Expert Comment

by:inter
ID: 1361145
Hi,

I have found a solution but can not code it bynow, may be in few hour I have time to do that.

By the way, The cursors has no canvas. But we may retreive their bits. The problem with the cursors is that they can not be encapsulated as having bits etc. Windows handle them. So if you look in Delphi the cursors are just integer identifiers for example crArrow is -1 or so.

So the algorithm has two parts:

1 - Let Delphi know about the Cursor.
2 - Manipulate the cursor and assign whenever and item is dragged from that list boxes.

So it should be possible. But do not think tha Microsoft guys does this. They are using icon drawing functions to show that drag and drop operations. Note that the hardware cursor can not have colors and it has a specified width and height so we talk CURSORS here and do it in this way. If we want to do it in other way we should specially deal with Delphi's Internal Drag-drop method which is a torture.

Regards,
Igor
0
 
LVL 5

Accepted Solution

by:
inter earned 400 total points
ID: 1361146
Here is how its done with cursors. Do the following:

1 - Create new project or create a new main form
2 - Add a button to it
3 - Paste following code as unit1
4 - Bind Button1.Onclick to button1click

unit Unit1;
interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

const
  crMyCursor = 5;
var
  CursorWidth, CursorHeight : Integer;

// This one modifies the cursor
procedure ModifyCursor(Index:integer;Text:string);
var
  ic : TIconInfo;
  ms : TBitmap;
  MemSt : TMemoryStream; //this is used for getting bitmap data
  Buf : array[0..10] of char;
  HPtr, TPtr : PChar; // these are just variables two swap bitmap rows
begin
  // Get Standart Arrow
  GetIconInfo( Screen.Cursors[crArrow], ic);
  // For easy manipulation assign it to a internal bitmap
  ms := TBitmap.Create;
  ms.handle := ic.hbmMask;
  // Modify them
  ms.Canvas.Font.Name := 'Small fonts';
  ms.Canvas.Font.Size := 6;
  ms.Canvas.TextOut(0,ms.Height div 2-10, Text);
  // Create new cursor and assign it to Cursors so that delphi knows it
  MemSt := TMemoryStream.Create;
  ms.SaveToStream(MemSt);
  // Align memory image because the first scanline in bitmap is in the last row
  HPtr := PChar(LongInt(MemSt.Memory) + PBitmapFileHeader(MemSt.Memory).bfOffBits);
  TPtr := PChar(LongInt(MemSt.Memory)+ MemSt.Size - CursorWidth);
  while HPtr < TPtr do
  begin
    System.Move(HPtr^, Buf, CursorWidth);
    System.Move(TPtr^, HPtr^, CursorWidth);
    System.Move(Buf, TPtr^, CursorWidth);
    Inc(HPtr, CursorWidth);
    Dec(TPtr, CursorWidth);
  end;
  try
  //delete old cursor
  Screen.Cursors[Index] := crNone;
  //Create new one with bitmap info
  Screen.Cursors[Index] := CreateCursor( HInstance,
    0,0,
    GetSystemMetrics( SM_CXCURSOR),
    GetSystemMetrics( SM_CYCURSOR),
    Pointer(LongInt(MemSt.Memory) + PBitmapFileHeader(MemSt.Memory).bfOffBits),
    Pointer(longint(MemSt.Memory) + PBitmapFileHeader(MemSt.Memory).bfOffBits+CursorWidth*CursorHeight));
  finally
    ms.Free;
    MemSt.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CursorWidth  := GetSystemMetrics( SM_CXCURSOR) div 8;
  CursorHeight := GetSystemMetrics( SM_CYCURSOR);
  Cursor := crMyCursor;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ModifyCursor(crMyCursor, InputBox('Text To Write','',''));
end;

end.

The key procedure here is procedure ModifyCursor(Index:integer;Text:string);
For using it while draging In your formcreate do this

  ListBox1.DragCursor := crMyCursor;

So when drag begins(OnBeginDrag of the component you want) do the following:

  ModifyCursor(crMyCursor, 'Filename');

As I said this is a solution with just Cursors if you want to drag an image more than 32x32 you should use Shells drag drop COM  interfaces with delphi components which is problematic as far as I know.

Regards,
Igor



0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1361147
Igor,

I have tried what you posted. However, I had major problems.  When it attempted to create the cursor and assign it to Screen.Cursor[Index], I got the dreaded blue screen and my machine totally locked up.  Any suggestions???

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1361148
Never fear, I figured it out.  You can't assign crNone to the cursor array for some reason.  Dunno why.

Thanks for you help.

Stu
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question