📄 bindview.cpp
字号:
//
// Before deleting the list in the tree, free the buffer
// associated with each item. The buffer holds the
// INF Id of network components.
//
ReleaseMemory( GetDlgItem(hwndDlg, IDT_COMPONENT_LIST),
TVI_ROOT );
EndDialog( hwndDlg, 0 );
}
else {
//
// User wants to bind/unbind.
//
if ( (LOWORD(wParam) == IDB_BIND_UNBIND) &&
(HIWORD(wParam) == BN_CLICKED) ) {
lpBindUnbind = (LPBIND_UNBIND_INFO)GetWindowLongPtr( hwndDlg,
DWLP_USER );
if ( BindUnbind(lpBindUnbind->lpszInfId,
GetDlgItem(hwndDlg, IDT_COMPONENT_LIST),
lpBindUnbind->fBindTo) ) {
RefreshBindings( hwndDlg,
lpBindUnbind->lpszInfId );
}
ReleaseMemory( GetDlgItem(hwndDlg, IDT_COMPONENT_LIST),
TVI_ROOT );
EndDialog( hwndDlg, 0 );
}
}
break;
case WM_SYSCOMMAND:
if ( (0xFFF0 & wParam) == SC_CLOSE ) {
//
// Before deleting the list in the tree, free the buffer
// associated with each item. The buffer holds the
// INF Id of network components.
//
ReleaseMemory( GetDlgItem(hwndDlg, IDT_COMPONENT_LIST),
TVI_ROOT );
EndDialog( hwndDlg, 0 );
}
}
return FALSE;
}
//
//WndProc of the dialog box for installing network components.
//
INT_PTR CALLBACK InstallDlg (HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
{
HWND hwndTree;
//
// List types of network components e.g. client,
// protocol and service.
//
hwndTree = GetDlgItem( hwndDlg,
IDT_COMPONENT_LIST );
TreeView_SetImageList( hwndTree,
ClassImageListData.ImageList,
LVSIL_NORMAL );
//
// Insert and select client by default.
//
TreeView_Select( hwndTree,
InsertItem(hwndTree,
CLIENTS_SELECTED),
TVGN_CARET );
InsertItem( hwndTree,
SERVICES_SELECTED );
InsertItem( hwndTree,
PROTOCOLS_SELECTED );
//
// Initialize it to FALSE. It will be set to TRUE when
// at least one component is installed.
//
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)FALSE );
return TRUE;
}
case WM_COMMAND:
switch( LOWORD(wParam) ) {
case IDB_INSTALL:
//
// Install from Windows system directory.
//
if ( HIWORD(wParam) == BN_CLICKED ) {
InstallSelectedComponentType( hwndDlg, NULL );
}
break;
case IDB_BROWSE:
//
// User wants to specify an INF file for the network
// to install.
//
if ( HIWORD(wParam) == BN_CLICKED ) {
WCHAR lpszInfFile[MAX_PATH+1];
if ( GetFileName(hwndDlg,
L"INF files (*.inf)\0*.inf\0",
L"Select the INF file of the network component to install",
OFN_DONTADDTORECENT | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST,
lpszInfFile,
NULL,
FALSE) ) {
InstallSelectedComponentType( hwndDlg,
lpszInfFile );
}
}
break;
case IDB_CLOSE:
if ( HIWORD(wParam) == BN_CLICKED ) {
//
// Return the value of DWLP_USER to indicate whether one or
// more components have been installed. Accordingly, the
// the list will be refreshed.
//
EndDialog( hwndDlg,
GetWindowLongPtr(hwndDlg, DWLP_USER) );
}
}
break;
case WM_NOTIFY:
{
LPNMHDR lpnm;
lpnm = (LPNMHDR)lParam;
if ( (lpnm->idFrom == IDT_COMPONENT_LIST) &&
(lpnm->code == NM_DBLCLK) ) {
//
// On double-click, install from Windows system directory.
//
InstallSelectedComponentType( hwndDlg, NULL );
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
}
break;
case WM_SYSCOMMAND:
if ( (0xFFF0 & wParam) == SC_CLOSE ) {
//
// Return the value of DWLP_USER to indicate whether one or
// more components have been installed. Accordingly, the
// the list will be refreshed.
//
EndDialog( hwndDlg,
GetWindowLongPtr(hwndDlg, DWLP_USER) );
}
}
return FALSE;
}
//
// WndProc of the dialog box for uninstalling a network component.
//
INT_PTR CALLBACK UninstallDlg (HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
HWND hwndTree;
switch (uMsg) {
case WM_INITDIALOG:
hwndTree = GetDlgItem( hwndDlg,
IDT_COMPONENT_LIST );
TreeView_SetImageList( hwndTree,
ClassImageListData.ImageList,
LVSIL_NORMAL );
//
// List all the compoents currently installed.
//
ListInstalledComponents( hwndTree,
&GUID_DEVCLASS_NETCLIENT);
ListInstalledComponents( hwndTree,
&GUID_DEVCLASS_NETSERVICE );
ListInstalledComponents( hwndTree,
&GUID_DEVCLASS_NETTRANS );
//
// Initialize it to FALSE. It will be set to TRUE when
// at least one component is installed.
//
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)FALSE );
return TRUE;
case WM_COMMAND:
switch( LOWORD(wParam) ) {
case IDB_REMOVE:
if ( HIWORD(wParam) == BN_CLICKED ) {
//
// Uninstall the selected component.
//
UninstallSelectedComponent( hwndDlg );
}
break;
case IDB_CLOSE:
if ( HIWORD(wParam) == BN_CLICKED ) {
hwndTree = GetDlgItem( hwndDlg,
IDT_COMPONENT_LIST );
ReleaseMemory( hwndTree,
TVI_ROOT );
//
// Return the value of DWLP_USER to indicate whether one or
// more components have been installed. Accordingly, the
// the list will be refreshed.
//
EndDialog( hwndDlg,
GetWindowLongPtr(hwndDlg, DWLP_USER) );
}
}
break;
case WM_NOTIFY:
{
LPNMHDR lpnm;
lpnm = (LPNMHDR)lParam;
if ( (lpnm->idFrom == IDT_COMPONENT_LIST) &&
(lpnm->code == NM_DBLCLK) ) {
UninstallSelectedComponent( hwndDlg );
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE);
return TRUE;
}
}
break;
case WM_SYSCOMMAND:
if ( (0xFFF0 & wParam) == SC_CLOSE ) {
hwndTree = GetDlgItem( hwndDlg,
IDT_COMPONENT_LIST );
ReleaseMemory( hwndTree,
TVI_ROOT );
//
// Return the value of DWLP_USER to indicate whether one or
// more components have been installed. Accordingly, the
// the list will be refreshed.
//
EndDialog( hwndDlg,
GetWindowLongPtr(hwndDlg, DWLP_USER) );
}
}
return FALSE;
}
//+---------------------------------------------------------------------------
//
// Function: DumpBindings
//
// Purpose: Write the binding information.
//
// Arguments:
// lpszFile [in] Name of the file in which to write.
//
// Returns: None
//
// Notes:
//
VOID DumpBindings (LPWSTR lpszFile)
{
FILE *fp;
fp = _wfopen( lpszFile,
L"w" );
if ( fp == NULL ) {
ErrMsg( 0,
L"Unable to open %s.",
lpszFile );
}
else {
WriteBindings( fp );
fclose( fp );
}
return;
}
//
// Function: InstallSelectedComponentType
//
// Purpose: Install a network component.
//
// Arguments:
// hwndDlg [in] Handle to Install dialog box.
// lpszInfFile [in] Inf file of the network component.
//
// Returns: None
//
// Notes:
// If lpszInfFile is NULL, network components are installed from the
// system directory.
//
VOID InstallSelectedComponentType (HWND hwndDlg,
LPWSTR lpszInfFile)
{
HWND hwndTree;
HTREEITEM hItem;
LPARAM lParam;
HCURSOR hPrevCursor;
HCURSOR hWaitCursor;
HWND hwndFocus;
DWORD dwType;
BOOL fEnable;
HRESULT hr;
hwndTree = GetDlgItem( hwndDlg,
IDT_COMPONENT_LIST );
//
// Find out the type of component selected.
//
hItem = TreeView_GetSelection( hwndTree );
if ( hItem ) {
if ( GetItemInfo( hwndTree,
hItem,
&lParam,
&dwType,
&fEnable) ) {
//
// Disable the install dialog controls.
//
hwndFocus = GetFocus();
hWaitCursor = LoadCursor( NULL,
IDC_WAIT );
if ( hWaitCursor ) {
hPrevCursor = SetCursor( hWaitCursor );
}
EnableWindow( hwndTree, FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDB_INSTALL),
FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDB_BROWSE),
FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE),
FALSE );
if ( lpszInfFile ) {
LPWSTR lpszPnpID;
//
// Inf file name specified, install the network component
// from this file.
//
hr = GetPnpID( lpszInfFile, &lpszPnpID );
if ( hr == S_OK ) {
hr = InstallSpecifiedComponent( lpszInfFile,
lpszPnpID,
pguidNetClass[(UINT)lParam] );
CoTaskMemFree( lpszPnpID );
}
else {
ErrMsg( hr,
L"Error reading the INF file %s.",
lpszInfFile );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -