[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

SetParent Usercontrol

I am trying to make a usercontrol that will go on the desktop, via the "SetParent" API call.

However, there is one minor problem.  Here is the slimmed down code:

(project with a usercontrol)

In the usercontrol there is this:

Private Declare Function WindowFromDC Lib "user32" (ByVal hdc As Long) As Long


Public Function hWnd() as long
    hWnd = WindowFromDC usercontrol.hDC
End Function



Now, in a form with UserControl1 (and a command button), there is this:

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Sub Command1_Click()
    SetParent UserControl1.hWnd, GetDesktopWindow
End Sub



This works fine, UserControl1 goes onto the desktop.  However, it adds a button to the taskbar.  How can I stop it from putting this button there?

-Sam
0
samsonite1023
Asked:
samsonite1023
  • 2
1 Solution
 
TigerZhaoCommented:
Form1.ShowInTaskbar = False
0
 
Roshan DavisCommented:
Make the window to Tool Window

Here is the code

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long


SetWindowLong(UserControl1.hWnd, -20, 128);
SetParent UserControl1.hWnd, GetDesktopWindow
0
 
Roshan DavisCommented:
That is here I'm changing the control's extented style to WS_EX_TOOLWINDOW.
Here I tested also.. And works fine

Good Luck
0
 
samsonite1023Author Commented:
Thanks!  Man, I tried using the SetWindowLong stuff, and it didn't work for me.  I guess I was using the wrong constants.

Your code works fine, though.

Thanks a ton!

-Sam
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now