Author Topic: How to do a TRS program in Qb64?  (Read 4237 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
How to do a TRS program in Qb64?
« on: December 01, 2018, 05:32:33 am »
Hi guys
Please tell me
If I want/need to do a program that stay in memory waiting for data/event from another program to work indipendently ( not an hidden program) how must I do?
In old DOS time you can use the related Call Interrupt.  In actual OSes  how can It be done?
Programming isn't difficult, only it's  consuming time and coffee

FellippeHeitor

  • Guest
Re: How to do a TRS program in Qb64?
« Reply #1 on: December 01, 2018, 06:19:03 am »
Sounds like just a hidden program.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to do a TRS program in Qb64?
« Reply #2 on: December 01, 2018, 10:50:05 am »
I think you mean a TSR program
https://en.wikipedia.org/wiki/Terminate_and_stay_resident_program

Such programs were perfect ingredient for a virus as I recall.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How to do a TRS program in Qb64?
« Reply #3 on: December 01, 2018, 06:20:41 pm »
Hi
I try to be clearer...

Quote
TSRs have now almost disappeared, as multitasking operating systems such as Windows Vista, Windows 7, Mac OS X, and Linux provide the facilities for multiple programs and device drivers to run simultaneously without the need for special programming tricks, and the modern notion of protected memory makes the kernel and its modules exclusively responsible for modifying an interrupt table.

lets make some examples...
-a clock that rings at a set time
-a screencapture that acts when is triggered the set key
-a control center for scanner/printer
-a program that sincronize the output of two programs toward a port
-a launcher of programs/games
....so I ask
Quote
In actual OSes  how can It be done?
Theorically I have imagined that
1. the two program (the TSR program plus the related program) can use HDD by files to communicate data and/or events
2. TSR program can use Memory reading to get these informations to activate its work
by in the facts how can be done it?

Thanks
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How to do a TRS program in Qb64?
« Reply #4 on: December 01, 2018, 07:30:16 pm »
http://qb64.org/wiki/Windows_Libraries#Hot_Keys_.28maximize.29  --- This demo will help you with the hot keys concept for the screen capture idea, providing you're running in Windows.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: How to do a TRS program in Qb64?
« Reply #5 on: December 01, 2018, 11:30:49 pm »
That program from the WIKI does not restore or minimize on my Windows 10. If it is manually minimized and Shift + A is pressed, you have to manually restore it to see it registered the key press.

AHA! I had some time to fool with it this morning and it turns out it needs a _DELAY after _TITLE to grab that initial windows state handle...

So this does work...

Code: QB64: [Select]
  1.     FUNCTION FindWindowA%& (BYVAL ClassName AS _OFFSET, WindowName$) 'find process handle by title
  2.     FUNCTION GetKeyState% (BYVAL nVirtKey AS LONG) 'Windows virtual key presses
  3.     FUNCTION ShowWindow& (BYVAL hwnd AS _OFFSET, BYVAL nCmdShow AS LONG) 'maximize process
  4.     FUNCTION GetForegroundWindow%& 'find currently focused process handle
  5.     FUNCTION SetForegroundWindow& (BYVAL hwnd AS _OFFSET) 'set foreground window process(focus)
  6.  
  7. title$ = "Cheapo Hotkey (Shift+A)" 'title of program window
  8. _TITLE title$ 'set program title
  9.  
  10. _DELAY .1 ' I found this delay is needed to get the _TITLE function to catch up and be read by the API function.
  11.  
  12. hwnd%& = FindWindowA(0, title$ + CHR$(0)) 'find this program's process handle
  13.  
  14. PRINT "Minimize window, click another then Press Shift+A to bring it back up."
  15.  
  16. '=== below minimizes it for you
  17. x& = ShowWindow&(hwnd%&, 2)
  18. '===========================
  19.  
  20.     IF GetKeyState(16) < 0 AND GetKeyState(ASC("A")) < 0 THEN '<==== Shift+A
  21.         FGwin%& = GetForegroundWindow%& 'get current process in focus
  22.         PRINT "Program Handle:"; hwnd%&; "Focus handle:"; FGwin%&
  23.  
  24.         y& = ShowWindow&(hwnd%&, 1) 'maximize minimized program
  25.  
  26.         IF FGwin%& <> hwnd%& THEN z& = SetForegroundWindow&(hwnd%&) 'set focus when necessary
  27.  
  28.         PRINT "That is all. Return values:"; x&; y&; z&
  29.  
  30.         _DELAY 5: END 'delay allows user to not minimize the window
  31.     END IF
  32.  
  33.     _LIMIT 30 'save CPU usage while waiting for key press
  34.  

Pete
« Last Edit: December 02, 2018, 11:49:25 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How to do a TRS program in Qb64?
« Reply #6 on: December 03, 2018, 02:28:34 pm »
@Thanks Pete

you have solved a my bad experience with windows calling of some time ago.
So I'll find time to go on with my DLL windows calling...


@Thanks Steve
your answer let me understand that each kind of program can be developed with a different kind of tecnique

DLL calling for minimize and send a specific hotkey for the program
a second program running with a first to syncronize the output to the driver of printer/scanner
a second program running with a first to manage program/game launched
an indipendent program for clock alarm or for mange landscape or screensaver to lock to system functions

Thank again


Programming isn't difficult, only it's  consuming time and coffee

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: How to do a TRS program in Qb64?
« Reply #7 on: December 03, 2018, 06:12:49 pm »
Hi,

If I may say, TSR were an excellent way to create utilities for DOS that would come over other applications like wordprocessor or spreadsheet using a DOS "bug" of an undocumented interupt calls when pressing a specific keystroke combination.

Back in the late 80ies, one of the most known TSR was Sidekick (from Borland) providing a notepad when pressing Left Shift + Right Shift.

In 1990, I developped with Turbo Pascal for my company (ISS) another worldwide used TSR "à la Sidkick" named TurboDesk that was usable when pressing Ctrl+Alt+Home and providing an editor with 3 text windows, an ASCII table, a Calendar, a Screen Cut function, an interface with the Clipboard and a programmable calculator that could replay macros from a "tape".

Bellow is a screen shot of my TurboDesk menu over QuickBasic (running in a DOS 6.3 VM).

http://www.as2.com/pictures/jpg/td.jpg

That was really a funy time when we could make money from our work.

Cheers.
Fifi
« Last Edit: December 03, 2018, 06:15:15 pm by Fifi »
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How to do a TRS program in Qb64?
« Reply #8 on: December 09, 2018, 05:50:37 pm »
Yes DOS Time
when in the deep dark screen, making a window interface gave depth to your application...with mouse implementation...

How is strange that now, after years of windowOses, I am uncomfortable in the black Linux console...

lazyness to learn the new console ?!?
Programming isn't difficult, only it's  consuming time and coffee

Offline Fifi

  • Forum Regular
  • Posts: 181
    • View Profile
    • My small QB64 contribution
Re: How to do a TRS program in Qb64?
« Reply #9 on: December 11, 2018, 01:19:25 pm »
Hi TempodiBasic,

How is strange that now, after years of windowOses, I am uncomfortable in the black Linux console...

Change it to white. ;)
Just teazing.

BTW, did you check the accuracy of my Italian messages?

You can get the last release of my install script on my dedicated web page : http://www.as2.com

TIA for your time.
Fifi
It's better to look like an idiot for a short time while asking something obvious to an expert than pretending to be smart all your life. (C) Me.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: How to do a TRS program in Qb64?
« Reply #10 on: December 11, 2018, 08:20:43 pm »
@Fifi
here there is attached the file of script with modifications of some affirmation to get a better italian speech.
Programming isn't difficult, only it's  consuming time and coffee