Solved

SetParent and related API not working

Posted on 2004-09-04
3
1,032 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now