Solved

SetParent and related API not working

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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