Solved

SetParent and related API not working

Posted on 2004-09-04
3
1,055 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_
  • 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 85

Accepted Solution

by:
Mike Tomlinson earned 75 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 62
VS.net 2010 11 36
export data table to excel in vb.net 10 26
Expression Evaluater 3 26
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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