まず結論としてWindowPos->flagsは動作を指定するフラグであって
操作された動作を表すフラグではない。
なので、ウインドウサイズ変更か、位置変更かと言うことは
自前で判定してやる必要がある。
な〜の〜で WMWindowPosChanginがきたときのウインドウ矩形
を取得し、その値とWindowPosの値をそれぞれ比較してやるわけである
それをフラグとして、位置が変わっていたならば位置補正を
サイズが変わっていたらサイズ補正を行う
さらに、思うに、デスクトップの周りに張り付くパターンと
ウインドウの外に張り付くパターンと、中から張り付くパターンは
全部別である、そしてそれぞれに対して、ウインドウ移動+サイズ移動問題
が存在する。
まずは外周パターンを考える、サイズ補正と、位置変更はサイズ補正をまず行う
(記述の右側、左側とかは全て、補正するウインドウを基準と考える)
変数は
WINDOWPOS *pos :WM_WindowPosChangingでキタやつ
RECT desktop:デスクトップ外周矩形
サイズ補正
左側: pos->cx = pos->cx - (desktop.left - pos->x) ;
右側: pos->cx = pos->cx + (desktop.right - (pos->x + pos->cx));
上側: pos->cy = pox->cy - (desktop.top - pos->x);
下側: pos->cy = pos->cy + (desktop.bottom - (pos->y +
pos->cy));
位置補正
左側: pos->x = desktop.left
右側: pos->x = desktop.right - pos->cx
上側: pos->y = desktop.top
下側: pos->y = desktop.bottom - pos->cy
これでいけるはずである。
次に対象が別ウインドウで外側からくっつくパターン
サイズ補正
左側: pos->cx = pos->cx - (target.right - pos->x);
右側: pos->cx = pos->cx + (target.left - (pos->x + pos->cx));
上側: pos->cy = pos->cy - (target.bottom - pos->y);
下側: pos->cy = pos->cy + (target.top - (pos->y + pos->cy));
位置補正
左側: pos->x = pos->x - (pos->x - target->right) = target->right;
右側: pos->x = pos->x + (target->left - (pos->x + pos->cx))
= target->left - pos->cx;
上側: pos->y = target->bottom;
下側: pos->y = target->top - pos->cy;
次に内側パターン
内側パターンと言うのはすでに外側でスナップしている場合に、対象ウインドウの
内側から、ぴたっと吸い付く動作である
例えば自分の右側が、相手の左側についていて
その状態で自分を上下させた場合に、自分の上か下のどちらかが
相手の上か下に吸い付く、(必ずしも判定としては内側でもないか(ぉ)
そしてこれはデスクトップ外周とスナップするかの判定式が
違うだけで、補正動作自体は同じであるので
サイズ補正
左側: pos->cx = pos->cx - (target.left - pos->x) ;
右側: pos->cx = pos->cx + (target.right - (pos->x + pos->cx));
上側: pos->cy = pox->cy - (target.top - pos->x);
下側: pos->cy = pos->cy + (target.bottom - (pos->y + pos->cy));
位置補正
左側: pos->x = target.left
右側: pos->x = target.right - pos->cx
上側: pos->y = target.top
下側: pos->y = target.bottom - pos->cy
と言うわけでこれで実装してみようと思う
問題はサイズ移動、位置移動の操作判定を何処で行うかと言うことかな・・