?
Solved

SetParent and related API not working

Posted on 2004-09-04
3
Medium Priority
?
1,098 Views
Last Modified: 2012-05-05
This used to be easy stuff back in my VB6 days.. Setting forms as a child of the desktop or whatever I wanted, but I can't get it to work in VB.NET.

Basically, I want to set Winamp as a child of the desktop window (when I press the Show Desktop button, Winamp and whatever else is a child of the desktop won't hide). Using Spy++, I've determined that Winamp's caption is "Main window" and its class is "BaseWindow_RootWnd".

At this point, I can't even set my own forms as a child of the desktop.. I'm using the following code (just testing, that's why it's ugly):

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim blah As Long = FindWindow("Progman", vbNullString)
        SetParent(Me.Handle.ToInt32, blah)
    End Sub
0
Comment
Question by:todd_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:todd_
ID: 11982994
The following function (that I've found in reference to VB6) doesn't work in VB.NET either:

    Public Function ArrangeDesktopIcons() As Boolean
        Dim hWnd As Long
        Dim RetVal As Long
        'Find the desktop handle
        hWnd = FindWindow("Progman", vbNullString)
        'Find the first child to the desktop
        hWnd = GetWindow(hWnd, 5)
        'Find the first child of the first child of the desktop
        hWnd = GetWindow(hWnd, 5)
        'Arrange the icons
        RetVal = SendMessage(hWnd, LVM_ARRANGE, LVA_ALIGNLEFT, 0)
        ArrangeDesktopIcons = RetVal > 0
    End Function

It should arrange desktop items (assuming I have all the API functions already declared) but doesn't in VB.NET.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 300 total points
ID: 11984147
The first problem I see is that you are using old VB6 API declarations.

In general, you need to change anything declared as Long to Integer.  Don't forget to change local variables that receive return values to Integer as well.

For instance, FindWindow() was this:

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long

and it becomes this:

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Integer

Regards,

Idle_Mind
0
 

Author Comment

by:todd_
ID: 11986618
Thanks a lot!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question