これは、Windows デベロッパー センターに投稿した質問の複製です。まだ返事待ちなので、こちらでやってみようと思います。フォーマットがうまくいかない場合は、お詫び申し上げます。
これは現在、Windows 7 Professional SP1 を使用して記述およびデバッグされています。
アプリケーションはデスクトップの上部にあり、作業領域は SystemParametersInfo 関数へのフックを介して適切にサイズ変更されます。MenuStrip は、MenuStrip からのドロップダウンが MenuStrip 自体から切り離されて表示されることを除いて (MenuStrip を含むフォームではなく、新しい作業領域に描画されているかのように) 表示されます。例えば:
- アプリケーションのトップレベル: true
- 適用高さ: 150
- アプリケーションの場所: デスクトップで 0,0 (作業領域のサイズ変更前)
- メニューストリップの高さ: 25
- MenuStrip の場所: 親フォーム内の 0,0
- MenuStrip DropDown Location: x,2 (x は有効で許容可能な値)サイズ変更された作業領域 (つまり、フォームの下) に描画されます。
カスタムレンダラーでこれを修正しようとしましたが、現在は役に立ちません。正確に何が起こっているかを確認するために、(次のように) WndProc をオーバーライドしようとしましたが、アプリケーションの描画の途中でスタックオーバーフローが発生しました。
protected override void WndProc(ref Message m)
{
if (mainForm.Visible)
{
MessageBox.Show("ID: " + m.Msg.ToString() + "\n" + m.ToString());
}
base.WndProc(ref m);
}
私はこれまでにこれを実行したと思いますが、さらに説明が必要な場合はお知らせください. どこを見ればよいか、誰かが私を適切な方向に向けてくれることを願っています。
SystemParametersInfo を使用した理由に関する質問にこれが答えてくれることを願っています。
#region TEMPORARY FIX TO ACHIEVE APPBAR
public RECT normalWorkingRECT = new RECT();
public RECT newWorkingRECT = new RECT();
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
};
[DllImport("user32.dll", EntryPoint="SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref RECT pvParam, uint fWinIni);
//call after scale is set
private void setAppBar()
{
//make the parent = the desktop
if (!this.GetTopLevel())
{
this.SetTopLevel(true);
}
this.Width = SystemInformation.PrimaryMonitorSize.Width;
//set old Working Area
SystemParametersInfo(0x0030, 0, ref normalWorkingRECT, 0);
//change work area based on size of main form
newWorkingRECT.left = normalWorkingRECT.left;
newWorkingRECT.top = normalWorkingRECT.top + this.DesktopBounds.Height + 4;
newWorkingRECT.right = normalWorkingRECT.right;
newWorkingRECT.bottom = normalWorkingRECT.bottom;
SystemParametersInfo(0x002F, 0, ref newWorkingRECT, 0x0002);
}
//called on close
private void unsetAppBar()
{
//get current work area to compare
RECT testRECT = new RECT();
SystemParametersInfo(0x0030, 0, ref testRECT, 0);
//if no change, resize to normal working rect
if (newWorkingRECT.top == testRECT.top &&
newWorkingRECT.bottom == testRECT.bottom &&
newWorkingRECT.left == testRECT.left &&
newWorkingRECT.right == testRECT.right)
{
SystemParametersInfo(0x002F, 0, ref normalWorkingRECT, 0x0002);
}
//if there is a change, resize to current working rect - this.height
else
{
testRECT.top -= this.DesktopBounds.Height + 4;
SystemParametersInfo(0x002F, 0, ref testRECT, 0x0002);
}
}
#endregion
編集: 要求に応じて画像を追加し、SystemParametersInfo の理由を示すコードを追加しました。