Sunday, August 19, 2007

Toggle ShowInTaskbar at Run Time

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. 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.

No comments: