最小化问题
程序已运行一次,且最小化在任务栏.如再次运行程序是否能把已运行的程序还原 问题点数:50、回复次数:14Top
1 楼no_com(探花)回复于 2002-03-29 08:21:03 得分 0
可控制,稍后给你贴代码Top
2 楼zjhnwlh(清嘴)回复于 2002-03-29 08:28:47 得分 0
谢谢Top
3 楼zjhnwlh(清嘴)回复于 2002-03-29 12:34:07 得分 0
no_com 快点呀,谢谢Top
4 楼lqf(奇枫)回复于 2002-03-29 12:48:08 得分 0
是还原窗口位置,还是程序中原有的数据Top
5 楼zjhnwlh(清嘴)回复于 2002-03-30 12:46:15 得分 0
是还原窗口位置.Top
6 楼no_com(探花)回复于 2002-04-22 09:10:55 得分 0
private form_load()
If App.PrevInstance Then
MsgBox ("系统不能重载!"), vbExclamation, "系统信息"
Unload Me
End IfTop
7 楼zjhnwlh(清嘴)回复于 2002-04-22 10:03:14 得分 0
不是呀,是当第二次重载程序时还原第一次载入的窗口,并且置窗口为顶层Top
8 楼dbcontrols(泰山__抛砖引玉)回复于 2002-04-22 10:13:43 得分 10
用API的FindWindow找到第一个窗口
用IsIconic判断是否被最小化
用OpenIcon来恢复Top
9 楼PluteWu(吴勇强)回复于 2002-04-22 20:23:06 得分 10
唯一的辦法是用API的方式,請給我MAIL地址,我將代碼寄給你。Top
10 楼daryl715(上善若水)回复于 2002-04-22 20:26:03 得分 0
泰山的方法我用过Top
11 楼enmity(灵感之源)回复于 2002-04-22 23:02:49 得分 10
Private Sub Form_Load()
If App.PrevInstance Then
ActivatePrevInstance
End If
End Sub
'2) Add a Standard Module to the Project
' .
'3) Paste the following code into the mo
' dule:
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
Top
12 楼enmity(灵感之源)回复于 2002-04-22 23:06:45 得分 10
'方法2 :
Public Const SW_NORMAL = 1
Public Const SW_MAXIMIZE = 3
Public Const SW_RESTORE = 9
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function ShowWindowAsync Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Sub Form_Load()
Dim temphwnd As Long, x As Long, AppTitle As String
If App.PrevInstance Or FindWindow("ThunderRT5Form", App.Title) > 0 Then
'get the handle to the window
'for non- forms use: temphwnd = FindW
' indow("ThunderRT5Form", App.Title)
temphwnd = FindWindow("ThunderRT5Form", App.Title)
'Here's the Aliasace secret!!!
AppTitle = App.Title
App.Title = "#$#"
Form1.Caption = "#$#"
'HERE's THE TWEAK
'activate the previous instance at the s
' ame
'place and size it was before
'could do ti non-asyc with ShowWindow bu
' t that
'lead to problems when working outside t
' he current thread
x = ShowWindowAsync(temphwnd, SW_RESTORE)
'bring it to the top of the z-order
SetWindowPos temphwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
'set focus to it
AppActivate AppTitle$
'now release it's lock on the z-order
'or other windows wont be able to show c
' orrectly
'remove this, run the app and watch how
' the OS tooltips
'for things like the windows min/max/clo
' se buttons
'appear behind the window, hence the rel
' ease call
SetWindowPos temphwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End
End If
'passed through, must be 1st instance
Form1.Caption = App.Title
Form1.Show
End Sub
Top
13 楼Alsen(大闸蟹(恶人谷水产局局长))回复于 2002-04-23 00:05:26 得分 0
同意 no_com(探花)Top
14 楼vcshcn(黑天的猩猩)回复于 2002-04-23 00:07:05 得分 10
找到那个窗口句柄,然后showwindow(那个句柄,SW_RESTORE)Top




