(今日の独り言)

 AutoHotkeyツールボックス的な アプリケーションを作ってみようかなと 製作中
普通に コピペして 実行すれば 多分 すぐにでも動くはず 多分、 あくまでも 多分 笑)

 以下の コードを 適当に ToolBox.ahk みたいな感じで保存して アプリケーションとして実行すれば
アクティブな ウインドウによって 形態を変える ツールボックスになります

 まだ 全然 完成してないけど雰囲気は伝わるかな? 笑)
現在は OutlookExpress と 秀丸 と 卓駆 に ちょっとだけ 個別に対応

 注意! あくまで まだ 現在製作中ですので 笑)
[]#NoTrayIcon[]
[]Gosub, On_InitApp[]
[]OnExit, On_ExitApp[]
[]Return[]
[]; -----------------------------------------------------------------------------------------------------------------------------------------------[]
[]; GUIの再構築 と ボタンを押した時の処理[]
[]RebuildToolBox:[]
[]{[]
[]	WinGetPos, GuiX, GuiY, GuiW, GuiH, ahk_class AutoHotkeyGUI[]
[]	If (GuiX == "")[]
[]	{[]
[]		; 最初に ツールボックスを表示させる位置[]
[]		GuiX := 900[]
[]		GuiY := 900[]
[]	}[]
[]	Gui, Destroy[]
[]	; --------------------------------------------------------------------------------------------------------------[]
[]	; ツールボックスの 構築処理 は ↓↓↓↓ここから↓↓↓↓[]
[]	;     操作対象のウインドウハンドル は hWindow[]
[]	;     操作対象のクラス名は         は ClassName[]
[]	;     操作対象のタイトルは         は WindowTitle[]

[]	If ( ClassName == "Hidemaru32Class" )[]
[]	{[]
[]		Gui, Font, S10[]
[]		Gui, Add, Button, X2 Y2 W40 H20 gClassNameCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %ClassName%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gTitleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %WindowTitle%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gHandleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W200 H20 ReadOnly, %hWindow%[]
[]		Gui, Add, Button, X280 yp+3 W200 H20 gCloseThisApp, 秀丸を終了する[]
[]		Gui, Add, Button, X4 y+10 W120 H20 gHidemaru_Search, 検索[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gHidemaru_Replace, 置換[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gHidemaru_FindUp, ↑候補[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gHidemaru_FindDown, ↓候補[]
[]		Gui, Add, Button, X4 y+4 W120 H20 gHidemaru_Highlight, 検索文字列の強調[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gHidemaru_Divide, ウィンドウ分割[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gHidemaru_Jump, 指定行[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gHidemaru_ForceSave, 上書き保存[]
[]		Gui, Font[]
[]		GuiW := 500[]
[]		GuiH := 130[]
[]		Goto, ShowToolBox[]
[]	}[]
[]	If ( ClassName == "Tac!Main" )[]
[]	{[]
[]		Gui, Font, S10[]
[]		Gui, Add, Button, X2 Y2 W40 H20 gClassNameCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %ClassName%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gTitleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %WindowTitle%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gHandleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W200 H20 ReadOnly, %hWindow%[]
[]		Gui, Add, Button, X280 yp+3 W200 H20 gCloseThisApp, 卓駆を終了する[]
[]		Gui, Add, Button, X4 y+10 W120 H20 gTac_Sort_Name, 名前でソート[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gTac_Sort_Size, サイズでソート[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gTac_Sort_Time, 時間でソート[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gTac_Sort_Ext, 拡張子でソート[]
[]		Gui, Add, Button, X4 y+4 W120 H20 gTac_Sort_Up, 昇順でソート[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gTac_Sort_Down, 降順でソート[]
[]		Gui, Font[]
[]		GuiW := 500[]
[]		GuiH := 130[]
[]		Goto, ShowToolBox[]
[]	}[]
[]	If ( ClassName == "Outlook Express Browser Class" )[]
[]	{[]
[]		Gui, Font, S10[]
[]		Gui, Add, Button, X2 Y2 W40 H20 gClassNameCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %ClassName%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gTitleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %WindowTitle%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gHandleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W200 H20 ReadOnly, %hWindow%[]
[]		Gui, Add, Button, X280 yp+3 W200 H20 gCloseThisApp, OutlookExpressを終了する[]
[]		Gui, Add, Button, X4 y+10 W120 H20 gOutlookExpress_ShutoutThisPostUser, 禁止ユーザに登録[]
[]		Gui, Add, Button, x+4 yp+0 W120 H20 gOutlookExpress_AllReceive, 全て受信[]
[]		Gui, Font[]
[]		GuiW := 500[]
[]		GuiH := 105[]
[]		Goto, ShowToolBox[]
[]	}[]
[]	; デスクトップだった場合[]
[]	If ( ClassName == "Progman" )[]
[]	{[]
[]		Gui, Font, S10[]
[]		Gui, Add, Button, X2 Y2 W40 H20 gClassNameCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %ClassName%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gTitleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %WindowTitle%[]
[]		Gui, Add, Button, X2 y+2 W40 H20 gHandleCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W200 H20 ReadOnly, %hWindow%[]
[]		Gui, Add, Button, X280 yp+0 W200 H20 gCloseThisApp, Windows終了オプションを表示する[]
[]		Gui, Font[]
[]		GuiW := 500[]
[]		GuiH := 70[]
[]		Goto, ShowToolBox[]
[]	}[]
[]	; タスクバーだった場合[]
[]	If ( ClassName == "Shell_TrayWnd" )[]
[]	{[]
[]		Gui, Font, S10[]
[]		Gui, Add, Button, X2 Y2 W40 H20 gClassNameCopy, Copy[]
[]		Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %ClassName%[]
[]		Gui, Add, Button, X270 y+5 W200 H20 gCloseThisApp, Windows終了オプションを表示する[]
[]		Gui, Font[]
[]		GuiW := 500[]
[]		GuiH := 50[]
[]		Goto, ShowToolBox[]
[]	}[]
[]	; 未登録だった場合[]
[]	Gui, Font, S10[]
[]	Gui, Add, Button, X2 Y2 W40 H20 gClassNameCopy, Copy[]
[]	Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %ClassName%[]
[]	Gui, Add, Button, X2 y+2 W40 H20 gTitleCopy, Copy[]
[]	Gui, Add, Edit, x+4 yp+0 W452 H20 ReadOnly, %WindowTitle%[]
[]	Gui, Add, Button, X2 y+2 W40 H20 gHandleCopy, Copy[]
[]	Gui, Add, Edit, x+4 yp+0 W200 H20 ReadOnly, %hWindow%[]
[]	Gui, Add, Button, X280 yp+2 W200 H20 gCloseThisApp, このアプリケーションを終了させる[]
[]	Gui, Font[]
[]	GuiW := 500[]
[]	GuiH := 70[]
[]	; ツールボックスの 構築処理 は ↑↑↑↑ここまで↑↑↑↑[]
[]	; --------------------------------------------------------------------------------------------------------------[]
[]	ShowToolBox:[]
[]	Gui, +E0x00000080[]
[]	Gui, Show, X%GuiX% Y%GuiY% W%GuiW% H%GuiH% NoActivate, AHK ToolBox[]
[]	hGui := WinExist("ahk_class AutoHotkeyGUI")[]
[]	WinSet, AlwaysOnTop, On, ahk_id %hGui%[]
[]	Return[]
[]}[]
[]; --------------------------------------------------------------------------------------------------------------[]
[]; ツールボックスからの 呼び出しサブルーチン は ↓↓↓↓ここから↓↓↓↓[]
[]ClassNameCopy:[]
[]{[]
[]	Clipboard := ClassName[]
[]	ToolTip, %ClassName%[]
[]	Sleep,2000[]
[]	ToolTip[]
[]	Return[]
[]}[]
[]CloseThisApp:[]
[]{[]
[]	WinClose, ahk_id %hWindow%[]
[]	Return[]
[]}[]
[]Hidemaru_Search:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 62)[]
[]	Return[]
[]}[]
[]Hidemaru_Replace:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 65)[]
[]	Return[]
[]}[]
[]Hidemaru_FindUp:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 64)[]
[]	Return[]
[]}[]
[]Hidemaru_FindDown:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 63)[]
[]	Return[]
[]}[]
[]Hidemaru_Highlight:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 344)[]
[]	Return[]
[]}[]
[]Hidemaru_Divide:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 140)[]
[]	Return[]
[]}[]
[]Hidemaru_Jump:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 34)[]
[]	Return[]
[]}[]
[]Hidemaru_ForceSave:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 5)[]
[]	Return[]
[]}[]
[]OutlookExpress_ShutoutThisPostUser:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 40294)[]
[]	WinWaitActive, Outlook Express, 現在のフォルダからも, 2[]
[]	Send, {Enter}[]
[]	WinWaitActive, Outlook Express, 選択された送信者からの, 2[]
[]	Send, {Enter}[]
[]	Return[]
[]}[]
[]OutlookExpress_AllReceive:[]
[]{[]
[]	WinActivate, ahk_id %hWindow%[]
[]	PstCmd(hWindow, 40194)[]
[]	Return[]
[]}[]
[]TitleCopy:[]
[]{[]
[]	Clipboard := WindowTitle[]
[]	ToolTip, %WindowTitle%[]
[]	Sleep,2000[]
[]	ToolTip[]
[]	Return[]
[]}[]
[]HandleCopy:[]
[]{[]
[]	Clipboard := hWindow[]
[]	ToolTip, %hWindow%[]
[]	Sleep,2000[]
[]	ToolTip[]
[]	Return[]
[]}[]
[]Tac_Sort_Name:[]
[]{[]
[]	buf_IME_IsON := IME_IsON(hWindow)[]
[]	IME_ON(hWindow, False)[]
[]	WinActivate, ahk_id %hWindow%[]
[]	WinWaitActive, ahk_id %hWindow%, , 2[]
[]	Send, s[]
[]	WinWaitActive, ソートの設定, , 2[]
[]	Send, n{Enter}[]
[]	IME_ON(hWindow, buf_IME_IsON)[]
[]	Return[]
[]}[]
[]Tac_Sort_Size:[]
[]{[]
[]	buf_IME_IsON := IME_IsON(hWindow)[]
[]	IME_ON(hWindow, False)[]
[]	WinActivate, ahk_id %hWindow%[]
[]	WinWaitActive, ahk_id %hWindow%, , 2[]
[]	Send, s[]
[]	WinWaitActive, ソートの設定, , 2[]
[]	Send, s{Enter}[]
[]	IME_ON(hWindow, buf_IME_IsON)[]
[]	Return[]
[]}[]
[]Tac_Sort_Time:[]
[]{[]
[]	buf_IME_IsON := IME_IsON(hWindow)[]
[]	IME_ON(hWindow, False)[]
[]	WinActivate, ahk_id %hWindow%[]
[]	WinWaitActive, ahk_id %hWindow%, , 2[]
[]	Send, s[]
[]	WinWaitActive, ソートの設定, , 2[]
[]	Send, t{Enter}[]
[]	IME_ON(hWindow, buf_IME_IsON)[]
[]	Return[]
[]}[]
[]Tac_Sort_Ext:[]
[]{[]
[]	buf_IME_IsON := IME_IsON(hWindow)[]
[]	IME_ON(hWindow, False)[]
[]	WinActivate, ahk_id %hWindow%[]
[]	WinWaitActive, ahk_id %hWindow%, , 2[]
[]	Send, s[]
[]	WinWaitActive, ソートの設定, , 2[]
[]	Send, x{Enter}[]
[]	IME_ON(hWindow, buf_IME_IsON)[]
[]	Return[]
[]}[]
[]Tac_Sort_Up:[]
[]{[]
[]	buf_IME_IsON := IME_IsON(hWindow)[]
[]	IME_ON(hWindow, False)[]
[]	WinActivate, ahk_id %hWindow%[]
[]	WinWaitActive, ahk_id %hWindow%, , 2[]
[]	Send, s[]
[]	WinWaitActive, ソートの設定, , 2[]
[]	Send, p{Enter}[]
[]	IME_ON(hWindow, buf_IME_IsON)[]
[]	Return[]
[]}[]
[]Tac_Sort_Down:[]
[]{[]
[]	buf_IME_IsON := IME_IsON(hWindow)[]
[]	IME_ON(hWindow, False)[]
[]	WinActivate, ahk_id %hWindow%[]
[]	WinWaitActive, ahk_id %hWindow%, , 2[]
[]	Send, s[]
[]	WinWaitActive, ソートの設定, , 2[]
[]	Send, d{Enter}[]
[]	IME_ON(hWindow, buf_IME_IsON)[]
[]	Return[]
[]}[]
[]; ツールボックスからの 呼び出しサブルーチン は ↑↑↑↑ここまで↑↑↑↑[]
[]; -----------------------------------------------------------------------------------------------------------------------------------------------[]
[]; 初期化処理[]
[]On_InitApp:[]
[]{[]
[]	SetTimer, On_Timer, 200[]
[]	Return[]
[]}[]
[]; -----------------------------------------------------------------------------------------------------------------------------------------------[]
[]; 終了処理[]
[]On_ExitApp:[]
[]{[]
[]	ExitApp[]
[]}[]
[]; -----------------------------------------------------------------------------------------------------------------------------------------------[]
[]; タイマー処理[]
[]On_Timer:[]
[]{[]
[]	hActive := WinExist("A")[]
[]	If ( hActive == hGui )[]
[]	{[]
[]		If WinExist("ahk_id " . hWindow)[]
[]		{[]
[]			Gosub, Check_IsOnderMouse[]
[]			Return[]
[]		}Else{[]
[]			Gosub, RebuildToolBox[]
[]			Gosub, Check_IsOnderMouse[]
[]			Return[]
[]		}[]
[]	}[]
[]	If ( (hActive != hWindow) or (WindowTitle != H2T(hActive)) )[]
[]	{[]
[]		hWindow := hActive[]
[]		ClassName := H2C(hWindow)[]
[]		WindowTitle := H2T(hWindow)[]
[]		Gosub, RebuildToolBox[]
[]		Gosub, Check_IsOnderMouse[]
[]		Return[]
[]	}Else{[]
[]		Gosub, Check_IsOnderMouse[]
[]		Return[]
[]	}[]
[]	MsgBox, Check漏れ有り[]
[]}[]
[]; -----------------------------------------------------------------------------------------------------------------------------------------------[]
[]; GUIを閉じた時の処理[]
[]GuiClose:[]
[]{[]
[]	ExitApp[]
[]}[]
[]; -----------------------------------------------------------------------------------------------------------------------------------------------[]
[]; GUI上にカーソルがあるかどうかのチェック[]
[]Check_IsOnderMouse:[]
[]{[]
[]	Return    ; Shade処理をする時は この Returnをコメントアウトする[]
[]	WinGetPos, CurrentX, CurrentY, CurrentW, CurrentH, ahk_class AutoHotkeyGUI[]
[]	If ( hGui == M2PH() )[]
[]	{[]
[]		If ( CurrentH == 22 )[]
[]			WinMove, ahk_class AutoHotkeyGUI, , CurrentX, CurrentY, CurrentW, LastH[]
[]	}Else{[]
[]		If ( CurrentH != 22 )[]
[]		{[]
[]			LastH := CurrentH[]
[]			WinMove, ahk_class AutoHotkeyGUI, , CurrentX, CurrentY, CurrentW, 22[]
[]		}[]
[]	}[]
[]Return[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]; 以下は 現在自分で製作中のライブラリの一部[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]PstCmd(hWindow, wParam, lParam = 0)[]
[]{[]
[]	Return 	DllCall("user32.dll\PostMessageA", "UInt", hWindow, "UInt", 0x0111, "Int", wParam, "Int", lParam)[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]SndSysCmd(hWindow, wParam, lParam = 0)[]
[]{[]
[]	Return 	DllCall("user32.dll\SendMessageA", "UInt", hWindow, "UInt", 0x0112, "Int", wParam, "Int", lParam)[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]IME_IsON(hWindow)[]
[]{[]
[]	; WM_IME_CONTROL    = 0x0283[]
[]	; IMC_GETOPENSTATUS = 0x0005[]
[]	bufCurrentDetectMode := A_DetectHiddenWindows[]
[]	DetectHiddenWindows, On[]
[]	buf := DllCall("user32.dll\SendMessageA", "UInt", DllCall("imm32.dll\ImmGetDefaultIMEWnd", "Uint",hWindow)[]
[]	                                        , "UInt", 0x0283, "Int", 0x0005, "Int", 0)[]
[]	DetectHiddenWindows, %bufCurrentDetectMode%[]
[]	Return buf[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]IME_ON(hWindow, IsON)[]
[]{[]
[]	; WM_IME_CONTROL    = 0x0283[]
[]	; IMC_SETOPENSTATUS = 0x0006[]
[]	bufCurrentDetectMode := A_DetectHiddenWindows[]
[]	DetectHiddenWindows, On[]
[]	buf := DllCall("user32.dll\SendMessageA", "UInt", DllCall("imm32.dll\ImmGetDefaultIMEWnd", "Uint",hWindow)[]
[]	                                        , "UInt", 0x0283, "Int", 0x0006, "Int", IsON)[]
[]	DetectHiddenWindows, %bufCurrentDetectMode%[]
[]	Return buf[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]H2T(hWindow, BufferSize = 120)[]
[]{[]
[]	VarSetCapacity(Buf, BufferSize, 0x00)[]
[]	DllCall("user32.dll\GetWindowTextA", "UInt", hWindow, "Str", Buf, "UInt", BufferSize)[]
[]	Return Buf[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]H2C(hWindow, BufferSize = 120)[]
[]{[]
[]	VarSetCapacity(Buf, BufferSize, 0x00)[]
[]	DllCall("user32.dll\GetClassNameA", "UInt", hWindow, "Str", Buf, "UInt", BufferSize)[]
[]	Return Buf[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]
[]M2PH()[]
[]{[]
[]	MouseGetPos, , , hWindow[]
[]	Return hWindow[]
[]}[]
[];---------------------------------------------------------------------------------------------------------------------------------------------------[]