2

This is a duplicate of a question I posted at Windows Dev Center. Still awaiting replies, so I thought I would try it here. My apologies if the formatting goes awry.

This is currently being written and debugged using Windows 7 Professional, SP1.

The application is located at the top of the desktop, and the working area is appropriately resized via a hook into the SystemParametersInfo function. The MenuStrip appears as it should, with the exception that any dropdown from the MenuStrip shows as detached from the MenuStrip itself (as if it is being drawn on the new working area, as opposed to the form containing the MenuStrip). For example:

  • Application TopLevel: true
  • Application Height: 150
  • Application Location: 0,0 on Desktop (prior to working area's resize)
  • MenuStrip Height: 25
  • MenuStrip Location: 0,0 inside Parent Form
  • MenuStrip DropDown Location: x,2 (where x is a valid and acceptable value) this is being drawn on the resized working area (i.e. beneath the form)

I have attempted correcting this with a custom Renderer to no present avail. I tried to override WndProc (as follows) so as to see what exactly was occurring, but that resulted in a stackoverflow halfway through drawing the application.

protected override void WndProc(ref Message m)
{
    if (mainForm.Visible)
    {
        MessageBox.Show("ID: " + m.Msg.ToString() + "\n" + m.ToString());
    }
    base.WndProc(ref m);
}

I suspect I've run this into the ground by now, but if you require any further explanation, just let me know. Just hoping someone can point me in the appropriate direction as to where I should look.


Hopefully this will answer the question regarding why I used 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

Cropped Screenshot of the issue.

EDIT: Added image as requested and code to show reason for SystemParametersInfo.

4

0 回答 0