none
How to access the windows taskbar to create an own contextmenu for minimized windows RRS feed

  • Question

  • Hi everyone,

    I made a custom control which gives me the possibility of a custom border and a custom controlbox for my window.

    Unfortunately this control requires an underlying borderless form. If I minimize the form and perform a rightclick on the minimized window in the taskbar there doesn't occur a contextmenu.

    Of course that's normal because a borderless form doesn't have such a contextmenu.

    Currently I'm searching after a possibilty to get the exactly location of the minimized rectangle in the taskbar. If I can get the location I could simply react by myself on the left mouseclick and so I could show the contextmenu.

    I know that there exist an sdk for win7 to manage the access to the taskbar. But I want to be compatible the the older windows versions too.

    I hope you understand my purpose.

     

    Greets

    Q-Tec

    EDIT:

    Sry didn't saw the sticky post that this isn't the forum for gui question.

    @Mods: Please move me to the right forum. Thanks


    Dev86 Technical Blog


    • Edited by Q-tec Monday, September 26, 2011 9:42 AM
    Monday, September 26, 2011 9:37 AM

Answers

  • Hi Q-tec,

    Welcome to MSDN Forum.

    Control.WndProc Method processes windows messages. All messages are sent to the WndProc method after getting filtered through the PreProcessMessage method.

    Please Try this:

    const int WM_TASKBARCLICK = 0x0313;

    protected override void WndProc(ref Message m)

    {

        // Listen for operating system messages.

        switch (m.Msg)

        {

            // The WM_TASKBARCLICK message occurs when Right click taskbar

            case WM_TASKBARCLICK:

                {

                    int x = Cursor.Position.X - this.Location.X;

                    int y = Cursor.Position.Y - this.Location.Y;

     

                    Point displayPoint = new Point(x, y);

                    this.contextMenu1.Show(this, displayPoint);

                    break;

                }

        }

        base.WndProc(ref m);

    }

     

    In fact, if you want to get the system contextmenu back, you just need to insert the code below in your source code:

    protected override CreateParams CreateParams

    {

        get

        {

            CreateParams cp = base.CreateParams;

            cp.Style |= 0x80000;  // Turn on WS_SYSMENU

            return cp;

        }

    }

     

    Hope this may help.

    Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Q-tec Thursday, September 29, 2011 7:29 AM
    Tuesday, September 27, 2011 9:51 AM
    Moderator
  • Hi Q-tec,

    In Windows Vista and Windows 7, use Shift +Right click instead of Right click.

    Hope this may help.

    Regards,
    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Q-tec Thursday, October 6, 2011 12:08 PM
    Thursday, October 6, 2011 5:46 AM
    Moderator

All replies

  • Hi Q-tec,

    Welcome to MSDN Forum.

    Control.WndProc Method processes windows messages. All messages are sent to the WndProc method after getting filtered through the PreProcessMessage method.

    Please Try this:

    const int WM_TASKBARCLICK = 0x0313;

    protected override void WndProc(ref Message m)

    {

        // Listen for operating system messages.

        switch (m.Msg)

        {

            // The WM_TASKBARCLICK message occurs when Right click taskbar

            case WM_TASKBARCLICK:

                {

                    int x = Cursor.Position.X - this.Location.X;

                    int y = Cursor.Position.Y - this.Location.Y;

     

                    Point displayPoint = new Point(x, y);

                    this.contextMenu1.Show(this, displayPoint);

                    break;

                }

        }

        base.WndProc(ref m);

    }

     

    In fact, if you want to get the system contextmenu back, you just need to insert the code below in your source code:

    protected override CreateParams CreateParams

    {

        get

        {

            CreateParams cp = base.CreateParams;

            cp.Style |= 0x80000;  // Turn on WS_SYSMENU

            return cp;

        }

    }

     

    Hope this may help.

    Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Q-tec Thursday, September 29, 2011 7:29 AM
    Tuesday, September 27, 2011 9:51 AM
    Moderator
  • Hi,

    thank you. That's exactly what I searched :).

     

    Greets

    Q-Tec


    Dev86 Technical Blog
    Thursday, September 29, 2011 7:31 AM
  • Hi,

    sry for doublepost but this solution doesn't seems to work above windows xp.

    I've tested it on windows xp where it works great.

    But it doesn't work at Windows Vista and Windows 7. Any idea why it doesn't work?

    Greets

    Q-Tec


    Dev86 Technical Blog
    • Edited by Q-tec Friday, September 30, 2011 4:06 PM
    Friday, September 30, 2011 4:06 PM
  • Hi Q-tec,

    In Windows Vista and Windows 7, use Shift +Right click instead of Right click.

    Hope this may help.

    Regards,
    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Q-tec Thursday, October 6, 2011 12:08 PM
    Thursday, October 6, 2011 5:46 AM
    Moderator