📄 bindview.cpp
字号:
else {
//
// Install from system directory.
//
hr = InstallComponent( hwndTree,
pguidNetClass[(UINT)lParam] );
}
if ( hWaitCursor ) {
SetCursor( hPrevCursor );
}
switch( hr ) {
case S_OK:
MessageBoxW(
hwndDlg,
L"Component installed successfully.",
L"Network Component Installation",
MB_OK | MB_ICONINFORMATION );
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)TRUE );
break;
case NETCFG_S_REBOOT:
MessageBoxW(
hwndDlg,
L"Component installed successfully: "
L"Reboot required.",
L"Network Component Installation",
MB_OK | MB_ICONINFORMATION );
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)TRUE );
}
//
// Enable the install dialog controls.
//
EnableWindow( hwndTree, TRUE );
EnableWindow( GetDlgItem(hwndDlg,IDB_INSTALL),
TRUE );
EnableWindow( GetDlgItem(hwndDlg,IDB_BROWSE),
TRUE );
EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE),
TRUE );
SetFocus( hwndFocus );
}
}
return;
}
//
// Function: GetPnpID
//
// Purpose: Retrieve PnpID from an inf file.
//
// Arguments:
// lpszInfFile [in] Inf file to search.
// lppszPnpID [out] PnpID found.
//
// Returns: TRUE on success.
//
// Notes:
//
HRESULT GetPnpID (LPWSTR lpszInfFile,
LPWSTR *lppszPnpID)
{
HINF hInf;
LPWSTR lpszModelSection;
HRESULT hr;
*lppszPnpID = NULL;
hInf = SetupOpenInfFileW( lpszInfFile,
NULL,
INF_STYLE_WIN4,
NULL );
if ( hInf == INVALID_HANDLE_VALUE )
{
return HRESULT_FROM_WIN32(GetLastError());
}
//
// Read the Model section name from Manufacturer section.
//
hr = GetKeyValue( hInf,
L"Manufacturer",
NULL,
1,
&lpszModelSection );
if ( hr == S_OK )
{
//
// Read PnpID from the Model section.
//
hr = GetKeyValue( hInf,
lpszModelSection,
NULL,
2,
lppszPnpID );
CoTaskMemFree( lpszModelSection );
}
SetupCloseInfFile( hInf );
return hr;
}
//
// Function: GetKeyValue
//
// Purpose: Retrieve the value of a key from the inf file.
//
// Arguments:
// hInf [in] Inf file handle.
// lpszSection [in] Section name.
// lpszKey [in] Key name.
// dwIndex [in] Key index.
// lppszValue [out] Key value.
//
// Returns: S_OK on success, otherwise and error code.
//
// Notes:
//
HRESULT GetKeyValue (HINF hInf,
LPCWSTR lpszSection,
LPCWSTR lpszKey,
DWORD dwIndex,
LPWSTR *lppszValue)
{
INFCONTEXT infCtx;
DWORD dwSizeNeeded;
HRESULT hr;
*lppszValue = NULL;
if ( SetupFindFirstLineW(hInf,
lpszSection,
lpszKey,
&infCtx) == FALSE )
{
return HRESULT_FROM_WIN32(GetLastError());
}
SetupGetStringFieldW( &infCtx,
dwIndex,
NULL,
0,
&dwSizeNeeded );
*lppszValue = (LPWSTR)CoTaskMemAlloc( sizeof(WCHAR) * dwSizeNeeded );
if ( !*lppszValue )
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
if ( SetupGetStringFieldW(&infCtx,
dwIndex,
*lppszValue,
dwSizeNeeded,
NULL) == FALSE )
{
hr = HRESULT_FROM_WIN32(GetLastError());
CoTaskMemFree( *lppszValue );
*lppszValue = NULL;
}
else
{
hr = S_OK;
}
return hr;
}
//
// Function: UninstallSelectedComponent
//
// Purpose: Uninstall the selected network component.
//
// Arguments:
// hwndDlg [in] Window handle of the uninstall dialog box.
//
// Returns: TRUE on success.
//
// Notes:
//
VOID UninstallSelectedComponent (HWND hwndDlg)
{
HWND hwndTree;
HTREEITEM hItem;
LPARAM lParam;
HCURSOR hPrevCursor;
HCURSOR hWaitCursor;
DWORD dwType;
BOOL fEnable;
HRESULT hr;
hwndTree = GetDlgItem( hwndDlg,
IDT_COMPONENT_LIST );
//
// Get the selected item to get its lParam which is the
// PnpID of the network component.
//
hItem = TreeView_GetSelection( hwndTree );
if ( hItem ) {
if ( GetItemInfo( hwndTree,
hItem,
&lParam,
&dwType,
&fEnable) ) {
hWaitCursor = LoadCursor( NULL,
IDC_WAIT );
if ( hWaitCursor ) {
hPrevCursor = SetCursor( hWaitCursor );
}
EnableWindow( hwndTree, FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDB_REMOVE),
FALSE );
EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE),
FALSE );
//
// Uninstall the selected component.
//
hr = UninstallComponent( (LPWSTR)lParam );
if ( hWaitCursor ) {
SetCursor( hPrevCursor );
}
switch( hr ) {
case S_OK:
MessageBoxW(
hwndDlg,
L"Uninstallation successful.",
L"Network Component Uninstallation",
MB_OK | MB_ICONINFORMATION );
CoTaskMemFree( (LPVOID)lParam );
TreeView_DeleteItem( hwndTree,
hItem );
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)TRUE );
break;
case NETCFG_S_REBOOT:
MessageBoxW(
hwndDlg,
L"Uninstallation successful: "
L"Reboot required.",
L"Network Component Uninstallation",
MB_OK | MB_ICONINFORMATION );
CoTaskMemFree( (LPVOID)lParam );
TreeView_DeleteItem( hwndTree,
hItem );
SetWindowLongPtr( hwndDlg,
DWLP_USER,
(LONG_PTR)TRUE );
}
EnableWindow( hwndTree, TRUE );
EnableWindow( GetDlgItem(hwndDlg,IDB_REMOVE),
TRUE );
EnableWindow( GetDlgItem(hwndDlg,IDB_CLOSE),
TRUE );
}
}
return;
}
//
// Function: ExpandCollapseAll
//
// Purpose: Expand or collapse a tree.
//
// Arguments:
// hwndTree [in] Window handle of the tree.
// hTreeItem [in] Handle of root item.
// uiFlag [in] Flag indicating whether to expand or collapse.
//
// Returns: None.
//
// Notes:
//
VOID ExpandCollapseAll (HWND hwndTree,
HTREEITEM hTreeItem,
UINT uiFlag)
{
HTREEITEM hItemChild;
hItemChild = TreeView_GetChild( hwndTree,
hTreeItem );
if ( hItemChild ) {
//
// If the root has one or more children, expand/collapse the root.
//
TreeView_Expand( hwndTree,
hTreeItem,
uiFlag );
}
while ( hItemChild ) {
//
// Expand/collapse all the children.
//
ExpandCollapseAll( hwndTree,
hItemChild,
uiFlag );
//
// Expand/collapse all the siblings.
//
hItemChild = TreeView_GetNextSibling( hwndTree,
hItemChild );
}
return;
}
//
// Function: GetFileName
//
// Purpose: Prompt for a filename.
//
// Arguments:
// hwndDlg [in] Window handle of the parent.
// lpszFilter [in] See documentation for GetOpenFileName.
// lpszTitle [in] See documentation for GetOpenFileName.
// dwFlags [in] See documentation for GetOpenFileName.
// lpszFile [in] See documentation for GetOpenFileName.
//
// Returns: See documentation for GetOpenFileName.
//
// Notes:
//
BOOL GetFileName (HWND hwndDlg,
LPWSTR lpszFilter,
LPWSTR lpszTitle,
DWORD dwFlags,
LPWSTR lpszFile,
LPWSTR lpszDefExt,
BOOL fSave)
{
OPENFILENAMEW ofn;
lpszFile[0] = NULL;
ZeroMemory( &ofn, sizeof(OPENFILENAMEW) );
ofn.lStructSize = sizeof(OPENFILENAMEW);
ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = lpszFilter;
ofn.lpstrFile = lpszFile;
ofn.lpstrDefExt = lpszDefExt;
ofn.nMaxFile = MAX_PATH+1;
ofn.lpstrTitle = lpszTitle;
ofn.Flags = dwFlags;
if ( fSave )
{
return GetSaveFileName( &ofn );
}
else
{
return GetOpenFileName( &ofn );
}
}
//
// Function: ProcessRightClick
//
// Purpose: Handle righ mouse button click.
//
// Arguments:
// lpnm [in] LPNMHDR info
//
// Returns: None.
//
// Notes:
//
VOID ProcessRightClick (LPNMHDR lpnm)
{
HTREEITEM hItemSelected;
LPARAM lParam;
DWORD dwItemType;
BOOL fEnabled;
//
// Determine the item on which user clicked the right mouse button.
//
hItemSelected = TreeView_GetDropHilight( lpnm->hwndFrom );
if ( !hItemSelected ) {
hItemSelected = TreeView_GetSelection( lpnm->hwndFrom );
}
else {
//
// User has right-clicked an unselected item, make that a selected
// item.
//
TreeView_Select( lpnm->hwndFrom,
hItemSelected,
TVGN_CARET );
}
if ( hItemSelected ) {
//
// Get the lParam of the selected node in the tree which points to inf id or
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -