Old 15th October 2007, 17:13   #1
Kauko
Junior Member
 
Join Date: Oct 2007
Posts: 4
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?
Kauko is offline   Reply With Quote
Old 15th October 2007, 17:17   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Try ExecShell with SW_SHOWMAXIMIZED.

Stu
Afrow UK is offline   Reply With Quote
Old 15th October 2007, 18:33   #3
helix400
Member
 
Join Date: Oct 2003
Posts: 51
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.
helix400 is offline   Reply With Quote
Old 15th October 2007, 19:07   #4
Kauko
Junior Member
 
Join Date: Oct 2007
Posts: 4
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
Kauko is offline   Reply With Quote
Old 15th October 2007, 20:23   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 16th October 2007, 14:10   #6
Kauko
Junior Member
 
Join Date: Oct 2007
Posts: 4
Thanks, this worked:

!define MUI_CUSTOMFUNCTION_GUIINIT MyGUIInit

Function MyGUIInit
BringToFront
FunctionEnd
Kauko is offline   Reply With Quote
Old 17th October 2007, 21:32   #7
helix400
Member
 
Join Date: Oct 2003
Posts: 51
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.
helix400 is offline   Reply With Quote
Old 18th October 2007, 11:05   #8
Kauko
Junior Member
 
Join Date: Oct 2007
Posts: 4
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?
Kauko is offline   Reply With Quote
Old 19th October 2007, 06:43   #9
helix400
Member
 
Join Date: Oct 2003
Posts: 51
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
helix400 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump