ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   AppActivate / Minimized Windows / GetWindowPlacement (https://www.excelbanter.com/excel-programming/410458-appactivate-minimized-windows-getwindowplacement.html)

MeistersingerVonNurnberg

AppActivate / Minimized Windows / GetWindowPlacement
 
Hi - Trying to activate an app that may or may not be minimized. Thought I
might be able to use the GetWindowPlacement api call, but it keeps crashing.
Likely due to my calculation of the WINDOWPLACEMENT struct / type size. Below
is the code of what I am doing. Any ideas?


' WinAPI structured type declarations.
Type POINTAPI
X As Integer
Y As Integer
End Type

Type RECT
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type

Type WINDOWPLACEMENT
length As Integer
flags As Integer
showCmd As Integer
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type

' WinAPI function declarations.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function GetWindowPlacement Lib "user32" (ByVal hWnd As
Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
Public Declare Function SetWindowPlacement Lib "user32" (ByVal hWnd As
Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer


Sub Some_Sub()
Dim lRC As Long
Dim hWnd As Integer
Dim wp As WINDOWPLACEMENT

hWnd = FindWindow(vbNullString, "UltraEdit - [file.txt]")
If hWnd = 0 Then GoTo gto_Exit_Function

wp.length = Len(wp)
lRC = GetWindowPlacement(hWnd, wp) ' == CRASHES HERE; MAYBE B/C OF LEN
CALC ABOVE? <==
If lRC = 0 Then GoTo gto_Exit_Function

gto_Exit_Function:
If Err Then Err.Clear

End Sub


MeistersingerVonNurnberg

AppActivate / Minimized Windows / GetWindowPlacement
 
change the below "integer" to "long" and everything works fine.

"MeistersingerVonNurnberg" wrote:

Hi - Trying to activate an app that may or may not be minimized. Thought I
might be able to use the GetWindowPlacement api call, but it keeps crashing.
Likely due to my calculation of the WINDOWPLACEMENT struct / type size. Below
is the code of what I am doing. Any ideas?


' WinAPI structured type declarations.
Type POINTAPI
X As Integer
Y As Integer
End Type

Type RECT
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
End Type

Type WINDOWPLACEMENT
length As Integer
flags As Integer
showCmd As Integer
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type

' WinAPI function declarations.
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Integer
Public Declare Function GetWindowPlacement Lib "user32" (ByVal hWnd As
Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
Public Declare Function SetWindowPlacement Lib "user32" (ByVal hWnd As
Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer


Sub Some_Sub()
Dim lRC As Long
Dim hWnd As Integer
Dim wp As WINDOWPLACEMENT

hWnd = FindWindow(vbNullString, "UltraEdit - [file.txt]")
If hWnd = 0 Then GoTo gto_Exit_Function

wp.length = Len(wp)
lRC = GetWindowPlacement(hWnd, wp) ' == CRASHES HERE; MAYBE B/C OF LEN
CALC ABOVE? <==
If lRC = 0 Then GoTo gto_Exit_Function

gto_Exit_Function:
If Err Then Err.Clear

End Sub



All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com