Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)
Private Sub Form_Activate()
'Set the window position to topmost
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub 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)
Private Sub Form_Activate()
'Set the window position to topmost
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
thanks
not working
heres the code(in usercontrol project):
Code:
Private Sub Timer1_Timer()
Dim winpos As RECT
Dim winpos2 As RECT
'Call Transparency_Initialize
GetWindowRect UserControl.ParentControls(0).hwnd, winpos2
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
If Ambient.UserMode = False Then Timer1.Enabled = False
End Sub
and the rest:
Code:
Public Property Get Transparency() As Byte
Transparency = m_Transparency
End Property
Public Property Let Transparency(ByVal New_Transparency As Byte)
If New_Transparency < 0 Or New_Transparency > 255 Then Exit Property
m_Transparency = New_Transparency
'TR Edit Please note
If New_Transparency = 255 Then
SetLayeredWindowAttributes UserControl.hwnd, 0, 255, LWA_ALPHA
Exit Property
End If
Transparency_Initialize
SetLayeredWindowAttributes UserControl.hwnd, 0, m_Transparency, LWA_ALPHA
PropertyChanged "Transparency"
End Property
Private Sub Transparency_Initialize()
Dim TMP As Long
If Timer1.Enabled Then Exit Sub
TMP = GetParent(UserControl.hwnd)
SetParent UserControl.hwnd, 0
SetWindowLong UserControl.hwnd, GWL_EXSTYLE, GetWindowLong(UserControl.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes UserControl.hwnd, 0, 64, LWA_ALPHA
SetParent UserControl.hwnd, TMP
UserControl.Refresh
Timer1.Interval = 15
Timer1.Enabled = True
End Sub
Not sure I follow but, If SetWindowPos is called in your usercontrol shouldn't the handle be UserControl.hWnd or UserControl.Parent.hWnd instead of Me.Hwnd ?
Not sure I follow but, If SetWindowPos is called in your usercontrol shouldn't the handle be UserControl.hWnd or UserControl.Parent.hWnd instead of Me.Hwnd ?
still having position problem
is like i can't plus the form position with usercontrol position
Try getting the code working without using the user control. Also Edgemeal makes a good point. If you're using Me inside the user control, that's probably not the parent form so it might be applying the code to the wrong window. You can use debug.print to see the window handle of the form and then use it again to see which handle you're running your code on. Are they different?
Has someone helped you? Then you can Rate their helpful post.
Try getting the code working without using the user control. Also Edgemeal makes a good point. If you're using Me inside the user control, that's probably not the parent form so it might be applying the code to the wrong window. You can use debug.print to see the window handle of the form and then use it again to see which handle you're running your code on. Are they different?
then tell me why isn't working, but in that UC.zip is working?
i only copy... that's strange... tell me something, please
I prefer to use the SetWindowPos in the form_paint event. I have found that as a software is running it can lose its top position to other windows and putting the SetWindowPos in the form paint the api call gets "reset" frequently enough to keep it on top permanently.