📄 bindview.cpp
字号:
else {
ErrMsg( hr,
L"Couldn't get the inf id of %s."
L" It will not be added to the list.",
lpszItemName );
}
CoTaskMemFree( lpszItemName );
}
else {
ErrMsg( hr,
L"Couldn't get the display name of a network component."
L" It will not be added to the list." );
}
return hTreeItem;
}
//
// Function: RefreshAll
//
// Purpose: Refreshes the main dialog box.
//
// Arguments:
// hwndDlg [in] Dialog box handle.
//
// Returns: None.
//
// Notes:
//
VOID RefreshAll (HWND hwndDlg)
{
HWND hwndTypeList;
INT iSelected;
//
// Find the selected network component type.
//
hwndTypeList = GetDlgItem( hwndDlg,
IDL_COMPONENT_TYPES );
iSelected = (int)SendMessage( hwndTypeList,
CB_GETCURSEL,
0,
0 );
if ( iSelected != CB_ERR ) {
//
// Before deleting the list in the tree, free the buffer
// associated with each item. The buffer holds either the
// INF Id or the pathtoken depending on whether it is a
// network component or a binding path.
//
ReleaseMemory( GetDlgItem(hwndDlg, IDT_BINDINGS),
TVI_ROOT );
TreeView_DeleteItem (
GetDlgItem(hwndDlg, IDT_BINDINGS),
TVI_ROOT );
//
// Repopulate the tree with the selected network compnent
// type.
//
EnumNetBindings( GetDlgItem(hwndDlg, IDT_BINDINGS),
(UINT)iSelected );
}
return;
}
//
// Function: RefreshItemState
//
// Purpose: Refreshes the specified item.
//
// Arguments:
// hwndTree [in] Dialog box handle.
// hItem [in] Item to refresh.
// fEnable [in] TRUE if component is enabled.
//
// Returns: None.
//
// Notes:
//
VOID RefreshItemState (HWND hwndTree,
HTREEITEM hItem,
BOOL fEnable)
{
TVITEMW tvItem;
ZeroMemory( &tvItem,
sizeof(TVITEMW) );
tvItem.hItem = hItem;
tvItem.mask = TVIF_STATE;
tvItem.stateMask = TVIS_OVERLAYMASK;
if ( fEnable )
tvItem.state = INDEXTOOVERLAYMASK( 0 );
else
tvItem.state = INDEXTOOVERLAYMASK(
IDI_DISABLED_OVL - IDI_CLASSICON_OVERLAYFIRST + 1);
TreeView_SetItem( hwndTree,
&tvItem );
return;
}
//
// Function: RefreshBindings
//
// Purpose: Refreshes bindings of a specific component.
//
// Arguments:
// hwndBindUnBindDlg [in] Dialog box handle.
// lpszInfId [in] PnpID of the component whose bindings changed.
//
// Returns: None.
//
// Notes:
//
VOID RefreshBindings (HWND hwndBindUnBindDlg,
LPWSTR lpszInfId)
{
INetCfg *pnc;
INetCfgComponent *pncc;
HWND hwndParent;
HWND hwndTree;
HTREEITEM hItem;
HRESULT hr;
hwndParent = GetParent( hwndBindUnBindDlg );
hwndTree = GetDlgItem( hwndParent,
IDT_BINDINGS );
hItem = TreeView_GetSelection( hwndTree );
hr = HrGetINetCfg( FALSE,
APP_NAME,
&pnc,
NULL );
if ( hr == S_OK ) {
hr = pnc->FindComponent( lpszInfId,
&pncc );
if ( hr == S_OK ) {
//
// Delete all the children.
//
ReleaseMemory( hwndTree,
hItem );
DeleteChildren( hwndTree,
hItem );
ListBindings( pncc,
hwndTree,
hItem );
ReleaseRef( pncc );
}
HrReleaseINetCfg( pnc,
FALSE );
}
return;
}
//
// Function: ReleaseMemory
//
// Purpose: Free memory associated with each item in the tree.
//
// Arguments:
// hwndTree [in] Tree handle.
// hTreeItem [in] Root item.
//
// Returns: None.
//
// Notes:
//
// Each node of the tree represents a network component or a binding path.
// At each node, lParam points to an allocated buffer wherein we store the
// inf id if it is a network component or pathtoken name if it is a binding
// path.
//
//
VOID ReleaseMemory (HWND hwndTree,
HTREEITEM hTreeItem)
{
HTREEITEM hItemChild;
TVITEMW tvItem;
hItemChild = TreeView_GetChild( hwndTree,
hTreeItem );
while ( hItemChild ) {
ZeroMemory(
&tvItem,
sizeof(TVITEMW) );
tvItem.hItem = hItemChild;
tvItem.mask = TVIF_PARAM;
TreeView_GetItem( hwndTree,
&tvItem );
//
// It should never be NULL but just in case...
//
if ( tvItem.lParam ) {
CoTaskMemFree( (LPVOID)tvItem.lParam );
}
ReleaseMemory( hwndTree, hItemChild );
hItemChild = TreeView_GetNextSibling( hwndTree,
hItemChild );
}
return;
}
//
// Function: DeleteChildren
//
// Purpose: Delete childen of a specific item.
//
// Arguments:
// hwndTree [in] Tree handle.
// hTreeItem [in] Parent item.
//
// Returns: None.
//
// Notes:
//
VOID DeleteChildren (HWND hwndTree,
HTREEITEM hTreeItem)
{
HTREEITEM hItemChild;
HTREEITEM hItemSibling;
hItemChild = TreeView_GetChild( hwndTree,
hTreeItem );
while ( hItemChild ) {
DeleteChildren( hwndTree,
hItemChild );
hItemSibling = TreeView_GetNextSibling( hwndTree,
hItemChild );
TreeView_DeleteItem( hwndTree,
hItemChild );
hItemChild = hItemSibling;
}
return;
}
//
// Function: InsertItem
//
// Purpose: Insert text for each network component type.
//
// Arguments:
// hwndTree [in] Tree handle.
// uiType [in] Item type, protocol, client, service.
//
// Returns: Item handle on success, otherwise NULL.
//
// Notes:
//
HTREEITEM InsertItem (HWND hwndTree,
UINT uiType)
{
TV_INSERTSTRUCTW tvInsertStruc;
ZeroMemory(
&tvInsertStruc,
sizeof(TV_INSERTSTRUCTW) );
tvInsertStruc.hParent = TVI_ROOT;
tvInsertStruc.hInsertAfter = TVI_LAST;
tvInsertStruc.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE |
TVIF_SELECTEDIMAGE;
switch( uiType ) {
case CLIENTS_SELECTED:
tvInsertStruc.item.pszText = L"Client";
break;
case SERVICES_SELECTED:
tvInsertStruc.item.pszText = L"Service";
break;
default:
tvInsertStruc.item.pszText = L"Protocol";
break;
}
SetupDiGetClassImageIndex( &ClassImageListData,
pguidNetClass[uiType],
&tvInsertStruc.item.iImage );
tvInsertStruc.item.iSelectedImage = tvInsertStruc.item.iImage;
tvInsertStruc.item.lParam = (LPARAM)uiType;
return TreeView_InsertItem( hwndTree,
&tvInsertStruc );
}
//
// Function: UpdateComponentTypeList
//
// Purpose: Insert text for each network component type.
//
// Arguments:
// hwndTypeList [in] ListView handle.
//
// Returns: TRUE on success.
//
// Notes:
//
BOOL UpdateComponentTypeList (HWND hwndTypeList)
{
UINT i;
for (i=0; i < 3; ++i) {
SendMessage( hwndTypeList,
CB_ADDSTRING,
(WPARAM)0,
(LPARAM)lpszNetClass[i] );
}
SendMessage( hwndTypeList,
CB_SETCURSEL,
(WPARAM)DEFAULT_COMPONENT_SELECTED,
(LPARAM)0 );
return TRUE;
}
//
// Function: ErrMsg
//
// Purpose: Insert text for each network component type.
//
// Arguments:
// hr [in] Error code.
//
// Returns: None.
//
// Notes:
//
VOID ErrMsg (HRESULT hr,
LPCWSTR lpFmt,
...)
{
LPWSTR lpSysMsg;
WCHAR buf[400];
ULONG offset;
va_list vArgList;
if ( hr != 0 ) {
swprintf( buf,
L"Error %#lx: ",
hr );
}
else {
buf[0] = 0;
}
offset = wcslen( buf );
va_start( vArgList,
lpFmt );
vswprintf( buf+offset,
lpFmt,
vArgList );
va_end( vArgList );
if ( hr != 0 ) {
FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
hr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&lpSysMsg,
0,
NULL );
if ( lpSysMsg ) {
offset = wcslen( buf );
swprintf( buf+offset,
L"\n\nPossible cause:\n\n" );
offset = wcslen( buf );
wcscat( buf+offset,
lpSysMsg );
LocalFree( (HLOCAL)lpSysMsg );
}
MessageBoxW( NULL,
buf,
L"Error",
MB_ICONERROR | MB_OK );
}
else {
MessageBoxW( NULL,
buf,
L"BindView",
MB_ICONINFORMATION | MB_OK );
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -