Drag a window without a system title bar

Source: Internet
Author: User
Tags integer

In VB, you can create a window without a system title bar by setting the properties of the form. However, because of the loss of the system title bar, how to use the mouse to drag the window becomes a thorny issue. In fact, with the help of API functions ReleaseCapture and SendMessage, this problem can be solved.

First, add the following declaration statement to the module file:

  Declare Sub ReleaseCapture Lib"User"()
 
   Declare Function SendMessage Lib"User"(ByVal hWnd _
As Integer,ByVal wMsg As Integer,ByVal wParam As Integer,_lParam As Any)As Long
 
   Public Const WM_SYSCOMMAND=&H112
 
   Public Const SC_MOVE=&HF010
   Public Const HTCAPTION=2
 
   然后,在Form的MouseDown事件中加入下列代码:
 
   ReleaseCapture
 
   Ret&=SendMessage(Me.hWnd,WM_SYSCOMMAND,_SC_MOVE+HTCAPTION,0)
 
   ……

When the program is running, you can drag the window as soon as the cursor falls in the form area while holding down the left mouse button. In the design of programs that require a lively interface, developers often want a unique title bar in their own style to meet the requirements of the entire interface. By this method, you can make homemade title bar to achieve the point of genuine. However, a control that is used as a homemade title bar must have a MouseDown event to display the above code.

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.