⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shareenum.cpp

📁 网络共享资源的枚举
💻 CPP
📖 第 1 页 / 共 3 页
字号:

	switch ( message )  {
	case WM_INITDIALOG:
		GetWindowRect( GetParent(hDlg), &parentRc );
		GetWindowRect( hDlg, &childRc );
		parentRc.left += 70;
		parentRc.top  += 60;
		MoveWindow( hDlg, parentRc.left, parentRc.top, childRc.right - childRc.left, childRc.bottom - childRc.top, TRUE );

		underline_link = TRUE;
		hLink = GetDlgItem( hDlg, IDC_LINK );

		// get link fonts
		hFontNormal = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
		GetObject( hFontNormal, sizeof logfont, &logfont); 
		logfont.lfUnderline = TRUE;
		hFontUnderline = CreateFontIndirect( &logfont );

		// get hand
		hHandCursor = LoadCursor( g.hInst, TEXT("HAND") );
		hRegularCursor = LoadCursor( NULL, IDC_ARROW );
		return TRUE;

	case WM_CTLCOLORSTATIC:
		if ( (HWND)lParam == hLink )  {
			HDC	hdc = (HDC)wParam;
			SetBkMode( hdc, TRANSPARENT );
			if ( GetSysColorBrush(26/*COLOR_HOTLIGHT*/) )
				SetTextColor( hdc, GetSysColor(26/*COLOR_HOTLIGHT*/) );
			else
				SetTextColor( hdc, RGB(0,0,255) );
			SelectObject( hdc, underline_link ? hFontUnderline : hFontNormal );
			return (LONG)GetSysColorBrush( COLOR_BTNFACE );
		}
		break;

	case WM_MOUSEMOVE: {
		POINT	pt = { LOWORD(lParam), HIWORD(lParam) };
		HWND	hChild = ChildWindowFromPoint( hDlg, pt );
		if ( underline_link == (hChild == hLink) )  {
			underline_link = !underline_link;
			InvalidateRect( hLink, NULL, FALSE );
		}
		if ( underline_link )
			SetCursor( hRegularCursor );
		else
			SetCursor( hHandCursor );
		break;
	}

	case WM_LBUTTONDOWN: {
		POINT		pt = { LOWORD(lParam), HIWORD(lParam) };
		HWND		hChild = ChildWindowFromPoint( hDlg, pt );
		if ( hChild == hLink )  {
			ShellExecute( hDlg, TEXT("open"), TEXT("http://www.sysinternals.com"), NULL, NULL, SW_SHOWNORMAL );
		} 
		break;
	}

	case WM_COMMAND:
		switch ( wParam ) {
		case IDOK:
		case IDCANCEL:
			EndDialog( hDlg, 0 );
			return TRUE;
		}
		break; 

	case WM_CLOSE:
		EndDialog( hDlg, 0 );
		return TRUE;

	default:
		break;
	}
    return FALSE;

}



