Realization of Intelligent ABC window

Source: Internet
Author: User
Tags bool manual valid

The Advanced top-level window is a frequently-used top-level window with no title bar, menu, or toolbar, and the most common example is an input window, such as the Smart ABC window. The characteristics of such a window, in addition to what is said above, the most important thing is the window movement. Ordinary window movement is through the title bar by the system automatically, for such windows can not rely on the system, the need for manual implementation. There are two ways to implement this:

Manual processing of Wm_move, wm_lbuttonup messages, and according to the mobile mouse to achieve the window to move the process of drawing;

In the Wm_move message processing function, the window movement process is implemented by the system by sending the wparam for the Htcaption lparam The Wm_nclbuttondown message for the mouse position.

Obviously, the latter is simpler than the former. This article uses the latter.

In order to move, you also define a valid mobile area for the window, that is, when you move the mouse to which part of the window, the mouse changes to a cross arrow, suggesting that you can now press the left button to start dragging. There are four tightly-arranged bitmap "buttons" in the windows of this article, and there is no space between them, so I define the window within the bitmap to be a valid moving region. When the mouse enters this area, it changes to a cross arrow shape, prompting the user to drag now.

When you define a window class, if the window has a border, then when the mouse is on the border, receive the Wm_ncmousemove message, so in order to be unified in the WM_MOUSEMOVE message processing function, this window does not use a border, as long as the mouse into the window, you begin to receive the WM_ MouseMove the news. But this introduces another question: How do I draw a 3D border? This article uses the function:

void Draw3dRect( LPCRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight)

Enables the drawing of a 3D border.

The basic principle of this article:

Derive a window class Cmainwnd directly from the CWnd and add a common function bool Createmainwnd () to create the window;

In the corresponding WM_PAINT, four bitmaps are plotted according to four marker variables in the client area.

In WM_LBUTTONDOWN message processing, detects whether the mouse falls into a "button" bitmap, sets the corresponding flag, and forces the system to redraw the client area;

In WM_MOUSEMOVE message processing, detects whether the mouse falls into a valid moving area and sets the corresponding cursor. If the left button is pressed, it starts to send Wm_nclbuttondown message and realizes the window moving;

In order to close the window, this program set the accelerator key F12, press F12 can close the program;

The code is as follows:

1. Create window:

bool CMainWnd::CreateMainWnd(void)
  {
    if(!CreateEx(0,
          ::AfxRegisterWndClass(0,
                     ::LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)),
                     GetSysColorBrush(COLOR_ACTIVEBORDER)
                     ),
           NULL,
           WS_POPUP,
           0,0,300,50,
           NULL,
           NULL))
      return false;
   return true;
  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.