Only one instance of program in windows environment 
Author Message
 Only one instance of program in windows environment

I want to allow one instance in the windows environemtn. I use the code

    If App.PrevInstance Then
        AppActivate App.Title
    end if

But how do I restore the program postion and size if it is mininized and
bring it to the front?
Thanks in advance
                                                                        Richard.



Sun, 25 Mar 2001 03:00:00 GMT  
 Only one instance of program in windows environment
Use the ShowWindow() API to unminimize it, and SetForeGroundWindow() to
bring it to the top (I've heard this fails in Win98).  Here's the code I
use:

    Const GW_HWNDNEXT = 2
    Const GW_CHILD = 5
    Const VB5CLASSNAME = "ThunderRT5Form"

    'Allow only one instance
    If App.PrevInstance Then
        'caption of hap always begins with HapCap:
        'HAPCAP = "Hap40 - [" (defined as public const)
        'allocate room for class name
        sClassName = Space(256)
        'Start from the first child of the desktop
        DeskTopWin = GetDesktopWindow()
        ApphWnd = GetWindow(DeskTopWin, GW_CHILD)
        'Now go through all its siblings
        Do While ApphWnd
            'check if the caption seems like hap's
            AppCap = Space(256)
            Ret = GetWindowText(ApphWnd, AppCap, 255)
            If Left$(AppCap, 9) = HAPCAP Then
                'check class name to be sure it's a VB5 app
                Ret = GetClassName(ApphWnd, sClassName, 255&)
                If Left$(sClassName, Ret) = VB5CLASSNAME Then
                    'restore it if minimized and bring it to front
                    dum = ShowWindow(ApphWnd, 9)
                    dum = SetForegroundWindow(ApphWnd)
                    Exit Do
                End If
            End If
            'get the next sibling of the child of the desktop
            ApphWnd = GetWindow(ApphWnd, GW_HWNDNEXT)
        Loop
        Screen.MousePointer = vbDefault
        End
    End If

Jim Deutch
MS Dev MVP



Quote:
> I want to allow one instance in the windows environemtn. I use the code

>     If App.PrevInstance Then
>         AppActivate App.Title
>     end if

> But how do I restore the program postion and size if it is mininized and
> bring it to the front?
> Thanks in advance
>                                                                    Richard.



Sun, 25 Mar 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Modifying contents of one window instance from another window instance

2. Only one instance of my program to be shown

3. Limiting to one instance of a VB3 program

4. Limiting to one instance of a VB3 program

5. Restricting to create only one instance of a Windows Form

6. one instance running in MS windows

7. Installing 16 bit VB program in Network Windows environment

8. Starting one and only one instance of Internet Explorer

9. A couple of questions (Data Environment and one lame one)

10. setting object variable to new instance of data environment causes error

11. One Presentation and Two instance

12. Find more than one instance using range object

 

 
Powered by phpBB® Forum Software