//----------------------------------------------------------------------
//  
// MainDialog
//
// Main interface for editing output
//
//----------------------------------------------------------------------
LRESULT CALLBACK MainDialog( HWND hDlg, UINT message, UINT wParam, LONG lParam ) 
{
	static CResizer		resizer;
	int					idx;
	OPENFILENAME		open;
	static TCHAR		exportPath[ MAX_PATH ];
	TCHAR			*	p;
	bool				ok;
	DWORD				style;
	static bool			Starting = true;
	static HCURSOR		hCursor;
	static DWORD		Ticks;

	switch ( message ) {

		case WM_INITDIALOG:
			// set anchor points
			resizer.OnInitDialog( hDlg );
			resizer.SetHorz( GetDlgItem(hDlg,IDC_REFRESH),		ANCHOR_LEFT );
			resizer.SetHorz( GetDlgItem(hDlg,IDC_EXPORT),		ANCHOR_LEFT );
			resizer.SetVert( GetDlgItem(hDlg,IDC_LIST),			ANCHOR_BOTH );
			resizer.SetHorz( GetDlgItem(hDlg,IDC_DOMAIN),		ANCHOR_LEFT );
			resizer.SetHorz( GetDlgItem(hDlg,IDC_DESCRIPTION),	ANCHOR_LEFT );
			resizer.SetHorz( GetDlgItem(hDlg,IDC_STATUS),		ANCHOR_BOTH );
	
			// clear status text
			SetWindowText( GetDlgItem(hDlg,IDC_STATUS),	_T("") );
	
			// Set cursor for window
			hCursor = LoadCursor( NULL, IDC_ARROW );
			SetClassLong( hDlg, GCL_HCURSOR, (LONG)hCursor );
			SetCursor( hCursor );

			// Create listview columns
			InitListViewColumns( GetDlgItem(hDlg,IDC_LIST), Columns, sizeof Columns/sizeof Columns[0] - 1 );

			style = GetWindowLong( GetDlgItem(hDlg,IDC_LIST), GWL_STYLE );
			style |= LVS_SHOWSELALWAYS;
			SetWindowLong( GetDlgItem(hDlg,IDC_LIST), GWL_STYLE, style );
			ListView_SetExtendedListViewStyleEx( GetDlgItem(hDlg,IDC_LIST), LVS_EX_LABELTIP, LVS_EX_LABELTIP );

			// Get a list of domains on network
			SendMessage( GetDlgItem( hDlg, IDC_DOMAIN ), CB_RESETCONTENT, 0, 0 );
			EnumerateDomains( GetDlgItem( hDlg, IDC_DOMAIN ), NULL );
			if ( SendMessage( GetDlgItem( hDlg, IDC_DOMAIN ), CB_GETCOUNT, 0, 0 ) >= 1 )  {
				SendMessage( GetDlgItem( hDlg, IDC_DOMAIN ), CB_ADDSTRING, 0, (LPARAM)ALL_DOMAINS );
			} else {
				MessageBox( hDlg, _T("No domains or workgroups were found on your network"), APPNAME, MB_OK|MB_ICONSTOP );
				EnableWindow( GetDlgItem( hDlg, IDC_REFRESH ), false );
			}
			SendMessage( GetDlgItem( hDlg, IDC_DOMAIN ), CB_SETCURSEL, 0, 0 );

			return TRUE;

		
		case WM_SETCURSOR:
			switch ( LOWORD(lParam) )  {
				case HTTOP:
				case HTBOTTOM:
				case HTLEFT:
				case HTRIGHT:
				case HTTOPLEFT:
				case HTTOPRIGHT:
				case HTBOTTOMLEFT:
				case HTBOTTOMRIGHT:
					break;
				default:
					SetCursor( hCursor ); 
					return true;
			}
			break;

		case WM_APP_ENUM_COMPLETE:
			Ticks = GetTickCount() - Ticks;

			EnableWindow( GetDlgItem( hDlg, IDC_REFRESH ), true );
			EnableWindow( GetDlgItem( hDlg, IDCANCEL    ), false );
			EnableWindow( GetDlgItem( hDlg, IDC_EXPORT ), true );
			hCursor = LoadCursor( NULL, IDC_ARROW );
			SetClassLong( hDlg, GCL_HCURSOR, (LONG)hCursor );
			SetCursor( hCursor );
			if ( g.Abort )  {
				SendMessage( g.Abort, WM_CLOSE, 0, 0 ); 
//				MessageBox( hDlg, _T("Scan cancelled by user"), APPNAME, MB_OK|MB_ICONINFORMATION );
			}
			break;

		case WM_NOTIFY:
			if ( LOWORD(wParam) == IDC_LIST )  {
				NMLISTVIEW	* nm = (NMLISTVIEW *) lParam;
				switch( nm->hdr.code )  {
					case LVN_COLUMNCLICK:
						// sort column
						SortListView( nm->hdr.hwndFrom, nm->iSubItem, Columns );
						break;
					case NM_DBLCLK:
						SendMessage( hDlg, WM_COMMAND, IDC_EXPLORE, 0 );
						break;
					case NM_RCLICK:
						// Create pop-up menu
						idx = ListView_GetSelectionMark( GetDlgItem(hDlg,IDC_LIST) );
						if ( idx >= 0 )  {
							POINT pt;
							GetCursorPos( &pt );

							HMENU hMenu = GetSubMenu( LoadMenu( g.hInst, _T("POPUPMENU") ), 0 );
							SetMenuDefaultItem( hMenu, IDC_PROPERTIES, FALSE );
							TrackPopupMenu( hMenu, 0, pt.x, pt.y, 0, hDlg, NULL );
						}
						break;
				}
			}
			break;

		case WM_COMMAND:
			// Normal notifications
			switch ( LOWORD(wParam) ) {

				case IDOK:
					// quit
					SendMessage( hDlg, WM_CLOSE, 0, 0 );
					break;

				case IDCANCEL:
					// is an enumeration in progress?
					if ( ! IsWindowEnabled( GetDlgItem( hDlg, IDC_REFRESH ) ) )  {
						// have we already cancelled it?
						if ( g.Abort == NULL )  {
							g.Abort = CreateDialog( g.hInst, _T("ABORT"), hDlg, AbortDialog );
						}
					}
					break;

				case IDC_EXPLORE:
				case IDC_PROPERTIES:
					// clicked item, so display device properties
					idx = ListView_GetSelectionMark( GetDlgItem(hDlg,IDC_LIST) );
					if ( idx >= 0 )  {
						TCHAR	path[ MAX_PATH ];
						ListView_GetItemText( GetDlgItem(hDlg,IDC_LIST), idx, 0, path, MAX_PATH );
						if ( LOWORD(wParam) == IDC_EXPLORE )  {
							// explore item
							ShellExecute( NULL, _T("explore"), path, NULL, NULL, SW_SHOWNORMAL );
						} else {
							// show item properties
							if ( _tcschr( path+2, '\\' ) == NULL )
								break;
							Properties( g.hInst, hDlg, path );
						}
					}
					break;

				case IDC_ABOUT:
					DialogBox( g.hInst, _T("ABOUT"), hDlg, AboutDialog );
					break;
				
				case IDC_REFRESH:
					if ( IsWindowEnabled( GetDlgItem( hDlg, IDC_REFRESH ) ) )  {
						// Create a list of all available computers
						EnableWindow( GetDlgItem( hDlg, IDC_REFRESH ), false );
						EnableWindow( GetDlgItem( hDlg, IDCANCEL    ), true );
						EnableWindow( GetDlgItem( hDlg, IDC_EXPORT ), false );
						hCursor = LoadCursor( NULL, IDC_APPSTARTING );
						SetClassLong( hDlg, GCL_HCURSOR, (LONG)hCursor );
						SetCursor( hCursor );

						TCHAR domain[ MAX_PATH ];
						GetDlgItemText( hDlg, IDC_DOMAIN, domain, MAX_PATH );

						delete g.ShareList;
						g.ShareList = NULL;
						g.Abort = NULL;
						ListView_DeleteAllItems( GetDlgItem(hDlg,IDC_LIST) );

						if ( _tcsicmp( domain, ALL_DOMAINS ) == 0 )  {
							// enumerate all domains
							bool warn = false;
							InterlockedIncrement( &g.ThreadCount );
							for ( int i = 1; SendMessage( GetDlgItem(hDlg,IDC_DOMAIN), CB_GETLBTEXT, i, (LPARAM)domain ) != CB_ERR; ++i )  {
								CEnumerateComputers * e = new CEnumerateComputers( GetDlgItem(hDlg,IDC_LIST), domain );
								e->Start();
								if ( ! IsDomainAdmin( domain ) )
									warn = true;
							}
							if ( warn )  {
								MessageBox( hDlg, _T("Information may be incomplete because you are not a domain administrator for one or more of the selected domain."), APPNAME, MB_OK|MB_ICONWARNING );
							}
							if ( InterlockedDecrement( &g.ThreadCount ) == 0 )  {
								PostMessage( g.hMainDlg, WM_APP_ENUM_COMPLETE, 0, 0 );
							}
						} else {
							// enumerate selected domain
							CEnumerateComputers * e = new CEnumerateComputers( GetDlgItem(hDlg,IDC_LIST), domain );
							e->Start();

							if ( ! IsDomainAdmin( domain ) )  {
								MessageBox( hDlg, _T("Information may be incomplete because you are not a domain administrator for the selected domain."), APPNAME, MB_OK|MB_ICONWARNING );
							}
						}
					}
					break;

				case IDC_EXPORT:
					// get export file name
					memset( &open, 0, sizeof open );
					open.lStructSize = sizeof open;
					open.hwndOwner = hDlg;
					open.lpstrFilter = TEXT("Unicode Text (*.txt)\0*.txt\0");
					open.lpstrFile = exportPath;
					open.nMaxFile = sizeof exportPath / sizeof(TCHAR);
					open.Flags = OFN_HIDEREADONLY;
					open.lpstrTitle = TEXT("Save as");
					if ( ! GetSaveFileName( &open ) )
						break;
					p = _tcschr( exportPath, 0 );
					p -= 4;
					if ( p < exportPath  ||  _tcsicmp( p, TEXT(".txt") ) != 0 )
						_tcscat( exportPath, TEXT(".txt") );
					DeleteFile( exportPath );
					ok = ExportFile( GetDlgItem(hDlg,IDC_LIST), exportPath );
					if ( ! ok )
						MessageBox( hDlg, TEXT("Error exporting settings"), APPNAME, MB_OK|MB_ICONSTOP );
					break;

				case IDC_COMPARE:
					CreateDialogParam( g.hInst, _T("COMPARE"), hDlg, CompareDialog, (LPARAM)g.ShareList );
					break;
			}
			break;

		case WM_GETMINMAXINFO:
			resizer.OnGetMinMaxInfo( wParam, lParam );
			return 0;

		case WM_SIZE:
			resizer.OnSize( wParam, lParam );
			UpdateWindow( hDlg );
			return 0;

		case WM_NCHITTEST:
			return resizer.OnNcHitTest( wParam, lParam );

		case WM_PAINT:
			resizer.OnPaint( wParam, lParam );
			break;

		case WM_CLOSE:
			SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
			SaveListViewColumns( GetDlgItem(hDlg,IDC_LIST));
			PostQuitMessage( 0 );
			break;
	}

	return DefWindowProc( hDlg, message, wParam, lParam );
}


