關掉widows視窗 |
答題得分者是:ys168
|
anderson8585
一般會員 發表:10 回覆:13 積分:4 註冊:2007-08-27 發送簡訊給我 |
這是我要關掉Windows Media Player的使用中的視窗
如果我要關掉G3500這個視窗 path => D:\\dd\\G3500 我要怎麼做到呢? 好像有這個SendMessage不好用 或是要怎麼辦到 開我的電腦的所有視窗都關掉 而不是exe檔~ AnsiString S="Windows Media Player"; HWND hMsgWnd; hMsgWnd = FindWindow(NULL, S.c_str()); if ( hMsgWnd ) SendMessage(hMsgWnd, WM_CLOSE, 0, 0); 編輯記錄
anderson8585 重新編輯於 2008-04-03 16:31:30, 註解 無‧
|
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
// 這是站上的程式我用過OK.
[code cpp] //--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- bool __fastcall TForm1::KillTask(String ExeFileName) { bool ContinueLoop; HANDLE FSnapshotHandle; PROCESSENTRY32 FProcessEntry32; int result= 0; FSnapshotHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize = sizeof(FProcessEntry32); ContinueLoop = Process32First(FSnapshotHandle,&FProcessEntry32); while(ContinueLoop !=0) { if((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) == UpperCase(ExeFileName))||(UpperCase(FProcessEntry32.szExeFile) == UpperCase(ExeFileName))) result = (int)TerminateProcess(OpenProcess(PROCESS_TERMINATE, false, FProcessEntry32.th32ProcessID), 0); ContinueLoop = Process32Next(FSnapshotHandle, &FProcessEntry32); } CloseHandle(FSnapshotHandle); return result; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { bool fg= KillTask(Edit1->Text); if(fg) ShowMessage("指定的檔案已關閉..."); else ShowMessage("找不到指定的檔案?"); } //--------------------------------------------------------------------------- [/code]
------
yangshuh |
anderson8585
一般會員 發表:10 回覆:13 積分:4 註冊:2007-08-27 發送簡訊給我 |
ye168 ~
你所po上的code是關掉應用程式 可是我想要的是如何關掉視窗 我在網路上看到的VB的Format 不知道要怎麼修改 有人是否有用過 版上討論的大都是關掉exe 而不是關掉視窗 因為如果開"我的電腦"或"C:\"或"D:\" (是一個視窗並非exe) http://tlcheng.twbbs.org/TLCheng/Basic/vbwindow.htm 我應該是要做這一個功能 不知道有沒有人試過這個功能 您po的範例應該是 http://tlcheng.twbbs.org/TLCheng/Basic/vbtlhelp.htm 用到裡面的format |
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
執行前先開啟個資料夾, 後在關閉此資料夾
程式如下: / 列出目前桌面上所有視窗的 Caption void __fastcall TForm1::Button1Click(TObject *Sender) { int olditemindex=ListBox1->ItemIndex; ListBox1->Items->Clear(); HANDLE hCurrentWindow = GetWindow(Handle, GW_HWNDFIRST); char szText[254]; char className[254]; String t; String c; while (hCurrentWindow != 0) { if((GetWindowText(hCurrentWindow, szText, 255) > 0) && (IsWindowVisible(hCurrentWindow))) { GetClassName(hCurrentWindow,className,255); t=szText; c=className; ListBox1->Items->Add(t); } hCurrentWindow = GetWindow(hCurrentWindow, GW_HWNDNEXT); } if (olditemindex<=(ListBox1->Items->Count)) ListBox1->ItemIndex=olditemindex; } //--------------------------------------------------------------------------- // 以 ListBox1 所點選, 後按此鈕關閉 void __fastcall TForm1::Button2Click(TObject *Sender) { HANDLE hCurrentWindow = GetWindow(Handle,GW_HWNDFIRST); char buff[255]; String Text; while (hCurrentWindow!=0) { if ( ( GetWindowText(hCurrentWindow,buff,255)>0) && IsWindowVisible(hCurrentWindow) ) { Text=buff; if (Text.Pos(ListBox1->Items->Strings[ListBox1->ItemIndex])!=0) { PostMessage(hCurrentWindow, WM_CLOSE, 0, 0); Form1->Caption=ListBox1->Items->Strings[ListBox1->ItemIndex] " [視窗已關閉?]"; } } hCurrentWindow = GetWindow(hCurrentWindow,GW_HWNDNEXT); } } //--------------------------------------------------------------------------- void __fastcall TForm1::ListBox1Click(TObject *Sender) { Form1->Caption=ListBox1->Items->Strings[ListBox1->ItemIndex]; } //--------------------------------------------------------------------------- ===================引 用 anderson8585 文 章=================== ye168 ~ 你所po上的code是關掉應用程式 可是我想要的是如何關掉視窗 我在網路上看到的VB的Format 不知道要怎麼修改 有人是否有用過 版上討論的大都是關掉exe 而不是關掉視窗 因為如果開"我的電腦"或"C:\"或"D:\" (是一個視窗並非exe) http://tlcheng.twbbs.org/TLCheng/Basic/vbwindow.htm 我應該是要做這一個功能 不知道有沒有人試過這個功能 您po的範例應該是 http://tlcheng.twbbs.org/TLCheng/Basic/vbtlhelp.htm 用到裡面的format
------
yangshuh |
anderson8585
一般會員 發表:10 回覆:13 積分:4 註冊:2007-08-27 發送簡訊給我 |
非常謝謝ye168 ~
我參考了您寫的code 有去看了一些Windows SDK的Documents 目前我有做稍微的更改 那有辦法去判斷 我要關掉的只有是 資料夾視窗 其他都留著嗎? 因為我有做要刪除C槽裡面的資料夾檔案等等動作 因為資料夾開著的話 是刪檔不成功的 需要關閉才能成功 所以想說只去關掉資料夾視窗 不然您是否還有哪些建議 怎麼做會比較快
編輯記錄
anderson8585 重新編輯於 2008-04-08 11:09:48, 註解 無‧
|
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
// 請先開啟愈關閉的資料夾
.h #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp><br />//--------------------------------------------------------------------------- bool CALLBACK EnumChildProc(HWND, LPARAM); bool CALLBACK EnumWindowsCallBack(HWND, LPARAM); //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TComboBox *ComboBox1; TButton *Button2; TButton *Button1; void __fastcall Button2Click(TObject *Sender); void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); void __fastcall subwin(void); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif .cpp #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- bool CALLBACK EnumWindowsCallBack(HWND hwnd,LPARAM lParam) { char WCaption[256]; GetWindowText(hwnd, WCaption, 255); TComboBox *box=(TComboBox *)lParam; if(box!=NULL && StrLen(WCaption)>0 && box->Items->IndexOf(String(WCaption))<0) box->Items->Add(String(WCaption)); return true; } //--------------------------------------------------------------------------- void __fastcall TForm1::subwin(void) { ComboBox1->Clear(); EnumWindows((WNDENUMPROC)EnumWindowsCallBack, (LPARAM)ComboBox1); if(ComboBox1->Items->Count>0) ComboBox1->ItemIndex=0; } //--------------------------------------------------------------------------- // 點選關閉資料夾 void __fastcall TForm1::Button2Click(TObject *Sender) { HWND hwnd; hwnd=FindWindow(NULL, ComboBox1->Text.c_str()); if (hwnd != 0) PostMessage(hwnd, WM_CLOSE, 0, 0); // 關閉指定視窗 } //--------------------------------------------------------------------------- // 載入視窗列表 void __fastcall TForm1::Button1Click(TObject *Sender) { subwin(); } //--------------------------------------------------------------------------- ===================引 用 anderson8585 文 章=================== 非常謝謝ye168 ~ 我參考了您寫的code 有去看了一些Windows SDK的Documents 目前我有做稍微的更改 那有辦法去判斷 我要關掉的只有是 資料夾視窗 其他都留著嗎? 因為我有做要刪除C槽裡面的資料夾檔案等等動作 因為資料夾開著的話 是刪檔不成功的 需要關閉才能成功 所以想說只去關掉資料夾視窗 不然您是否還有哪些建議 怎麼做會比較快
------
yangshuh |
anyone
中階會員 發表:1 回覆:63 積分:52 註冊:2007-02-12 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |