Archive: VB and NSIS


VB and NSIS
When I call NSIS generated installer from VB program it doesn't show up on the screen foreground but only in taskbar?
How do I bring it to the screen foreground?


Try ExecShell with SW_SHOWMAXIMIZED.

Stu


Here's some VB6 code we use to restore other windows:

'These next sections are helpful to find a window specifically by its handle (hWnd)
'----------------------------------------------------
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Declare Function SetActiveWindow Lib "user32" (ByVal hWnd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Declare Function GetWindowPlacement Lib "user32" (ByVal hWnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Const SW_SHOW = 5
Const SW_RESTORE = 9
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWNORMAL = 1

Public Type Rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type POINTAPI
x As Long
y As Long
End Type

Private Type WINDOWPLACEMENT
Length As Long
Flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As Rect
End Type

Private lpwndpl As WINDOWPLACEMENT


Public Function RestoreWindow(lngHandle As Long) As Boolean
'If you know a window's handle, this will restore the window to the front

On Local Error GoTo ErrorHandler

Dim lState As Long
Dim bRetVal As Boolean

bRetVal = False
lpwndpl.Length = 44

lState = GetWindowPlacement(lngHandle, lpwndpl)
HandleDebug "lState is: " & lState
If lState <> 0 Then
Select Case lpwndpl.showCmd
Case SW_SHOWMINIMIZED
Call ShowWindow(lngHandle, SW_RESTORE)
Case SW_SHOWNORMAL, SW_SHOWMAXIMIZED
Call ShowWindow(lngHandle, SW_SHOW)
End Select
Call SetFocus(lngHandle)
Call SetActiveWindow(lngHandle)
Call SetForegroundWindow(lngHandle)
bRetVal = True
End If

RestoreWindow = bRetVal
Exit Function
ErrorHandler:
MsgBox "Error loading window"
RestoreWindow = bRetVal
End Function


If you need to get a window's handle, you can do so with this...

lngHandle = FindWindow(vbNullString, [window's caption name])

If you need a VB.NET version, just let me know.


Looks like you guys are trying to make this too complicated?
Pls notice that this is NSIS generated install program run FROM VB menu program which starts by CD-ROM's Autorun.
I have dozen separate programs in the menu of VB program.
I want to select program to install by clicking VB program button.
All install programs created in VB properly execute in the foreground but all NSIS install programs execute to HIDING. Only taskbar shows that it is running.
There is no ExecShell anywhere here.
There is Shell in VB menu program running the install programs.
Thanks


http://www.vbaccelerator.com/codelib/shell/shellex.htm

If you wrote the installer, try putting a BringToFront in the welcome page's show function (or onGUIInit).

Stu


Thanks, this worked:

!define MUI_CUSTOMFUNCTION_GUIINIT MyGUIInit

Function MyGUIInit
BringToFront
FunctionEnd


BringToFront doesn't work on newer Windows versions (Microsoft I suppose disabled the underlying feature due to too many spyware popups). BringToFront instead will just cause the taskbar item to blink.

As both of us mentioned, the problem is not with NSIS, it's with how you launch the application from within VB.


Do not know any better so I do:

Private Sub ButtonMyProgram_Click()
Shell "Programs\Setup_MyProgram.exe"
End Sub

which works with Win2000 & WinXP and BringToFront in my NSIS script.
Can you please give details how I suppose do it right?


Again, just so you know, newer Windows versions do not allow applications to bring themselves to the front. Only applications in front have the rights to bring other apps in front.

In VB6, I think you can do this with:

Shell "Programs\Setup_MyProgram.exe", vbNormalFocus

If you ever wondered why Shell has 2 parameters in vb6, now you know why :)