🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #14753

Re: Welke codes in VB6 om te voorkomen dat het programma tegelijkertijd uitgevoerd wordt?

#14753
From: dlacc
Date: Wed, 10 Jan 2001 21:37
85 lines
3543 bytes
In article <9351an$f7n$1@news1.skynet.be>,
  "Verhaeghe Pieter" <verhaeghe.pieter@skynet.be> wrote:
> Welke codes in Visual Basic 6.0 moet ik gebruiken, zodat mijn
programma niet
> twee maal open kan staan.  Wanneer het programma twee maal open
staat, komt
> er een foutmelding voor: de database is reeds geopend.
>
> Graag antwoord,
>
> Verhaeghe Pieter
>
>


Option Explicit

      Public Const GW_HWNDPREV = 3

      Declare Function OpenIcon Lib "user32" (ByVal hwnd As Long) As
Long
      Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
         (ByVal lpClassName As String, ByVal lpWindowName As String) _
         As Long
      Declare Function GetWindow Lib "user32" _
         (ByVal hwnd As Long, ByVal wCmd As Long) As Long
      Declare Function SetForegroundWindow Lib "user32" _
        (ByVal hwnd As Long) As Long

      Sub ActivatePrevInstance()
         Dim OldTitle As String
         Dim PrevHndl As Long
         Dim result As Long

         'Save the title of the application.
         OldTitle = App.Title

         'Rename the title of this application so FindWindow
         'will not find this application instance.
         App.Title = "unwanted instance"

         'Attempt to get window handle using VB4 class name.
         PrevHndl = FindWindow("ThunderRTMain", OldTitle)

         'Check for no success.
         If PrevHndl = 0 Then
            'Attempt to get window handle using VB5 class name.
            PrevHndl = FindWindow("ThunderRT5Main", OldTitle)
         End If

         'Check if found
         If PrevHndl = 0 Then
         'Attempt to get window handle using VB6 class name
         PrevHndl = FindWindow("ThunderRT6Main", OldTitle)
         End If

         'Check if found
         If PrevHndl = 0 Then
            'No previous instance found.
            Exit Sub
         End If

         'Get handle to previous window.
         PrevHndl = GetWindow(PrevHndl, GW_HWNDPREV)

         'Restore the program.
         result = OpenIcon(PrevHndl)

         'Activate the application.
         result = SetForegroundWindow(PrevHndl)

         'End the application.
         End
      End Sub

'Dit in de Form load event
If App.PrevInstance Then
     ActivatePrevInstance
  End If




Sent via Deja.com
http://www.deja.com/
Technical Details
Message-ID: <93ikm5$i7r$1@nnrp1.deja.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news3.cnt.ru!mtu.ru!newsfeed.sovam.com!news3.bellglobal.com!sunqbc.risq.qc.ca!nntp1.njy.teleglobe.net!teleglobe.net!news.stealth.net!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail
References: <9351an$f7n$1@news1.skynet.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 107324,d0015270be29ee92
X-Google-Attributes: gid107324,public
X-Google-Thread: fcea4,d0015270be29ee92
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2001-01-10 13:58:04 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news3.cnt.ru!mtu.ru!newsfeed.sovam.com!news3.bellglobal.com!sunqbc.risq.qc.ca!nntp1.njy.teleglobe.net!teleglobe.net!news.stealth.net!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail
From: dlacc@hotmail.com
Newsgroups: be.comp.programming,nl.comp.programmeren
Subject: Re: Welke codes in VB6 om te voorkomen dat het programma tegelijkertijd uitgevoerd wordt?
Date: Wed, 10 Jan 2001 21:37:10 GMT
Organization: Deja.com
Lines: 85
Message-ID: <93ikm5$i7r$1@nnrp1.deja.com>
References: <9351an$f7n$1@news1.skynet.be>
NNTP-Posting-Host: 195.96.98.188
X-Article-Creation-Date: Wed Jan 10 21:37:10 2001 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
X-Http-Proxy: 1.1 www.cache.casema.net (NetCache 4.1R1D5), 1.1 x65.deja.com:80 (Squid/1.1.22) for client 212.64.60.81, 195.96.98.188
X-MyDeja-Info: XMYDJUIDrobbeukema