SetWindowPos (VB.NET)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig

    SetWindowPos (VB.NET)

    Hi,

    I'm attempting to use SetWindowPos to flip between a few apps and I've
    hit a problem. Whenever I use the following it doesn't seem to ignore
    the nomove and nosize flags and moves the app to the top left and makes
    it 0 x 0. Any suggestions please?

    Const SWP_NOSIZE As Short = &H1
    Const SWP_NOMOVE As Short = &H2
    Public 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

    SetWindowPos(iH andle, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
  • Arne Janning

    #2
    Re: SetWindowPos (VB.NET)

    Hi Craig!

    "Craig" schrieb[color=blue]
    > I'm attempting to use SetWindowPos to flip between a few apps and I've hit
    > a problem. Whenever I use the following it doesn't seem to ignore the
    > nomove and nosize flags and moves the app to the top left and makes it 0 x
    > 0. Any suggestions please?
    >
    > Const SWP_NOSIZE As Short = &H1
    > Const SWP_NOMOVE As Short = &H2
    > Public 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
    >
    > SetWindowPos(iH andle, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)[/color]

    First of all your Declaration of SetWindowPos is wrong seems to be an old
    VB6 one):

    use this:

    Imports System.Runtime. InteropServices

    Public Const SWP_NOSIZE As Int32 = &H1
    Public Const SWP_NOMOVE As Int32 = &H2

    <DllImport( _
    "user32.dll ", _
    CharSet:=CharSe t.Auto, _
    CallingConventi on:=CallingConv ention.StdCall _
    )> _
    Public Shared Function SetWindowPos( _
    ByVal hWnd As IntPtr, _
    ByVal hWndInsertAfter As IntPtr, _
    ByVal X As Int32, _
    ByVal Y As Int32, _
    ByVal cx As Int32, _
    ByVal cy As Int32, _
    ByVal uFlags As Int32) _
    As Boolean
    End Function


    To combine the SWP_NOSIZE and SWP_NOMOVE-Flags use the binary "Or"-Operator
    as shown in the example:

    Dim b As Boolean = _
    SetWindowPos( _
    Me.Handle, _
    New IntPtr(-1), _
    0, 0, 0, 0, _
    SWP_NOMOVE Or SWP_NOSIZE)

    Cheers

    Arne Janning


    Comment

    • Craig

      #3
      Re: SetWindowPos (VB.NET)

      Arne,

      Great it works, thanks for your help.



      Arne Janning wrote:[color=blue]
      > Hi Craig!
      >
      > "Craig" schrieb
      >[color=green]
      >>I'm attempting to use SetWindowPos to flip between a few apps and I've hit
      >>a problem. Whenever I use the following it doesn't seem to ignore the
      >>nomove and nosize flags and moves the app to the top left and makes it 0 x
      >>0. Any suggestions please?
      >>
      >>Const SWP_NOSIZE As Short = &H1
      >>Const SWP_NOMOVE As Short = &H2
      >>Public 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
      >>
      >>SetWindowPos( iHandle, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)[/color]
      >
      >
      > First of all your Declaration of SetWindowPos is wrong seems to be an old
      > VB6 one):
      >
      > use this:
      >
      > Imports System.Runtime. InteropServices
      >
      > Public Const SWP_NOSIZE As Int32 = &H1
      > Public Const SWP_NOMOVE As Int32 = &H2
      >
      > <DllImport( _
      > "user32.dll ", _
      > CharSet:=CharSe t.Auto, _
      > CallingConventi on:=CallingConv ention.StdCall _
      > )> _
      > Public Shared Function SetWindowPos( _
      > ByVal hWnd As IntPtr, _
      > ByVal hWndInsertAfter As IntPtr, _
      > ByVal X As Int32, _
      > ByVal Y As Int32, _
      > ByVal cx As Int32, _
      > ByVal cy As Int32, _
      > ByVal uFlags As Int32) _
      > As Boolean
      > End Function
      >
      >
      > To combine the SWP_NOSIZE and SWP_NOMOVE-Flags use the binary "Or"-Operator
      > as shown in the example:
      >
      > Dim b As Boolean = _
      > SetWindowPos( _
      > Me.Handle, _
      > New IntPtr(-1), _
      > 0, 0, 0, 0, _
      > SWP_NOMOVE Or SWP_NOSIZE)
      >
      > Cheers
      >
      > Arne Janning
      >
      >[/color]

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: SetWindowPos (VB.NET)

        "Arne Janning" <spam.me-here.iasyncresu lt@gmail.com> schrieb:[color=blue]
        > Imports System.Runtime. InteropServices
        >
        > Public Const SWP_NOSIZE As Int32 = &H1
        > Public Const SWP_NOMOVE As Int32 = &H2
        >
        > <DllImport( _
        > "user32.dll ", _
        > CharSet:=CharSe t.Auto, _
        > CallingConventi on:=CallingConv ention.StdCall _
        > )> _
        > Public Shared Function SetWindowPos( _
        > ByVal hWnd As IntPtr, _
        > ByVal hWndInsertAfter As IntPtr, _
        > ByVal X As Int32, _
        > ByVal Y As Int32, _
        > ByVal cx As Int32, _
        > ByVal cy As Int32, _
        > ByVal uFlags As Int32) _
        > As Boolean
        > End Function[/color]

        Mhm... No need for 'Charset.Auto'. I prefer this declaration in VB.NET:

        \\\
        Public Declare Function SetWindowPos Lib "user32.dll " ( _
        ByVal hWnd As IntPtr, _
        ByVal hWndInsertAfter As IntPtr, _
        ByVal X As Int32, _
        ByVal Y As Int32, _
        ByVal cx As Int32, _
        ByVal cy As Int32, _
        ByVal uFlags As Int32 _
        ) As Boolean
        ///
        [color=blue]
        > SetWindowPos( _
        > Me.Handle, _
        > New IntPtr(-1), _[/color]

        =>

        \\\
        Private ReadOnly HWND_TOPMOST As New IntPtr(-1)
        ..
        ..
        ..
        .... = SetWindowPos(Me .Handle, HWND_TOPMOST, ...)
        ///

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        Working...