[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SetParent and related API not working

Posted on 2004-09-04
3
Medium Priority
?
1,118 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 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