By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

SetWindowPos (VB.NET)

P: n/a
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(iHandle, -1, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Craig!

"Craig" schrieb
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)


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:=CharSet.Auto, _
CallingConvention:=CallingConvention.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
Nov 21 '05 #2

P: n/a
Arne,

Great it works, thanks for your help.

Arne Janning wrote:
Hi Craig!

"Craig" schrieb
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)

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:=CharSet.Auto, _
CallingConvention:=CallingConvention.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

Nov 21 '05 #3

P: n/a
"Arne Janning" <sp***********************@gmail.com> schrieb:
Imports System.Runtime.InteropServices

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

<DllImport( _
"user32.dll", _
CharSet:=CharSet.Auto, _
CallingConvention:=CallingConvention.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
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
///
SetWindowPos( _
Me.Handle, _
New IntPtr(-1), _


=>

\\\
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/>
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.