private void UIVisibleTimer_Ticked(object sender, EventArgs e) { #if DEBUG //cnt += 1; //Debug.WriteLine("UIVisible Timer Ticked " + cnt.ToString() ); #endif // 設定プロファイル Profile pf = mainWindow.Setting.TempProfile; // ウインドウ幅が狭い時は、ツールバー位置を調整 int p1 = 490; if (mainWindow.Width < p1) { mainWindow.ToolbarWrapper.HorizontalAlignment = HorizontalAlignment.Left; mainWindow.ToolbarWrapper.Margin = new Thickness(10, 10, 80, 0); // ツールバー縮小 //int p2 = 290; //if(mainWindow.Width < p2 ) //{ // double scale = mainWindow.Width / ( p2 + 50 ); // this.mainWindow.ToolbarWrapper.LayoutTransform = new ScaleTransform(scale, scale); //} //else //{ // this.mainWindow.ToolbarWrapper.LayoutTransform = new ScaleTransform(1.0, 1.0); //} } else { mainWindow.ToolbarWrapper.HorizontalAlignment = HorizontalAlignment.Center; mainWindow.ToolbarWrapper.Margin = new Thickness(10, 10, 10, 0); // ツールバー等倍 this.mainWindow.ToolbarWrapper.LayoutTransform = new ScaleTransform(1.0, 1.0); } // マウスボタンが押されているか(リサイズ中かどうか)チェック short stateL = Win32.GetKeyState(Win32.VK_LBUTTON); short stateR = Win32.GetKeyState(Win32.VK_RBUTTON); if ((stateL & 0x8000) != 0 || (stateR & 0x8000) != 0) { return; } // 現在座標(スクリーン上の) Win32.POINT pt = new Win32.POINT(); Win32.GetCursorPos(ref pt); // スクリーン上のカーソル下のプロセスが、このアプリのものであるかチェック IntPtr hwnd = Win32.WindowFromPoint(pt); int pid = Win32.GetPidFromHwnd((int)hwnd); if (this.processId == 0) { this.processId = Win32.GetPidFromHwnd((int)new WindowInteropHelper(mainWindow).Handle); } if (pid != this.processId) { HideAllUI(); uIVisibleTimer.Stop(); return; } // カーソル下がMenuItem等の場合はreturn IntPtr hwndThis = new WindowInteropHelper(mainWindow).Handle; if (hwnd != hwndThis) { return; } // 一定時間のカーソル停止を検知して、タイマーを止める。カーソルも隠す Point d = new Point(Math.Abs(pt.X - ptCursorPause.X), Math.Abs(pt.Y - ptCursorPause.Y)); if (!isCursorPaused && d.X == 0 && d.Y == 0) { cursorPauseTime += 1; if (cursorPauseTime > 15) // 1.5 sec { if (mainWindow.Setting.MouseCursorAutoHide) { if (!pf.IsFullScreenMode.Value && mainWindow.Setting.MouseCursorAutoHideInFullScreenModeOnly) { mainWindow.Cursor = null; } else { mainWindow.Cursor = Cursors.None; } } isCursorPaused = true; this.uIVisibleTimer.Stop(); return; } } else { mainWindow.Cursor = null; ptCursorPause.X = pt.X; ptCursorPause.Y = pt.Y; cursorPauseTime = 0; isCursorPaused = false; } // カーソル位置によってUIの表示を変える Point ptWnd = Win32.GetWindowPos(hwndThis); var h3 = mainWindow.Height / 3; var w3 = mainWindow.Width / 3; // 拡大パネル内ファイル情報表示時 TileExpantionPanel panel = mainWindow.TileExpantionPanel; if (panel.IsShowing) { // ツールバー、シークバーは常に隠す mainWindow.ToolbarWrapper.Visibility = Visibility.Collapsed; HideSeekbar(); // 上部 1/3 if (pt.Y < ptWnd.Y + h3) { mainWindow.SystemButtonWrapper.Visibility = Visibility.Visible; } else { mainWindow.SystemButtonWrapper.Visibility = Visibility.Collapsed; } // 下部 1/3 if (pt.Y > ptWnd.Y + (2 * h3)) { panel.ToolbarWrapper.Visibility = Visibility.Visible; mainWindow.PageInfo.Visibility = Visibility.Visible; } else { panel.ToolbarWrapper.Visibility = Visibility.Collapsed; mainWindow.PageInfo.Visibility = Visibility.Collapsed; } return; } // ツールバー、システムボタン double borderHeight = mainWindow.ToolbarWrapper.ActualHeight + mainWindow.ToolbarWrapper.Margin.Top; if (pt.Y < ptWnd.Y + h3 || pt.Y < ptWnd.Y + borderHeight) { mainWindow.ToolbarWrapper.Visibility = Visibility.Visible; mainWindow.SystemButtonWrapper.Visibility = Visibility.Visible; } else { if (!mainWindow.IsAnyToolbarMenuOpened) { mainWindow.ToolbarWrapper.Visibility = Visibility.Hidden; } mainWindow.SystemButtonWrapper.Visibility = Visibility.Hidden; } // シークバー if (mainWindow.Setting.TempProfile.IsHorizontalSlide) { // 水平 if (pt.Y > ptWnd.Y + h3 * 2) { ShowSeekbar(); } else { HideSeekbar(); } } else { // 垂直 if (pt.X > ptWnd.X + w3 * 2) { ShowSeekbar(); } else { HideSeekbar(); } } }
public IntPtr HwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WM_MOUSEMOVE) { //Debug.WriteLine("WM_MOUSEMOVE"); // カーソル停止からの復帰 if (isCursorPaused) { Win32.POINT pt = new Win32.POINT(); Win32.GetCursorPos(ref pt); if (pt.X != ptCursorPause.X && pt.Y != ptCursorPause.Y) { mainWindow.Cursor = null; isCursorPaused = false; cursorPauseTime = 0; this.uIVisibleTimer.Start(); } } } if (msg == WM_NCACTIVATE) { // wParam:アクティブになった時1 非アクティブになった時0 // lParam: 非アクティブにさせたウインドウハンドル Debug.WriteLine("WM_NCACTIVATE " + "wParam: " + wParam + " lParam: " + lParam); // ウインドウ切り替えにより、非アクティブにした時に、非アクティブ用の枠を表示させない if (lParam == new IntPtr(0)) { handled = true; return(new IntPtr(0)); } else { if (wParam != new IntPtr(0)) { // フォルダ指定ダイアログ等を表示した為、非アクティブになり、戻った時 // 再描画し、非アクティブ用のウインドウ枠を消す // handled をtrueにしない(するとフリーズしてしまう) Win32.InvalidateRect(hwnd, IntPtr.Zero, false); return(new IntPtr(0)); } } //this.mainWindow.Dispatcher.Invoke(DispatcherPriority.Render, // new Action( () => { })); //mainWindow.UpdateWindowSize(); //Win32.PostMessage(hwnd, WM_SIZING, new IntPtr(0), new IntPtr(0)); } if (msg == WM_NCCALCSIZE) { // クライアント領域を、ウインドウ枠を覆うまで広げる handled = true; return(new IntPtr(0)); } if (msg == WM_NCHITTEST) { // カーソル停止中は処理しない if (isCursorPaused) { handled = false; return(new IntPtr(HTCLIENT)); } // handled により、MouseEnterが呼ばれない為、ここでUI表示 if (!uIVisibleTimer.IsEnabled) { //ShowExceptToolbar(); uIVisibleTimer.Start(); this.UIVisibleTimer_Ticked(this, null); } // これ以上処理させない(完全に処理を横取りする) handled = true; // フルスクリーンモード中はリサイズの必要がないので、リターン if (mainWindow.Setting.TempProfile.IsFullScreenMode.Value) { handled = false; return(new IntPtr(HTCLIENT)); } // クライアント座標のマウス位置を取得 Point ptScreen = new Point((int)lParam & 0xFFFF, ((int)lParam >> 16) & 0xFFFF); Point ptClient = mainWindow.PointFromScreen(ptScreen); // リサイズ可能と判断するサイズ //double bh = SystemParameters.ResizeFrameHorizontalBorderHeight; //double bw = SystemParameters.ResizeFrameVerticalBorderWidth; //double captionH = SystemParameters.CaptionHeight; double bh = 10; double bw = 10; // 四隅の斜め方向リサイズが優先 int hit = -1; if (new Rect(0, 0, bw, bh).Contains(ptClient)) { hit = HTTOPLEFT; } else if (new Rect(mainWindow.Width - bw, 0, bw, bh).Contains(ptClient)) { hit = HTTOPRIGHT; } else if (new Rect(0, mainWindow.Height - bh, bw, bh).Contains(ptClient)) { hit = HTBOTTOMLEFT; } else if (new Rect(mainWindow.Width - bw, mainWindow.Height - bh, bw, bh).Contains(ptClient)) { hit = HTBOTTOMRIGHT; } // 四辺の直交方向リサイズ else if (new Rect(0, 0, mainWindow.Width, bw).Contains(ptClient)) { hit = HTTOP; } else if (new Rect(0, 0, bw, mainWindow.Height).Contains(ptClient)) { hit = HTLEFT; } else if (new Rect(mainWindow.Width - bw, 0, bw, mainWindow.Height).Contains(ptClient)) { hit = HTRIGHT; } else if (new Rect(0, mainWindow.Height - bh, mainWindow.Width, bh).Contains(ptClient)) { hit = HTBOTTOM; } if (hit != -1) { //return new IntPtr(HTCLIENT); return(new IntPtr(hit)); } // ドラッグ移動可能な領域を指定 //if (new Rect(0, 0, Width, captionH).Contains(ptClient)) return new IntPtr(HTCAPTION); // 上記以外はクライアント領域と判断 handled = false; return(new IntPtr(HTCLIENT)); } /* ---------------------------------------------------- */ // メインウインドウ アス比固定処理 /* ---------------------------------------------------- */ if (msg == WM_SIZING && !mainWindow.Setting.TempProfile.NonFixAspectRatio.Value) { RECT r = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT)); int w = r.right - r.left; int h = r.bottom - r.top; w -= (int)mainWindow.MainContent.Margin.Left * 2; h -= (int)mainWindow.MainContent.Margin.Top * 2; int dw = (int)(h * mainWindow.MainContentAspectRatio + 0.5) - w; int dh = (int)(w / mainWindow.MainContentAspectRatio + 0.5) - h; switch (wParam.ToInt32()) { case WMSZ_TOP: case WMSZ_BOTTOM: r.right += dw; break; case WMSZ_LEFT: case WMSZ_RIGHT: r.bottom += dh; break; case WMSZ_TOPLEFT: if (dw > 0) { r.left -= dw; } else { r.top -= dh; } break; case WMSZ_TOPRIGHT: if (dw > 0) { r.right += dw; } else { r.top -= dh; } break; case WMSZ_BOTTOMLEFT: if (dw > 0) { r.left -= dw; } else { r.bottom += dh; } break; case WMSZ_BOTTOMRIGHT: if (dw > 0) { r.right += dw; } else { r.bottom += dh; } break; } Marshal.StructureToPtr(r, lParam, false); } return(IntPtr.Zero); }