Board index » delphi » Cursors,cursors and cursors

Cursors,cursors and cursors

Hi People,

I am a student in Interactive Multimedia Communications any help will be
most useful for me.

I am having trouble with custom cursors.  My problem is this:
(I am a Delphi beginner, by the way) :-)
I have an image, with code attached to it.  I wish to be able to drag it
around the form at runtime.

So far I have been able to get the thing to move, but I cant move it
without it being jerky, so my idea was to hide the image when
image1.dragging, show a custom dragCursor while image1.dragging, then
show the image1 when image1 is not dragging (if NOT image1.dragging then
image1.visible:=true) as it were.  Theother problem I have with it is
that I haven't the faintest clue how to get Delphi to save the image
position on the form when closing the application.  When I do restart
the app, the image appears in its original design time position.

This is probably a bit much to ask, as I am sure you are all busy, but
if you do get the time, could you possibly provide me with tips that
would help me out?

Yours, appreciatively in anticipation,

Neil J. McLeish
Please reply via email to:
n9577...@wlv.ac.uk
(as I don't get to newsgroups very often)

 

Re:Cursors,cursors and cursors


In article , "Neil says...

[snip]

Quote
>I have an image, with code attached to it.  I wish to be able to drag it
>around the form at runtime.

>So far I have been able to get the thing to move, but I cant move it
>without it being jerky, so my idea was to hide the image when
>image1.dragging, show a custom dragCursor while image1.dragging, then
>show the image1 when image1 is not dragging (if NOT image1.dragging then
>image1.visible:=true) as it were.  Theother problem I have with it is
>that I haven't the faintest clue how to get Delphi to save the image
>position on the form when closing the application.  When I do restart
>the app, the image appears in its original design time position.

>This is probably a bit much to ask, as I am sure you are all busy, but
>if you do get the time, could you possibly provide me with tips that
>would help me out?

[snip]

I'd suggest you follow the GUI (at least Windows) standard of 'ghosting' the
position of a two-dimensional area, as it's being 'dragged.' That is, while
dragging, you see an unfilled rectangle moving with your cursor.

To do this, don't hide the image, draw a rectangle matching its dimensions on
the image's parent control (the form?). This will (I think) involve XOR drawing
and you probably need to turn off clipping for the parent control's children.
The rectangle appears on mouse down, disappears on mouse up, and the image's
position is updated on mouse up.

If inifiles are not to your taste, you can save the state of your entire form as
a form file:

TFormMovingImage.SaveState(const FileName: TFileName);
var
  FileStream: TFileStream;
begin
  FileStream := TFileStream.Create(FileName, fmCreate);
  try
    FileStream.WriteComponent(Self);
  finally
    FileStream.Free;
  end;
end;

TFormMovingImage.RestoreState(const FileName: TFileName);
var
  Stream: TFileStream;
  I: Integer;
begin
  if FileExists(FileName) then
  begin
    FileStream := TFileStream.Create(FileName, fmOpenRead);
    try
      for I := (ComponentCount - 1) downto 0 do
        Components[i].Free;
      FileStream.ReadComponent(Self);
    finally
      FileStream.Free;
    end;
  end;
end;

Cheers,
Graham Meintjes
[To send email, remove .nospam from the email address.]

Re:Cursors,cursors and cursors


Neil,
  The easiest way I can think of to do this would be to save the images
co-ords in a *.ini file and then read them back when you start up the app.
Take a look at TIniFile in the online help.  For something like this you
would probably want to store the inifile in the apps directory as opposed
to the windows directory.

Email me if you need some more help.

Hope this helps!
--

Rodney E Geraghty
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Neil J. McLeish <n9577...@wlv.ac.uk> wrote in article
<34327775.3...@wlv.ac.uk>...

Quote
> Hi People,

> I am a student in Interactive Multimedia Communications any help will be
> most useful for me.

> I am having trouble with custom cursors.  My problem is this:
> (I am a Delphi beginner, by the way) :-)
> I have an image, with code attached to it.  I wish to be able to drag it
> around the form at runtime.

> So far I have been able to get the thing to move, but I cant move it
> without it being jerky, so my idea was to hide the image when
> image1.dragging, show a custom dragCursor while image1.dragging, then
> show the image1 when image1 is not dragging (if NOT image1.dragging then
> image1.visible:=true) as it were.  Theother problem I have with it is
> that I haven't the faintest clue how to get Delphi to save the image
> position on the form when closing the application.  When I do restart
> the app, the image appears in its original design time position.

> This is probably a bit much to ask, as I am sure you are all busy, but
> if you do get the time, could you possibly provide me with tips that
> would help me out?

> Yours, appreciatively in anticipation,

> Neil J. McLeish
> Please reply via email to:
> n9577...@wlv.ac.uk
> (as I don't get to newsgroups very often)

Re:Cursors,cursors and cursors


Neil J. McLeish <n9577...@wlv.ac.uk> wrote in article
<34327775.3...@wlv.ac.uk>...

Quote
> Hi People,

> I am a student in Interactive Multimedia Communications any help will be
> most useful for me.

> I am having trouble with custom cursors.  My problem is this:
> (I am a Delphi beginner, by the way) :-)
> I have an image, with code attached to it.  I wish to be able to drag it
> around the form at runtime.

> So far I have been able to get the thing to move, but I cant move it
> without it being jerky, so my idea was to hide the image when
> image1.dragging, show a custom dragCursor while image1.dragging, then
> show the image1 when image1 is not dragging (if NOT image1.dragging then
> image1.visible:=true) as it were.  Theother problem I have with it is
> that I haven't the faintest clue how to get Delphi to save the image
> position on the form when closing the application.  When I do restart
> the app, the image appears in its original design time position.

> This is probably a bit much to ask, as I am sure you are all busy, but
> if you do get the time, could you possibly provide me with tips that
> would help me out?

> Yours, appreciatively in anticipation,

> Neil J. McLeish
> Please reply via email to:
> n9577...@wlv.ac.uk
> (as I don't get to newsgroups very often)

Hope this response is timely and helpful.

        I have not found a definitive method to move screen items at run time.
Although, I originally believed that dynamically altering the cursor was
the answer, it does not seem that this is the method used by other
applications including Delphi. When components are moved in Delphi, Delphi
appears to divide components into two categories, windowed and
non-windowed.  Windowed controls(which have window handles) are left
unaltered.  Non-window controls are placed and/or surrounded by 8 window
containers which are registered as Tgrabhandle. These 8 containers are used
to size move the non-windowed component.  Although I think Delphi should
have made this class available to its developers, it didnt (or at least I
cant access them.

        A solution (I forget where I came across it, but it is not intuitive or
clearly documented), is to place your Timage in a windowed container: An
example is as follows:

        1) create a new application.

        2) drop a panel on the form, change the caption property to a blank, and
set the BevelInner to bvLowered.

        3) drop an image component on the panel, set its align property to
alClient.

        4) assign the following OnMousedown method to the image compenent.

procedure TForm1.Image1MouseDown (Sender: Tobject;  Button:   TMouseButton;
 Shift: TShiftState; X, Y: Integer);

    const
      SC_DragMove = $F012;

    begin

      ReleaseCapture;
      panel1.perform(WM_SysCommand, SC_dragmove, 0);

    end;

        This should work to move your image.  To save the coordinates of image it
would probably be preferable to use ini or the windows registry. The
coordinates can be saved either at the end of the mouse down event
described above or a method could be assigned to the onclose event of the
form. The coordinates could be retrieved from the ini file or the registry
in the forms onactiviate event, and then assigned to the panel. The
Tinifile and Tregistry objects are fairly well documented in the Delphi
online help.  If you need more information.  Drop me an EMail.

__________________________________________
My Adverti{*word*224}t:

        Need support to provide user support for the Microsoft IntelliMouse?
pointing device (a mouse with a Wheel).  Send me an e-mail,
(va...@neosoft.com) and Ill send an free Delphi add on and sample program
demonstrating TMouseWheel, a component that provides complete support for
the IntelliMouse.  

Other Threads