//----------------------------------------------------------------------
//  
// WinMain
//
// Initialize and start application
//
//----------------------------------------------------------------------
int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
						LPSTR lpCmdLine, int nCmdShow )
{
	int		 argc;
	WCHAR ** argv = CommandLineToArgvW( GetCommandLine(), &argc );

	// initialize things
	InitCommonControls();

	g.hInst			= hInstance;
	g.MaxThreads	= 200;

	if ( argc > 1 )
		g.MaxThreads = _wtoi( argv[1] );

#if 0
	Properties( g.hInst, NULL, _T("\\\\BHC-DELL620\\Recovery Manager") );
#endif


	// register window class
	WNDCLASSEX	wndclass = { 0 };
	wndclass.cbSize			= sizeof wndclass;
	wndclass.style          = CS_HREDRAW | CS_VREDRAW;
 	wndclass.lpfnWndProc    = MainDialog;
	wndclass.hInstance      = hInstance;
	wndclass.cbWndExtra		= DLGWINDOWEXTRA;
	wndclass.hIcon          = LoadIcon( hInstance, TEXT("APPICON") );
	wndclass.hIconSm		= LoadIcon( hInstance, TEXT("APPICON") );
	wndclass.hCursor        = LoadCursor( NULL, IDC_ARROW );
	wndclass.hbrBackground  = (HBRUSH) (COLOR_BTNFACE+1);
	wndclass.lpszClassName  = TEXT("ShareEnumClass");
	if ( RegisterClassEx( &wndclass ) == 0 )
		GetLastError();

	g.hMainDlg = CreateDialog( hInstance, TEXT("MAIN"), NULL, (DLGPROC)MainDialog );
	if ( g.hMainDlg == NULL )  {
		GetLastError();
		return 1;
	}

	DWORD LocalComputerNameLen = MAX_PATH;
	GetComputerName( g.LocalComputerName, &LocalComputerNameLen );

	// make top window
	//SetWindowPos( hMainDlg, HWND_TOP, 1, 1, 0, 0, SWP_NOSIZE );

	// Make the window visible 
	ShowWindow( g.hMainDlg, nCmdShow );
	// Paint window
	UpdateWindow( g.hMainDlg ); 

	// Keyboard accelerators
	HACCEL hAccel = LoadAccelerators( hInstance, TEXT("ACCELERATORS") );

	// Message loop
	MSG msg;
	while ( GetMessage( &msg, NULL, 0, 0 )) {

		if ( TranslateAccelerator( g.hMainDlg, hAccel, &msg ) )
			continue;
		if ( IsDialogMessage( g.hMainDlg, &msg ) )
			continue;

		// process message
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -