jonny
jonny

Reputation: 736

Custom form designer, move/resize controls using WinAPI

I have to fix some problems and enchance form designer written long ago for a database project. In Design Panel class code I encountered these lines

private void DesignPanel_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        (sender as Control).Capture = false;
        switch (FMousePosition)
        {
        case MousePosition.mpNone: 
            SendMessage((sender as Control).Handle, WM_SYSCOMMAND, 0xF009, 0);
            break;// Move
        case MousePosition.mpRightBottom: 
            SendMessage((sender as Control).Handle, WM_SYSCOMMAND, 0xF008, 0);
            break;//RB
        case MousePosition.mpLeftBottom: 
            SendMessage((sender as Control).Handle, WM_SYSCOMMAND, 0xF007, 0); 
            // ... here are similar cases ...
        case MousePosition.mpLeft:
            SendMessage((sender as Control).Handle, WM_SYSCOMMAND, 0xF001, 0);
            break;//L  
        }
    }
}

FMousePosition indicates whether mouse was over any edge of selected control.

What confusing me is these windows messages: it seems there is no documentation on WM_SYSCOMMAND with parameters 0xF001-0xF009 (maybe it starts some kind of 'drag/resize sequence'). Any ideas?

If my suggestion is right, then how can I cancel these sequences?

Upvotes: 1

Views: 3022

Answers (2)

stukelly
stukelly

Reputation: 4307

They are undocumented parameters. After searching I managed to find this list.

  • 0xF000 (SC_SIZE, Center cursor on the form)
  • 0xF001 (SC_SZLEFT, Resize from left)
  • 0xF002 (SC_SZRIGHT, Resize from right)
  • 0xF003 (SC_SZTOP, Resize from top)
  • 0xF004 (SC_SZTOPLEFT, Lock the bottom right corner of the form, the top left corner move for resize)
  • 0xF005 (SC_SZTOPRIGHT, Same from bottom left corner)
  • 0xF006 (SC_SZBOTTOM, Lock top right and left border, resize bottom)
  • 0xF007 (SC_SZBOTTOMLEFT, Lock top and right border, resize other border)
  • 0xF008 (SC_SZBOTTOMRIGHT, Lock left and top border and resize other)
  • 0xF009 (SC_SIZE|0x9, Drag from anywhere)
  • 0xF00F (SC_SEPARATOR)
  • 0xF010 (SC_MOVE, Put cursor centered at the upper order)
  • 0xF012 (SC_DRAGMOVE, move by dragging)
  • 0xF020 (SC_MINIMIZE, Auto-Minimize Form)
  • 0xF030 (SC_MAXIMIZE, Auto-Maximize Form)
  • 0xF040 (SC_NEXTWINDOW, Stop! You don't want that, it will lock all mouse click and make you reboot)
  • 0xF148 (SC_SCREENSAVE|0x8, Activate ScreenSaver)
  • 0xF13E (SC_TASKLIST|0xE, Activate StartButton)

Reference: http://www.delphi3000.com/articles/article_1054.asp#Comments

Upvotes: 4

Andy Dent
Andy Dent

Reputation: 17971

Based on my Win32 Programming (Rector and Newcomer) p902-903 explains WM_SYSCOMMAND is sent when the user selects an item from the system menu (rather than sending the normal WM_COMMAND).

The MSDN help says SC_SIZE = 0xF000 and it and Win32 Programming also say Windows uses the four low-order bits of the predefined system menu IDs internally but doesn't go on to clarify their use. Thanks stukelly for clarifying them.

Upvotes: 1

Related Questions