Jamyn
10th March 2006 16:30 UTC
Unminimize solution?
Hi all,
I noticed that this wiki page, which talks about setting a mutex and only allowing one copy of the installer to run, has been updated.
Someone updated the page with an advanced example that will check for the installer, and if someone tries to launch two copies - it will set the first one as the active window instead.
Now I know this is a tiny thing, but if the user has (for some reason) minimized the first installer window, the example will indeed set the first one as the active window. But, it will not "pop" it back up from being minimized. At least this is the case when testing on Windows XP.
Do any of you smart people know the proper way to add the functionality to this example? I thought it would be a useful addition to the advanced example, but don't want to modify it in an unportable way.
*wishes he knew a lot more... ok anything.. about windows api stuff* ;)
Thanks,
-J
kichik
10th March 2006 16:42 UTC
You can try adding a call to ShowWindow:
!include WinMessages.nsh
ShowWindow $1 ${SW_SHOW}
Jamyn
10th March 2006 16:44 UTC
Thanks
Thanks Kichik -- I drink from your fountain of knowledge regularly ;) Much appreciated.
Jamyn
10th March 2006 17:03 UTC
How about this?
I will say up front - I'm very much grasping at thin air here, and "guessing" on the format of the extra line:
Is this a proper way to add this functionality in a portable way? (ie: not requiring the WinMessages include)? It does seem to work when I test it, but that does't mean it's the "right" way, that it won't blow up, etc.
System::Call "kernel32::CreateMutexA(i 0, i 0, t '$(^Name)') i .r0 ?e"
Pop $0
StrCmp $0 0 launch
StrLen $0 "$(^Name)"
IntOp $0 $0 + 1
loop:
FindWindow $1 '#32770' '' 0 $1
IntCmp $1 0 +4
System::Call "user32::GetWindowText(i r1, t .r2, i r0) i."
StrCmp $2 "$(^Name)" 0 loop
System::Call "user32::SetForegroundWindow(i r1) i."
System::Call "user32::ShowWindow(i r1) i."
; ShowWindow $1 ${SW_SHOW}
Abort
launch:
FunctionEnd
kichik
10th March 2006 17:11 UTC
WinMessages.nsh is included in the NSIS package, it's portable enough. There's no need to use the System plug-in when you've got ShowWindow as a built-in instruction. You can use the code I've put above as-is.
Your current code is missing an argument for ShowWindow. You passed only the window handle and forgot the requested show command.
Jamyn
11th March 2006 05:13 UTC
Sorry to mis-state what I meant. I have the flu, and have been quite medicated for the last few days. I find it hard to articulate correctly (not that I do much better of a job when I'm not sick, but...
I of course am not implying you write non-portable code :) What I mean to say is, I wanted to apply that one extra piece of the puzzle, to the current wiki entry. So I wanted to add the line using the same "style" as the wiki entry author - the author used the System:: method.
Perhaps I will just add another example, using the WinMessages style of doing things instead of using the System:: calls. Thanks again for your feedback to my question.