473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Restore Window After Duplicate Instance Check

I can determine if another instance is running, but how do I get it's
minimized window to restore (in VBNET). Using the standard win32 functions
is not working.

Thanks
Nov 21 '05 #1
6 2284

Credit to Herfried...

Public Const GW_HWNDPREV = 3
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As
Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal handle As IntPtr, ByVal nCmd As
Int32) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsIconic(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsZoomed(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function
Public Shared Sub SetToForGround(ByVal hwnd As IntPtr)
Dim strStatus As String
'Dim hwnd As IntPtr
'hwnd = p.MainWindowHandle

If IntPtr.Zero.Equals(hwnd) Then
strStatus = ""
Exit Sub
End If
If IsIconic(hwnd) Then
strStatus = "MIN"
End If
'If IsZoomed(hwnd) Then
' IsNormal = True
'End If
'If IsIconic(hwnd) And IsZoomed(hwnd) Then
' IsNormal = True
'End If

If strStatus = "MIN" Then
'mimized
ShowWindow(hwnd, SW_RESTORE)
SetForegroundWindow(hwnd)
Else
'maximzed or restored
SetForegroundWindow(hwnd)
End If
End Sub

"Glenn" <g.***@comcast.net> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl:
I can determine if another instance is running, but how do I get it's
minimized window to restore (in VBNET). Using the standard win32 functions
is not working.

Thanks


Nov 21 '05 #2
Herfried's code is extremely long when you can produce the same result is
around 3-5 lines.

Why not use appActivate using the process handle?

Crouchie1998
BA (HOS) MCP MCSE
Nov 21 '05 #3
Herfried

Why didn't you just tell the user to Import System.Runtime.InteropServices
to shorten then API calls?

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #4
Sorry for delay, I was away:

AppActivate does not restore the window according to the documentation and
also from trying.

Thanks for your comment.

Best,
Glenn
"Crouchie1998" <cr**********@spamcop.net> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
Herfried's code is extremely long when you can produce the same result is
around 3-5 lines.

Why not use appActivate using the process handle?

Crouchie1998
BA (HOS) MCP MCSE

Nov 21 '05 #5
Thanks for your response. I will give it a try. Seems amazing that for
something that one might think was a fairly common need, there would not be
something simple built in
like App.Activate, something like, App.Activat(RestoreWindow), etc.

Best,
Glenn

"scorpion53061" <sc************@nospamhereyahoo.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

Credit to Herfried...

Public Const GW_HWNDPREV = 3
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As
Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal handle As IntPtr, ByVal nCmd As
Int32) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsIconic(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsZoomed(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function
Public Shared Sub SetToForGround(ByVal hwnd As IntPtr)
Dim strStatus As String
'Dim hwnd As IntPtr
'hwnd = p.MainWindowHandle

If IntPtr.Zero.Equals(hwnd) Then
strStatus = ""
Exit Sub
End If
If IsIconic(hwnd) Then
strStatus = "MIN"
End If
'If IsZoomed(hwnd) Then
' IsNormal = True
'End If
'If IsIconic(hwnd) And IsZoomed(hwnd) Then
' IsNormal = True
'End If

If strStatus = "MIN" Then
'mimized
ShowWindow(hwnd, SW_RESTORE)
SetForegroundWindow(hwnd)
Else
'maximzed or restored
SetForegroundWindow(hwnd)
End If
End Sub

"Glenn" <g.***@comcast.net> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl:
I can determine if another instance is running, but how do I get it's
minimized window to restore (in VBNET). Using the standard win32
functions
is not working.

Thanks

Nov 21 '05 #6
Finally got to test. Restoring from icon does not work. If the window is
maximized or normal, the window comes to foreground, but if minimized, then
not. IsIconic() reports false when window minimized. Also, ShowWindow does
not restore and SetToForground does not even highlight the window.

Any further ideas?
--
Thanks.

Best,
Glenn
"scorpion53061" wrote:

Credit to Herfried...

Public Const GW_HWNDPREV = 3
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As
Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal handle As IntPtr, ByVal nCmd As
Int32) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsIconic(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32. dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.Calling Convention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsZoomed(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function
Public Shared Sub SetToForGround(ByVal hwnd As IntPtr)
Dim strStatus As String
'Dim hwnd As IntPtr
'hwnd = p.MainWindowHandle

If IntPtr.Zero.Equals(hwnd) Then
strStatus = ""
Exit Sub
End If
If IsIconic(hwnd) Then
strStatus = "MIN"
End If
'If IsZoomed(hwnd) Then
' IsNormal = True
'End If
'If IsIconic(hwnd) And IsZoomed(hwnd) Then
' IsNormal = True
'End If

If strStatus = "MIN" Then
'mimized
ShowWindow(hwnd, SW_RESTORE)
SetForegroundWindow(hwnd)
Else
'maximzed or restored
SetForegroundWindow(hwnd)
End If
End Sub

"Glenn" <g.***@comcast.net> wrote in message
news:#Y**************@TK2MSFTNGP11.phx.gbl:
I can determine if another instance is running, but how do I get it's
minimized window to restore (in VBNET). Using the standard win32 functions
is not working.

Thanks


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vikrant | last post by:
Friends, Due an application (old) install program problem, Under AIX I could only create DB2 instance, I could also catalog it. Its complex application and I am not expert in creating full...
2
by: Vikrant | last post by:
Friends, I have read DB2/UDB 8.x 'RESTORE DATABASE Command', with my 'limited' knowledge & skill. I think it should address my concern, but I want advice/ opinion / experience and any care I...
9
by: GL | last post by:
I am running DB2 8.1.1 on AIX 5.1 Having a problem with a redirected restore. Once into the restore continue phase, I immediately get the following “SQL2059W A device full warning was...
3
by: cerbdog | last post by:
Hello, all. Was hoping someone might be able to help us out with an issue: We're trying to perform a restore from a backup of one AIX 5.1 server, we'll call it "AIX", to another AIX 5.1 server;...
5
by: chow.justy | last post by:
Dear all, I'm a new beginner of DB2. I face 2 question during restore the data. I have 2 DB2 servers on my company. Server A is running on V7.2 and Server B is running on v8.2 (Enterprise...
4
by: lesperancer | last post by:
it looks like this will save many versions of a relationship window, but based on the fact that the same tables are displayed in the relationship window and it will restore versions of what was...
0
by: mitrofun63 | last post by:
Hello. On my production site i have DB2 9.1.2 database configured for archiving logs and making backup through TSM Data Protection for DB2 UDB The LOGARCHMETH1 parameter is set to ...
3
by: aka | last post by:
Hi, I'm actually working on the migration of a DB2 unicode db (V8.2 FP 15) from a Sunfire machine with SunOS (64 bit, Big-endian) to an AIX 5.3 (64-bit, Big-endian) server located in US. The...
4
by: DL | last post by:
Background Info: Instance A: SQL Server 2005 on Windows Server 2003 OS Instance B: SQL Server 2005 on XP Prof w/ SP2 Process: backup a database on Instance A like this: step 1 -- Management...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.