TOC

 INTERMEDIATE  Ask the VB Pro


Add a Window to the Taskbar

by Karl E. Peterson

   
Q. Force a Dialog Into the Taskbar
I spend a lot of time with the Windows NT Services control panel applet running, and one thing about it has always bugged me: It doesn't display as a button in the taskbar, so I have to minimize all running apps one at a time in order to uncover it. Is there some way for me to tweak this dialog so it's easier to find?
ABOUT THIS COLUMN
Ask the VB Pro provides you with free advice on programming obstacles, techniques, and ideas. Read more answers from our crack VB pros. You can submit your questions, tips, or ideas on the site, or access a comprehensive database of previously answered questions.

A. I've heard of utilities for download that force any window to be "always on top." Something like that is fairly easy to code up, and it would certainly ensure you could find the dialog. However, it's a less-than-optimal solution for this problem.

You alluded to the best solution when you mentioned the missing taskbar button. The criteria Windows applies when deciding whether to display a task on the taskbar are barely documented. To add a window to the taskbar, make sure the WS_EX_TOOLWINDOW extended style is not set and the WS_EX_APPWINDOW extended style is set. You also need to toggle the window's visibility in order for the taskbar to notice this change in styles.

My preferred solution: Create a launcher utility. The utility tests to see that it's executing in the desired operating system—in this case, NT4, because Windows 9x doesn't have a Services applet and Windows 2000 uses the management console for this task. Next, the utility spawns the Services applet using the appropriate Shell command and begins looking for the target window using FindWindow. When it finds the dialog, the bit flipping can begin (see Listing 1).

If you want to remove a window from the taskbar, alter the style bits while the window is invisible.


Q. Toggle ShowInTaskbar at Run Time
In the process of making a window appear in the taskbar, why did Microsoft make the ShowInTaskbar property read-only at run time?

A. Good question. ShowInTaskbar is another property that's ideally suited for addition to the CFormBorder class, which sets many normally untouchable properties at run time (see the November 2000 Ask the VB Pro column). The Property Let/Get pair simply locks the window from update to prevent flicker, hides the window, toggles the WS_EX_APPWINDOW extended style bit, then shows and unlocks the window (see Listing 2). Use the class from your form like this:

' Border handler class
Private m_bdr As CFormBorder

Private Sub Check1_Click()
   ' Toggle replacement property
   m_bdr.ShowInTaskbar = _ 
      CBool(Check1.Value)
End Sub

Private Sub Form_Load()
   ' Set up replacement properties
   Set m_bdr = New CFormBorder
   Set m_bdr.Client = Me
End Sub


Q. Obtain the Domain Controller Name
I've been looking at some of the new functions that come built into Windows 2000, and I found one I'd like to use. The DsGetDcName API looks extremely useful, but no matter what I try, I can't make sense of the pointer returned in DomainControllerInfo, the last parameter.

A. The SDK docs appear to be less than clear in this case. That parameter is documented as a "Pointer to a variable that receives a pointer to a structure... ." However, it appears that DomainControllerInfo is a pointer to a buffer that contains the data.

Given that clue, you can declare a DOMAIN_CONTROLLER_INFO consisting entirely of Longs and a GUID, and use CopyMemory to sling the API-provided bits into your local structure. You still need to dereference the strings so you can declare a more VB-friendly structure and use it as the destination for the recovered strings. Finally, you need to free the API-allocated buffer with a call to NetApiBufferFree (see Listing 3).

For more information on dereferencing API pointers, see the detailed techniques examined in the November 1999 Ask the VB Pro column. In the future, I'll discuss how I determined the SDK docs were misleading and how you can expand on this lesson to solve your own memory-based mysteries.




Karl E. Peterson is a GIS analyst with a regional transportation planning agency and serves as a member of the VBPJ Technical Review and Editorial Advisory Boards. Online, he's a Microsoft MVP and a section leader on several VBPJ forums. Find more of Karl's VB samples at www.mvps.org/vb.

 
  Get the code for this article here.

Updated samples based on this article:
FormBdr
NetDomain

 


• Ask the VB Pro, "Toggle the Titlebar [and Other Form Tricks]," by Karl E. Peterson [VBPJ November 2000]
• Ask the VB Pro, "Who Says VB Can't Use Pointers?" by Karl E. Peterson [VBPJ November 1999]
Handling the Taskbar, MSDN
Shelling Control Panel Applets and System Wizards
Microsoft Knowledge Base article Q247811