当用户尝试在 vb6 中打开新实例时返回到已打开的应用程序 [英] Return to an already open application when a user tries to open a new instance in vb6

查看:31
本文介绍了当用户尝试在 vb6 中打开新实例时返回到已打开的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设用户将我的可视化基本应用程序最小化到任务栏通知图标.现在我想当用户打开一个新实例时,旧的应该恢复.

Suppose a user minimize my visual basic application to the taskbar notification icon. Now I want when user open a new instance, the old one should restore.

推荐答案

您通常可以很简单地以退化的方式使用 DDE:

You can often do this fairly simply using DDE in a degenerate way:

Form1.frm

Option Explicit
'This is Form1.  To use as DDE source at design time we set:
'   Form1.LinkMode = 1 (Source, i.e. vbLinkSource).
'   Form1.LinkTopic = "Form1" (default).
'
'Note we use (hidden) Label1 on this Form as a DDE destination.

Private PrevState As Integer

Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
    'Got a "command" so restore Form1 and accept the command.
    WindowState = PrevState
    Caption = "I am awake!"
    Cancel = False
End Sub

Private Sub Form_Load()
    PrevState = WindowState
End Sub

Private Sub Form_Resize()
    If WindowState <> vbMinimized Then PrevState = WindowState
End Sub

Module1.bas

Option Explicit

Private Sub Main()
    Load Form1
    'After Form1 is loaded (hidden), try DDE link to possible prior copy.
    With Form1.Label1
        .LinkTopic = App.EXEName & "|Form1"
        On Error Resume Next
        .LinkMode = vbLinkManual
        If Err.Number = 0 Then
            On Error GoTo 0
            'Link succeeded.  Wake up prior copy via pushback to
            'the DDE source, then unload Form1 and terminate.
            .LinkExecute "Wake up!"
            Unload Form1
        Else
            On Error GoTo 0
            'Link failed, so we're 1st.  Show Form1.
            Form1.Show vbModal
        End If
    End With
End Sub

这篇关于当用户尝试在 vb6 中打开新实例时返回到已打开的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