GetStartupInfo_ if clicked or keyed

Just starting out? Need help? Post your questions and find answers here.
eJan
Enthusiast
Enthusiast
Posts: 368
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

GetStartupInfo_ if clicked or keyed

Post by eJan »

Hi, i have small clenup utility which uses 'si\dwFlags & #STARTF_TITLESHORTCUT ' is there possibility to detect if the program was opened from StartMenu or with Keyboard 'Ctrl + Alt + F8' as it in both cases runs automatically (i have to set some parameters what to clean when opened from StartMenu), when opened with 'Ctrl + Alt + F8' to go automatic.

Code: Select all

; El_Choni: http://www.purebasic.fr/english/viewtopic.php?p=143028#143028

; Returns TRUE if started through a shortcut, FALSE if not.

#STARTF_TITLESHORTCUT = $800
 
Procedure StartedFromShortcut() 
  GetStartupInfo_(@si.STARTUPINFO) 
  If si\dwFlags & #STARTF_TITLESHORTCUT 
    ProcedureReturn #True 
  EndIf 
  ProcedureReturn #False 
EndProcedure  

MessageRequester("Started from shortcut?:", Str(StartedFromShortcut()))
Win 11 25H2 Pro
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

How do you do the Ctrl + Alt + F8 ?
eJan
Enthusiast
Enthusiast
Posts: 368
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Rescator wrote:How do you do the Ctrl + Alt + F8 ?
Alt Gr + F8
Win 11 25H2 Pro
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Doesn't work here :P


Obviously you need to add the hotkey to the system some way right?
Why not do it like pretty much any other tool?

They use a silent or auto parameter.

That way the user can (if they want) make the shortcut the way they want it.

Installers usually have /silent or /s parameter.
eJan
Enthusiast
Enthusiast
Posts: 368
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

But when added switch /a to the shortcut i've got same result: Mouse clicked <> Keyboard pushed.
Try to compile, add shotrcut .lnk near to it and test.

Code: Select all

#STARTF_TITLESHORTCUT = $800

Procedure StartedFromShortcut()
  GetStartupInfo_(@si.STARTUPINFO)
  If si\dwFlags & #STARTF_TITLESHORTCUT
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure

param = CountProgramParameters()

If param
  MessageRequester("Started from shortcut?:", Str(StartedFromShortcut()))
Else
  MessageRequester("Started from shortcut?:", "Runing")
EndIf
EDIT: bad solution is to create two shortcuts in StartMenu with different switches, which will program check?
Win 11 25H2 Pro
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

First of all, #STARTF_TITLESHORTCUT (or $800) is un-documented, MSDN does not list it at all.
For such an important feature it's not wise to bet on it, it may only work on XP for example, you don't know.

Also, GetStartupInfo() only works on Win2K and later, in case you didn't know.

I understand what you mean now about the shortcut hotkey.
On Windows (at least XP and Vista I assume?) a shortcut has a extra shortcut tab that lets us set a hotkey.
Nope! there is no way to determine if the hotkey was pressed, as the hotkey combo is actually "simulating" clicking the shortcut.

And I'm confused what you are trying to do.
You want the program to go into automatic mode if the user uses the hotkey combo, I hope you make sure it can't be started multiple times.

If I where you I'd do it the other way around. Only allow automatic from a commandline or scheduler using parameters. While a normal shortcut and hotkey starts the full program, you avoid accidental cleanups that way.


The whole point of the shortcut is that clicking it (or using a hotkey) is just like clicking the program icon.
Also make sure that you do not force the user to use global hotkey (it may even clash with other programs).

If this is a program only for yourself on the other hand you can do whatever you want ;)
EDIT: bad solution is to create two shortcuts in StartMenu with different switches, which will program check?
I really do not understand what you mean here.
A lot of programs do it this way.
Some games/programs have a normal shortcut and a Safe mode (where settings are changed back to default) or even a Debug mode.
They use flags like nothing or /normal or -safe or debug etc.

And I'm not sure by what you mean by "which" the program will check?
If you could explain a bit more, or if you what to explain in your own language then do so and if I'm unable to understand I'll just ask someone else here to translate for me. (I read "some" German).

I guess what I'm trying to say is, I'm confused as to what you are trying to do here. :)
eJan
Enthusiast
Enthusiast
Posts: 368
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

Thanks Rescator for your help, lets leave it as it is for now.
Win 11 25H2 Pro
Post Reply