Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2007

Tip: Looking for answers? Try searching our database.

SetWindowPlacement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zamdrist - 28 Dec 2007 20:41 GMT
For the life of me I cannot get this API function to work as expected
in VB.Net

I am however using SetWindowPos, and so long as the window is not
minimized, it will position as I tell it to. If the window is
minimized SetWindowPos will not move the window, and
SetWindowPlacement does not appear to have any effect on changing the
state of the window from Minimized to any other state, such as normal,
maximized or otherwise.

I've tried code, and combination of code from a number of sources,
including MSDN, pinvoke.net, and vbnet.mvps.org, all with no luck.

Now keep in mind that I'm not concerned about 64 bit systems, so a
data type of Long should be fine. I've tried various versions of this
function, including the <DLLImport...> version, as well as having the
function return a Boolean value rather than a Long. This function
appears to have zero effect. Also note that I do have the proper
constructs in place, i.e. WindowPlacement, PointAPI & Rect.

Interestingly enough I have been able to get the IsIconic function
working, and it *will* return correctly the state of the application
window (minimized or no).

Here's the code for what its worth...although this variation and its
forms are all over the net...any thoughts, advice or ideas would be
greatly appreciated. Thanks.

Public Declare Function SetWindowPlacement Lib "user32" _
(ByVal hwnd As Long, _
ByRef lpwndpl As WINDOWPLACEMENT) _
As Long

Private Sub (Blah, Blah)

Dim lhWnd As Long = lvWindows.SelectedItems(0).SubItems(1).Text
Dim currWinp As WINDOWPLACEMENT

currWinp.Length = Len(currWinp)
currWinp.flags = 0&
currWinp.showCmd = SW_SHOWNORMAL

SetWindowPos(lhWnd, 0, 0, 0, SWP_NOSIZE)
SetWindowPlacement(lhWnd, currWinp)

End Sub

       'RestoreWindow(lhWnd)

   End Sub
Duncan Jones - 28 Dec 2007 21:21 GMT
"Long" in VB5/6 was 32 bits - but in .NET it is 64 bits. [
http://msdn2.microsoft.com/en-us/library/y595sc15.aspx ]
However a HWND is still 32 bits - so the data type Int32 or better still
IntPtr should be used in its stead.
[
http://msdn2.microsoft.com/en-us/library/system.intptr_members(VS.71).aspx ]

Hope this help,
 Duncan

> For the life of me I cannot get this API function to work as expected
> in VB.Net
[quoted text clipped - 46 lines]
>
>    End Sub
Zamdrist - 28 Dec 2007 21:37 GMT
Thank you Duncan. Use of IntPtr I understand will ensure my
application is compatible with 64-bit systems, and while I understand
that is good form, its not a concern of mine as I am developing for a
controlled environment of Windows XP clients using 32-bit Intel
processors.

Nevertheless, I removed all of my non working code, and started from
scratch, using the code found here:

http://www.dotnetspider.com/kb/Article3505.aspx

Interesting enough, it casts the hWnd value as an Integer. It appears
to work nevertheless, or even as a Long. I haven't figured out a way
to convert a value to IntPtr in any event, even if I wanted to.

So the code from the above mentioned article works very much as is and
I'm looking for a compelling reason to monkey with it more or just let
it be. Again, I'm not the least bit concerned this program would ever
be ran on anything but a 32-bit system. Its distributed within a
controlled environment.

Thanks

> "Long" in VB5/6 was 32 bits - but in .NET it is 64 bits. [http://msdn2.microsoft.com/en-us/library/y595sc15.aspx]
> However a HWND is still 32 bits - so the data type Int32 or better still
[quoted text clipped - 3 lines]
> Hope this help,
>   Duncan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.