こんにちは。
Buttonを押したときに特定のExprolerのwindowのiconの表示サイズを変更したいです。
アイコンを小さくするコマンドメッセージは0x702aだということなので、エクスプローラのウィンドウに WM_COMMAND, 0x702A, 0をPostMessageしてみました。
前半でactivewindowにし、そのhWndはとれているようです。
ウィンドウがactiveになるので。
しかし、PostMessageがうまくいかないです。
併せて、アイコンを最大化するコマンドメッセージとか、メッセージ一覧もいただけたら嬉しいです。
Windows10, Visual Studio 2013 communityです。
private const int WM_COMMAND = 0x0111; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr FindWindow( string lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = true)] public static extern int GetWindowThreadProcessId( IntPtr hWnd, out int lpdwProcessId); private const Int32 WM_USER = 0x400; private const Int32 WM_IPC_MESSAGE = WM_USER + 1; [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); private void Button_Click(object sender, RoutedEventArgs e){ IntPtr hWnd = activeWindow("titleOfWindow"); PostMessage(hWnd, WM_COMMAND, new IntPtr(0x702A), IntPtr.Zero); } //以下の参照を追加 //・com/Microsoft Shell Controls And Automation //・com/Microsoft Internet Control //web.LocationNameがエクスプローラが選択しているフォルダ //web.LocationURLがするフルパス //※コード中ではLocationNameのみ使用しています [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); public IntPtr activeWindow(string foldername) { IntPtr hWnd = (IntPtr)0; Shell shell = new Shell(); ShellWindows win = shell.Windows(); foreach (IWebBrowser2 web in win) { if (Path.GetFileName(web.FullName).ToUpper() == "EXPLORER.EXE") { // この部分をアクティブにしたいエクスプローラのタイトル(選択フォルダ)に変更してください if (web.LocationName == foldername) { // 指定のエクスプローラをアクティブにする hWnd = (IntPtr)web.HWND; SetForegroundWindow(hWnd); break; } } } return hWnd; } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。