掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ShellExecute(Handle, 'OPEN', 'で起動したアプリを閉じるには。 (ID:32347)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
1) タイマーで自分にメッセージを送って、無理やりメッセージループを回す のはいかにも非効率ですね。自分でメッセージループを真似てループを回すと いいです。 2) ビューワのクラス名は ShImgVw:CPreviewWnd なので >hd := FindWindow('Rundll32.exe',nil); ではなく hd := FindWindow('ShImgVw:CPreviewWnd',nil); とすると成功しますね。(Xp で確認) とりあえずテストコードを示します。 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm1 = class(TForm) OpenDialog1: TOpenDialog; Button1: TButton; ListBox1: TListBox; procedure Button1Click(Sender: TObject); private { Private 宣言 } public procedure GetKeyLoop; procedure SlideShowDisp(const c:integer); end; var Form1: TForm1; implementation {$R *.dfm} uses ShellAPI; var ListNo:integer; flag :Boolean; procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin ListBox1.Sorted:=true; OpenDialog1.Options:=[ofAllowMultiSelect]; //複数のファイルを選択する if OpenDialog1.Execute then for i := 0 to OpenDialog1.Files.Count - 1 do Listbox1.Items.Add(OpenDialog1.Files[i]); ListNo:=0; flag := true; GetKeyLoop; end; function IsKeyPushed(ch : Char): Boolean; begin result := (GetAsyncKeyState(ord(ch)) and $8000) <> 0; end; procedure TForm1.GetKeyLoop; begin while flag do begin Application.ProcessMessages; Sleep(10); if IsKeyPushed('Z') then begin Sleep(250);SlideShowDisp(1);end else if IsKeyPushed('A') then begin Sleep(250);SlideShowDisp(2);end else if IsKeyPushed('Q') then begin Sleep(250);SlideShowDisp(8);end end; end; procedure TForm1.SlideShowDisp(const c:integer); var hd:HWND; Path:string; begin if ListBox1.Items.Count=0 then exit; case c of 1: begin ListNo:=ListNo+1;end; //------次へ Z 2: begin ListNo:=ListNo-1;end; //------前へ A 8: begin hd := FindWindow('ShImgVw:CPreviewWnd',nil); SendMessage(hd, WM_CLOSE, 0, 0); flag := false; exit; end; else exit; end; if ListNo<0 then ListNo:=0; if ListNo>ListBox1.Items.Count-1 then ListNo:=ListBox1.Items.Count-1; Path:= 'shimgvw.dll,ImageView_Fullscreen '+ListBox1.Items.Strings[ListNo]; ShellExecute(Handle, 'OPEN', 'Rundll32.exe',PChar(Path), nil, SW_SHOW); end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.