Results 1 to 9 of 9

Thread: SetParent problem [resolved]

  1. #1

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    SetParent problem [resolved]

    Hello everyone.

    I'm working on a windows extension that adds a "Minimize to tray" button to each window. I got everything to work but there's one problem remaining:

    For the button I use a UserControl because of several reasons. However I found out when using SetParent( handle, 0 ) a tab in the taskbar appears. Try it by creating a new project, adding a PictureBox and using SetParent with 0 as parent handle.

    Now the question is how can I avoid this taskbar tab? Thanks for hints,

    Fox
    Last edited by Fox; Dec 1st, 2004 at 08:49 AM.

  2. #2
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    You could use the SetParent as you are, then SetWindowAttributes (I think that's the right API) and tell the object not to display in the task bar.
    "I don't want to live alone until I'm married" - M.M.R.P

  3. #3

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yes I already tried this but it doesn't work. The code to hide the taskbar button works on other windows but not on the one I changed the parent to 0...

  4. #4
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    have you tried setting the desktop winodw as the parent?
    "I don't want to live alone until I'm married" - M.M.R.P

  5. #5

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Yes, this also creates one more tab in the taskbar...

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,287
    Apply the WS_EX_TOOLWINDOW extended style to your window. This will trick windows into thinking it's a tool window, and thus remove it from the task bar.

    Here's a quick example
    VB Code:
    1. Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    2. Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    3. Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
    4. Private Const GWL_EXSTYLE = -20
    5. Private Const WS_EX_TOOLWINDOW As Long = &H80&
    6.  
    7. Private Sub Command1_Click()
    8.        
    9.     ' make the picturebox a top-level parent window
    10.    
    11.     Dim lstyle As Long
    12.    
    13.     'apply the tool window extended style
    14.     lstyle = GetWindowLong(Picture1.hwnd, GWL_EXSTYLE)
    15.     lstyle = lstyle Or WS_EX_TOOLWINDOW
    16.     SetWindowLong Picture1.hwnd, GWL_EXSTYLE, lstyle
    17.    
    18.     SetParent Picture1.hwnd, 0
    19.    
    20. End Sub
    21.  
    22. Private Sub Picture1_Click()
    23.     'close the form
    24.     Unload Me
    25. End Sub

  7. #7

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Thanks alot, that works

  8. #8
    Hyperactive Member Disiance's Avatar
    Join Date
    Sep 2004
    Location
    Denver, CO
    Posts
    439
    When you finish this program Fox could you please post it for download? This type of project has been on the back of my mind for months now but I adhore subclassing.
    "I don't want to live alone until I'm married" - M.M.R.P

  9. #9

    Thread Starter
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Of course. It's not just a minimize to tray, it's a whole windows manager suite (thus called "WinMan"). You can show/hide/rename/set alpha/whatever on each window. Also you can apply bots to automate those actions (eg. "Set ICQ's alpha to 20% when it's running").

    This is the 2nd edition btw, the original code was written in 2001 - even it's crappy coded ever since, it's one of the most-used tools I got.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width