[VB6] - SetWindowPos() api function-VBForums
Results 1 to 9 of 9

Thread: [VB6] - SetWindowPos() api function

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,922

    [VB6] - SetWindowPos() api function

    can anyone tell me how use SetWindowPos() api function?
    my problem is how convert the values
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Junior Member 8086's Avatar
    Join Date
    Feb 2010
    Location
    tehran , IRAN
    Posts
    23

    Re: [VB6] - SetWindowPos() api function

    hi

    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

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,922

    Re: [VB6] - SetWindowPos() api function

    Quote Originally Posted by 8086 View Post
    hi

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,922

    Re: [VB6] - SetWindowPos() api function

    what make me strange is that i try copy from another simple project, but without sucess
    heres the project that i use for combine to my project...
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    Lively Member
    Join Date
    Mar 2010
    Posts
    123

    Re: [VB6] - SetWindowPos() api function

    SetWindowPos function is used to bring a window always up other.

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    3,671

    Re: [VB6] - SetWindowPos() api function

    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 ?

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,922

    Re: [VB6] - SetWindowPos() api function

    Quote Originally Posted by Edgemeal View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Other side of town from si_the_geek
    Posts
    7,171

    Re: [VB6] - SetWindowPos() api function

    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.

  9. #9

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    2,922

    Re: [VB6] - SetWindowPos() api function

    Quote Originally Posted by manavo11 View 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
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.