酢ろぐ!

カレーが嫌いなスマートフォンアプリプログラマのブログ。

Windows MobileでのScrollWindowEx関数を使ったときの駄目な例

OnMouseMoveメソッドで移動した量だけをスクロールさせたコード。でも条件が仕様上使えなさげ。

|cs| Rectangle clip; if (scrollHeightEx > 0) { // 下方向へスクロール clip = new Rectangle(0, 0, this.Width - ScrollBarWidth, this.Height - Math.Abs(scrollHeightEx)); } else if (scrollHeightEx < 0) { // 上方向へスクロール clip = new Rectangle(0, Math.Abs(scrollHeightEx), this.Width - ScrollBarWidth, this.Height - Math.Abs(_scrollHeightEx)); } else { clip = new Rectangle(0, 0, this.Width - ScrollBarWidth, this.Height); }

Platform.Win32.ScrollWindow(this.Handle, 0, _scrollHeightEx, clip);

||<

あ。ScrollWindowExのP/Invoke宣言はこんな感じ。時間が出来たらきちんとまとめます。

|cs| const int SW_INVALIDATE = 0x0002;

[DllImport("coredll.dll")]
static unsafe extern Int32 ScrollWindowEx(IntPtr window, int x, int y, RECT* scroll, RECT* clip, IntPtr updateRegion, RECT* update, UInt32 flags);
public static void ScrollWindow(IntPtr window, int x, int y)
{
    unsafe
    {
        ScrollWindowEx(window, x, y, null, null, IntPtr.Zero, null, SW_INVALIDATE);
    }
}
public static void ScrollWindow(IntPtr window, int x, int y, Rectangle clipRect)
{
    unsafe
    {
        RECT clip = new RECT(clipRect);
        ScrollWindowEx(window, x, y, &clip, &clip, IntPtr.Zero, null, SW_INVALIDATE);
    }
}

||<