跳动百科

shell编程基础(shell编程)

农娥祥   来源:

大家好,小阳来为大家解答以上的问题。shell编程基础,shell编程这个很多人还不知道,现在让我们一起来看看吧!

1、/////////////////////////////////////#define INC_OLE2#define WIN32_LEAN_AND_MEAN#define STRICT#include #include #include #include #include #include “taskbar.h”#include “resource.h”// datastatic WNDPROC g_pfnOldProc;static HWND g_hwndButton=NULL;static HWND g_hDlg=NULL;static HINSTANCE g_hInstance;static HICON g_hIconLarge;static HICON g_hIconSmall;// functionsstatic VOID OnRunPrograms( VOID );static VOID OnFindFiles( VOID );static VOID OnMinimizeAll( VOID );static VOID OnUndoMinimize( VOID );static VOID OnTaskbarProperties( VOID );static VOID OnAddTab( HWND );static VOID OnDeleteTab( VOID );static VOID OnInitDialog( HWND );static VOID OnButtonActivation( VOID );// callbacksLRESULT CALLBACK APP_DlgProc( HWND, UINT, WPARAM, LPARAM );LRESULT CALLBACK ButtonProc( HWND, UINT, WPARAM, LPARAM );INT APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevious,LPSTR lpsz, INT iCmd ){BOOL b;g_hIconLarge = (HICON) LoadImage( hInstance, “APP_ICON”, IMAGE_ICON,GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CXICON), 0 );g_hIconSmall = (HICON) LoadImage( hInstance, “APP_ICON”, IMAGE_ICON,GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CXSMICON), 0 );// initialize OLE librariesCoInitialize(NULL);InitCommonControls();// run main dialogg_hInstance = hInstance;b = DialogBox( hInstance, “DLG_MAIN”, NULL, (DLGPROC)APP_DlgProc );// exitDestroyIcon( g_hIconLarge );DestroyIcon( g_hIconSmall );// free the objects used by ITaskbarListDestroyWindow( g_hwndButton );OnDeleteTab();CoUninitialize();return b;}LRESULT CALLBACK APP_DlgProc( HWND hDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam ){switch( uiMsg ){case WM_INITDIALOG:OnInitDialog( hDlg );break;case WM_COMMAND:switch( wParam ){case IDC_FINDFILES:OnFindFiles();return 1;case IDC_RUNPROGRAMS:OnRunPrograms();return 1;case IDC_MINIMIZE:OnMinimizeAll();return 1;case IDC_UNDOMINIMIZE:OnUndoMinimize();return 1;case IDC_PROPERTIES:OnTaskbarProperties();return 1;case IDC_ADDTAB:OnAddTab( hDlg );return 1;case IDC_DELETETAB:OnDeleteTab();return 1;case IDCANCEL:EndDialog( hDlg, FALSE );return 0;}break;}return 0;}VOID OnFindFiles( VOID ){HRESULT sc;IShellDispatch *pShellDisp = NULL;sc = CoCreateInstance( CLSID_Shell, NULL, CLSCTX_SERVER, IID_IDispatch, (LPVOID *) &pShellDisp );if( FAILED(sc) )return;pShellDisp->FindFiles();pShellDisp->Release();return;}VOID OnTaskbarProperties( VOID ){HRESULT sc;IShellDispatch *pShellDisp = NULL;sc = CoCreateInstance( CLSID_Shell, NULL, CLSCTX_SERVER,IID_IDispatch, (LPVOID *) &pShellDisp );if( FAILED(sc) )return;pShellDisp->TrayProperties();pShellDisp->Release();return;}VOID OnRunPrograms( VOID ){HRESULT sc;IShellDispatch *pShellDisp = NULL;sc = CoCreateInstance( CLSID_Shell, NULL, CLSCTX_SERVER, IID_IShellDispatch, (LPVOID *) &pShellDisp );if( FAILED(sc) )return;pShellDisp->FileRun();pShellDisp->Release();return;}VOID OnMinimizeAll( VOID ){HRESULT sc;IShellDispatch *pShellDisp = NULL;sc = CoCreateInstance( CLSID_Shell, NULL, CLSCTX_SERVER,IID_IDispatch, (LPVOID *) &pShellDisp );if( FAILED(sc) )return;pShellDisp->MinimizeAll();pShellDisp->Release();return;}VOID OnUndoMinimize( VOID ){HRESULT sc;IShellDispatch *pShellDisp = NULL;sc = CoCreateInstance( CLSID_Shell, NULL, CLSCTX_SERVER,IID_IDispatch, (LPVOID *) &pShellDisp );if( FAILED(sc) )return;pShellDisp->UndoMinimizeALL();pShellDisp->Release();return;}VOID OnInitDialog( HWND hDlg ){// set the icons (T/F as to Large/Small icon)g_hDlg = hDlg;SendMessage( hDlg, WM_SETICON, FALSE, (LPARAM)g_hIconSmall );SendMessage( hDlg, WM_SETICON, TRUE, (LPARAM)g_hIconLarge );}VOID OnAddTab( HWND hWnd ){static BOOL g_bFirstTime=TRUE;HRESULT sc;ITaskbarList *pDisp = NULL;sc = CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_SERVER, IID_ITaskbarList, (LPVOID *) &pDisp );if( FAILED(sc) )return;// call the first time onlyif( g_bFirstTime ){g_bFirstTime = FALSE;pDisp->HrInit();// create a new button windowg_hwndButton = CreateWindow( “button”, “My Button”, WS_CLIPSIBLINGS|BS_PUSHBUTTON,0, 0, 58, 14, hWnd, NULL, g_hInstance, NULL );g_pfnOldProc = (WNDPROC) SubclassWindow( g_hwndButton, ButtonProc );}pDisp->AddTab( g_hwndButton );pDisp->Release();return;}VOID OnDeleteTab( VOID ){HRESULT sc;ITaskbarList *pDisp = NULL;sc = CoCreateInstance( CLSID_TaskbarList, NULL, CLSCTX_SERVER, IID_ITaskbarList, (LPVOID *) &pDisp );if( FAILED(sc) )return;pDisp->DeleteTab( g_hwndButton );pDisp->Release();return;}LRESULT CALLBACK ButtonProc( HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam ){switch( uiMsg ){case WM_NCACTIVATE:if( wParam==TRUE )OnButtonActivation();break;}return CallWindowProc( g_pfnOldProc, hwnd, uiMsg, wParam, lParam );}VOID OnButtonActivation( VOID ){HMENU hmenu;RECT r;LONG x, y;// get some window handlesHWND h0=FindWindow(“Shell_TrayWnd”, NULL );HWND h1=FindWindowEx(h0,NULL,”RebarWindow32″, NULL);HWND h2=FindWindowEx(h1,NULL,”MSTaskSwWClass”, NULL);HWND h3=FindWindowEx(h2,NULL,”SysTabControl32″, NULL);GetWindowRect( h3, &r );// get the currently selected button and// create a new popup menuhmenu = CreatePopupMenu();INT i=TabCtrl_GetCurSel( h3 );if( i==-1 ){AppendMenu( hmenu, MF_STRING, IDC_DELETETAB,”&Close” );}else{AppendMenu( hmenu, MF_STRING, IDC_MINIMIZE,”&Minimize All” );AppendMenu( hmenu, MF_STRING, IDC_UNDOMINIMIZE,”&Undo Minimize All” );AppendMenu( hmenu, MF_SEPARATOR, 0, NULL );AppendMenu( hmenu, MF_STRING, IDC_PROPERTIES,”&Taskbar Properties” );}// set and immediately reset its size to get// the current width and heightLONG l = TabCtrl_SetItemSize( h3, 0, 0 );TabCtrl_SetItemSize( h3, LOWORD(l), HIWORD(l) );// have the menu to appear just above the buttonif( i==-1 ){POINT pt;GetCursorPos( &pt );x = pt.x;y = pt.y;}else{x = r.left + LOWORD(l)*i+3;y = GetSystemMetrics(SM_CYSCREEN)-(HIWORD(l)+1);}TrackPopupMenu( hmenu, TPM_BOTTOMALIGN, x, y, 0, g_hDlg, 0);DestroyMenu( hmenu );return;}。

本文到此分享完毕,希望对大家有所帮助。