Recent

Author Topic: [Solved] dos program  (Read 1979 times)

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #15 on: December 01, 2020, 05:01:45 am »
Hi, I'm the author of ptcgraph, ptccrt, ptcmouse and ptcpas. If you want keyboard input to work with ptcgraph, you should use ptccrt and only 'readkey' and 'keypressed', not read/readln. Keyboard input via read/readln is not supported while the graphics window is open. And if you want to get rid of the console window, add {$apptype gui} to your program.

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #16 on: December 01, 2020, 01:47:44 pm »
Thanks a lot nickysn,
I'll try yor suggestions as soon as possible.

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #17 on: December 01, 2020, 08:01:47 pm »
@nicksyn

now with readkey it is fine, there is still the error raiseed in initgraph : "the project raised the exception TPCTError : cannot recycle because it is not already open" do you know how to avoid this ?

thanks again.

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #18 on: December 02, 2020, 05:01:18 am »
Can you give me a small example program and the exact specs to reproduce the "cannot recycle because it is not already open" error? Which Windows version are you using? What is the graphics card?

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #19 on: December 02, 2020, 11:15:19 am »
Yes, I'll attach the sample test later.

Laz 2.0.10, fpc 3.2.0, win 10 pro, graphic card gtx-1030.

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #20 on: December 02, 2020, 08:54:43 pm »
the file

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #21 on: December 05, 2020, 12:10:25 pm »
Dear nicksyn,

I am using "GetMouseState(Posizione.PosX, Posizione.PosY, buttype);" to retrive the mouse position and button state.
What I see is that once a click is done ButType returns a value in the range 1..3, but how can I RESET the buttype ? succcessive calla to GetMouseState still give buttype = last click, also LPressed seems anchored to the last click event.

Can you give me an idea how this works ?

thanks

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #22 on: December 05, 2020, 05:20:27 pm »
These only give you the current state of the buttons. Note that "buttype" in your example is actually a bit mask, and it's not necessarily in the range 1..3, but can actually be in the range 0..7. Each binary bit indicates the state of an individual button:

     bit 1 set -> left button pressed
     bit 2 set -> right button pressed
     bit 3 set -> middle button pressed

To check whether the left button is currently pressed:

if (buttype and 1) <> 0 then
begin
  // left button is currently pressed
end;
if (buttype and 2) <> 0 then
begin
  // right button is currently pressed
end;
if (buttype and 4) <> 0 then
begin
  // middle button is currently pressed
end;

To get the moment that left mouse button is clicked only once, you need to keep the previous button state, and catch the moment, where the left mouse button is pressed now, but wasn't pressed the previous time. E.g.

lastbuttype := 0;
repeat  // loop start
  GetMouseState(Posizione.PosX, Posizione.PosY, buttype);
  if ((buttype and 1) <> 0) and ((lastbuttype and 1) = 0) then
  begin
    // on left mouse button click...
  end;
  if ((buttype and 2) <> 0) and ((lastbuttype and 2) = 0) then
  begin
    // on right mouse button click...
  end;
  if ((buttype and 4) <> 0) and ((lastbuttype and 4) = 0) then
  begin
    // on middle mouse button click...
  end;

  // do other stuff here

  lastbuttype := buttype;
until false; // loop end

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #23 on: December 05, 2020, 05:23:39 pm »
Note also that the following constants are defined in ptcmouse for convenience, when using the bit mask:

const
  LButton = 1; { left button   }
  RButton = 2; { right button  }
  MButton = 4; { middle button }

so instead of

if (buttype and 4) <> 0 then

you can use

if (buttype and MButton) <> 0 then

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #24 on: December 05, 2020, 06:05:33 pm »
perfect !

many thanks, something to re-code but now it works !

PS: still the error message at begin, did you find the cause ?

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #25 on: December 05, 2020, 07:19:41 pm »
Didn't have time today to check it, sorry, but I'll try to find some time tomorrow.

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #26 on: December 05, 2020, 07:51:28 pm »
many thanks again.

In my old version of the software I was also able to change the cursor shape, is it still possbile ?

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #27 on: December 07, 2020, 11:22:07 pm »
No, unfortunately, it's not possible to change the cursor, but you can hide the regular cursor, using HideCursor and draw your own cursor manually. After you're done, you can use ShowCursor to show the normal cursor again.

The exception you get on startup, when running the program with the Lazarus debugger is normal, and not propagated to your program. It's an exception that is raised internally and then caught and handled all inside the ptc library code. The Lazarus debugger by default catches all exceptions,as soon as they are raised, and not just *unhandled* exceptions. In this case, this is an annoyance, and should be disabled by unchecking 'Notify on Exceptions' inside Tools->Options->Debugger->Language Exceptions.

Also note that you don't need to handle any exceptions in your code, so the try..except block around InitGraph is not needed. This is really not an exception that is propagated to your code, it's just caught by the debugger, because of the 'Notify on Exceptions' option. As you can see, your program runs just fine, when run outside the debugger, and that is also the case, when you remove the try..except block as well.

Paolo

  • Full Member
  • ***
  • Posts: 110
Re: dos program
« Reply #28 on: December 08, 2020, 12:06:06 am »
Thanks a lot,
I am very happy to see my old code working again. That wasn't possibile without your help.
I see that the exception is only in the IDE.
Concerning the mouse you said that I need to draw it by myself, are you suggesting something like (in sequence) :
1) draw a cursor
2) catch new mouse position
3) delete cursor at old position
4) draw cursor at new position
... and so on.
Right ?

nickysn

  • New Member
  • *
  • Posts: 11
Re: dos program
« Reply #29 on: December 08, 2020, 07:47:06 am »
Yes, something like that.

 

TinyPortal © 2005-2018