Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

strange window behaviour in SW x64 1

Status
Not open for further replies.

dogarila

Mechanical
Oct 28, 2001
594
0
0
CA
I have some VB programs and some VBA programs to help me with my work. They worked fine in SW2009 x32. After I upgraded to SW2009x64 (Windows XP) they started this annoying behaviour that the window they open goes to the bottom of the windows on my screen and I have to dig for it. Same behaviour in SW2010 x64 on Windows 7. I checked one of Tick's programs and it does the same thing. Has anyone encountered this problem and has a solution? I have SW2009 x64 installed at home on Windows Vista and don't have this issue.
 
Replies continue below

Recommended for you

I have seen the same behavior exactly as you have stated. I just learned to use the windows button + tab button and select the macro window. I am on windows 7, sw2010 x64.
 
Thanks gopack13 for the link. It needed a little tinkering but I got it running. I had to declare the functions private and remove "Global" in front of const.

Code:
Option Explicit

Private 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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Dim res As Long
Dim lRet As Long

Const SWP_NOMOVE As Long = 2
Const SWP_NOSIZE As Long = 1
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Const HWND_TOPMOST As Long = -1
Const HWND_NOTOPMOST As Long = -2

and in main() or form_load() in my case, right at the end:
Code:
lRet = FindWindow(vbNullString, UserForm1.Caption)
res = SetWindowPos(lRet, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
 
I have had this problem with SW2010 and 2011 on both Vista and 7 x64.

This is sofar my best solution.
Every time i have a messagebox i then have to redo it.

Code:
swApp.SendMsgToUser2 "Bla bla", swMbInformation, swMbOk
  
UserForm_Layout

Code:
Sub SetTopMost(sCaption As String)
  Const FLAG = SWP_NOSIZE + SWP_NOMOVE
  Dim hWndForm As Long

  On Error Resume Next

  hWndForm = FindWindow(vbNullString, sCaption)           'get the handle of the userform
  Call SetWindowPos(hWndForm, HWND_TOPMOST, 0, 0, 0, 0, FLAG)
End Sub

Sub UnsetTopMost(sCaption As String)
  Const FLAG = SWP_NOSIZE + SWP_NOMOVE
  Dim hWndForm As Long

  On Error Resume Next

  hWndForm = FindWindow(vbNullString, sCaption)           'get the handle of the userform
  Call SetWindowPos(hWndForm, HWND_NOTOPMOST, 0, 0, 0, 0, FLAG)
End Sub

and then in the form i add

Code:
Private Sub UserForm_Layout()
  SetTopMost Me.Caption
  UnsetTopMost Me.Caption
End Sub
This is the only way i found to bring the form to front and still not lockup solidworks totally afterwards.
 
Status
Not open for further replies.
Back
Top