Win32API lecture 3

xiaoxiao2021-03-06  40

Third lesson: Window function 1. About window functions in the last class, we have proposed the concept of "handle" and conduct more depth discussions. Now I want to add, I have to add that the handle is not only the window. It seems that all Windows objects have handles. For example, the brush, brush, etc. in the GDI object, soon the equipment scene to learn, etc., there is also its own handle, and so on. However, unlike some controls, these objects do not belong to the window. What is a window? There is a very interesting thing: if it is on the screen, then it is definitely in a window; if it is not on the screen, it may still be in one window. The form is also a window; the scroll bar, the list box, the text box, and even the shortcuts on the desktop are also windows. More interesting is that the desktop as a background is also a window. Many controls basically provide HWND properties, but there is no available. For these controls, you can use the setFocus method to set the input focus to the control, then use the API function getFocus to get the handle of the window with the focus. Of course, this process should be written in the Gofocus event. There is an interesting thing in the question I have encountered Yes, the HWnd attribute of the IE control provided by VB does not care. I generally be solved by the above method. Many windows functions can operate any form of the system. This means that the VB program can directly manipulate other forms that are running. Everyone knows that if the procedure for VB is designed to do special processing, then we can start multiple this application instance. We can use the API window function to determine if a preparation of a form is running, so that if a precedent is stopped, stop starting. Many applications look like this. For example, in the four-way Chinese platform, the program will tell the user "The Four-way Pipe is already running" and stops starting. The window function can be divided into four types (perhaps "this is" more suitable for this classification ": 1, window grading function; 2, window location and size function; 3, window information function; 4 , Other window functions. Let's talk about it one by one. However, due to the more window functions, discussions are discussed here. About the window function, how is the specific usage, you can pay attention to the technical documentation of the VB API site of "Xiaoyan", or the WinAPI help in this site. Since its contents are from the website of "Xiaoyan", it will be more late. Second, the window running in the window grading function system is a level of high and low. Who doesn't know this? This is of course nonsense. Many articles are similar to this nonsense to be a speech. I am just learning here. First, the father and child relationship. Each window may have its own parent window and sub-windows. However, the window running in the system is limited, indicating that there is a window that has a window, and we call it top window. Generally, a primary window of an application is a top window, VB standalone form and MDI form are top-level windows. The parent child relationship between the window generally follows the rules: 1. When the parent window is displayed, all the visible sub-windings in which the inclusive it is in which all the visible sub-windows are displayed as the parent window. 2, when the parent window hides, all the sub-windings in which the package is hidden with the hidden parent window. 3, when the parent window is uninstalled, ha, you already know what I want to say, of course: follow the automatic uninstallation. 4. When the parent window moves, follow. Second, the brother relationship and the Z sequence of course, a father has several children, all are common. Similarly, a parent window can have multiple subforms. For example, the relationship between various controls between a form and the sub-windows of the MDI window.

The parent window is displayed, hidden, uninstall, and movement of the sub-window, and its order is obvious. So what is the situation between the brothers window? Obviously, two two sub-forms that overlap each other cannot also display its full picture, naturally there is a sequential rule of display. This sequence rule is called a Z sequence. There is an explanation that if the screen consisting of the screen coordinates is the plane of the X and Y axes (in fact, it is true), as a three-dimensional coordinate system Z-axis can be seen as a shaft perpendicular to the screen. In this way, it can be considered that all windows on the screen are perpendicular to this z-axis. On the z-axis, who is in front, who is after, there is a z-sequence. Very vivid! The Z sequence can be controlled with the Windows API function and the Visual Basic z sequence method. With the simple knowledge above, we are not difficult to apply the API window grading function, mainly below: Window grading function function name indicating that FindWindow is looking for a window FindWindowEx is similar to findwindow. More Features GetLastactivePopup Retrieves the handle of the previous active pop-up window to get the handle GetTopWindow get the handle GetTopWindow for the specified window parent window getwindow's handle getWindow, such as given a window handle, this The function can retrieve another handle of another window with a specific relationship. For example, the first sub-window, the parent window, or the previous window in the window list. SetParent changes the parent window of any window. From my personal experience, I am most commonly used is getWindow and setParent functions. Third, the window position and the size function Windows API function is basically (especially those in the user32.dll dynamic connection library) with screen pixels as metric. This is important, you must keep in mind. To do this, when using the API function, we often set the SCALEMODE property of the form or picture frame control to 3, ie VBPixels. The key to understanding the location and size function is three concepts of distinguishing screen coordinates, window coordinates, and customer coordinates. The following figure shows the relationship between the three coordinate systems. Screen, window and customer zone coordinate system As long as the coordinates have a clear concept, it is not difficult to use the window position and size function. About the location of the window, some functions returned to the Rect structure in the previous class. About window location and size functions are listed in the following table: Window location and size function function name to illuminate BringWindOWTOP Enable the specified window to enter the top of the visible window list, if it is partially or completely hidden, it is all visible. At the same time, the window has become the current active window. It is only effective when you call from the front line. ChildWindowFromPoint acquires the handle (if any) of the specified coordinates, the coordinates here refer to the coordinates of the client area relative to the parent window. ChildWindowFromPointex is the same as ChildWindowFromPoint, which is more functional. ClientToscreen determines the screen coordinates of the specified point in the window client area. GetClientRect A rectangle (RECT) that is expressed in the window client area. This is a simple way to determine the size of the customer area in pixels. GetWindowPlacement gets a Windowplacement structure of the specified window. This structure illustrates the state of the window.

GetWindowRect is used to obtain a rectangular structure that describes the location of the form in the screen coordinate system. MapWindowPoint converts one or more points in a window client zone, represented by a client area coordinate of another window. MoveWindow moves the location of the specified window and change its size. OpenICON recovers a minimization window to the original state. ScreenToClient indicates it in a specified point in the screen, indicates it with a client area within a particular window. SetWindowsPOS changes the location and size of the window and can modify its location within the internal window list (this list is first in the control window first). SetwindowPlacement Sets the feature of a window on a Windowplacement structure. This structure describes the state of the window, and it is minimized, maximized, or normally displayed. WINDOWFROMPOINT determines which window is located below according to a specified point on the screen. The specific usage of the above functions can be found in WinAPI help. Among these functions, the SETWINDOWSPOS function is relatively high, and now many people use this function to implement the effect of "Window in the front", that is, put the window at the top of the list via HWND_TOPMOST constant. If you want From1 top of the list, as follows: SetWindowPos Form1.hWnd, HWND_TOPMOST, Form1.Left / Screen.TwipsPerPixelX, Fo rm1.Top / Screen.TwipsPerPixelY, Form1.Width / Screen.TwipsPerPixelX, Form1.Height / Screen. Twipsperpixely, 0 You can put this line code in the PAINT event. In addition, the getWindowRect function, the MoveWindow function, and the next class of the next classroom will be able to implement a window that drags the ringable bar. This is one of the skills you must master. Interested friends, you can go to the "frontline" "source analysis" section, download the Demo Procedure No. 4.

The following is the main part of the code :Private MyRect As RECTPrivate MyPoint As POINTAPIPrivate Movex As Long, Movey As Long Private Sub Image1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single) Dim dl & dl & = GetWindowRect (Form1.hwnd , MyRect) dl & = GetCursorPos (MyPoint) If Button = 1 Then Movex = MyPoint.X - MyRect.Left Movey = MyPoint.Y - MyRect.TopEnd IfEnd Sub Private Sub Image1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y askL & DL & = getCursorpos (MyPoint) if button = 1 THEN DL & = MoveWindow (Form1.hwnd, MyPoint.x - Movex, MyPoint.y - Movey, _ MyRect.right - MyRect.Left, MyRect.Bottom - MyRect.top, -1) Endness Sub In the MouseDown event, the program first use the getWindowRect function to determine the location of the window in the screen. Once again, it is the location of the GetCursorpos function in the screen. Thereby, the lateral direction and longitudinal distance between the mouse position and the upper left corner of the window can be obtained. Program continuously with the GetCursorpos function in the MouseMove event immediately, and is done directly in the MoveWindow function call according to the MoveX and Movey Decision window that has been obtained earlier, and this is done directly in the MoveWindow function call. The MOVEWINDOW function moves the form to a new location. Fourth, window information functions so-called window information function is used to get functions for the current status information about the window. Such functions mainly: Function, getClassInfo gets the class information structure of the specified window, the GetClassInfoEx effect is similar to getClassInfo, but adds some features getClasslong, getClassWord is used to obtain window class information setClasslong, setClassword uses window class information GetClassName Get window Class name getDesktopWind Get the entire desktop (screen) window handle GetWindowlong, getWindowWord Get information about the window for information setWindowLong, setWindowWord Settings information about the window. GetWindowText get window text. Its effect is substantially equivalent to the TEXT attribute of the form or control GetWindowTextLength obtains the length of the window text, represented by the number of characters. Ischild determines whether a window is a sub-window or a slave window for another window.

Isiconic determines if a window is in a minimized state IsWindow determined whether the specified handle is a window handle. IsWindowEnableD determines if the specified window is active. IsWindowVisible determines if a window is visible. Iszoomed determines if the window is in a maximized state. SetwindowText Settings Window Text. Generally equivalent to the text attribute of the form or control. Most window information functions are very well understood, in accordance with the function description in the relevant manual, according to the specified data type. It is necessary to explain that the style bits of classes and windows. Windows is a bit setting method with a long shaped data to record the style of the class and the window. Wherein, the window style is composed of a 32-bit style and another 32-bit extension style. The class style operation is performed by getClasslong and getClasslong in the above list, and the window style operation is performed by getWindowlong and SetWindowlong. Due to the large content of the style, I can't give it here, you can refer to the relevant manual. It is necessary to remind everyone that you want to change or get the style of the current window or class, most of the cases can consider style bit operations. Below, a simple example of this question will be explained. Below is the BS_LEFTText style bits to move the text of the VB check box or the option button on the left and right, and move the procedure (which is part of the supplied Program1.vbp). The principle of the program is simple. First get the information of the current style bit with the getWindowlong function, and then prepare the new style bit information by bit operation, and finally change it with SETWINDOWLONG. As follows: Dim f &, dl & f & = GetWindowLong (Option1.hWnd, GWL_STYLE) 'to obtain the current style bits of information If Index = 0 Then f & = f & Or BS_LEFTTEXT Else f & = f & And Not BS_LEFTTEXT End If dl & = SetWindowLong (Option1.hWnd, GWL_Style, F &) 'Sets new style bits Option1.refresh (for friends who are not familiar with the AND AND bit, please refer to the relevant technical information) here, the style is not performed more detailed discussion, mainly such a reason. After changing a style bit with a setwindowlong function, it will not cause a corresponding change in the window (at least no change immediately). Some style bits may change success during runtime, and most of them will only take effect when the window is created. Because, create a form with API has exceeded the scope of this tutorial, even if I talk about the style here, you may not have much place. At the same time, Microsoft did not tell us which style bits have been safely changed during operation, so they have to conduct specific tests on their specific situations. From my personal actual programming experience, there is no special requirement, we will not talk about these style bits, many of which can be easily implemented in VB. This tutorial also comes with a program2.vbp demo program. It is my own place to write, there is nothing special. I want to see it.

Finally, it is easy to mention that when using the setwindowlong function, change GWL_WndProc data is very dangerous (system or VB often hang), the location of the window function is changed. Typically, this change is applied in places that need subclass processing. Each time you trial running procedures, you should habitually operate. V. Other window function APIs There are also window functions not listed in this tutorial for your reference. Function name tells the AnyPopup to determine whether there is a visible pop-up window Cascadewindows order window displaying closewindow to minimize the specified window (if it is a nail window), the pop-up and sub-window invalid DestroyWindow clear specified Window and the Sub-window DrawanImatedRects get a window DrawanImatedRects get window Open or close (Disable) Specify window flashwindow to show the title of the specified window Blinking the GetUpdateRect to update the location of the window that needs to be updated GetWindowContextHelpID gets associated with the window Help Scene InvalidateRect The All or Section ISWINDOWUNICODE needs to be updated in the invalidate in the specified window IsWindowUnde desired text messages Use Unicode format LockWindowUpdate to allow or disable a powerful function that depicts the specified window RedRawwindow, for control all or part of the window. Heavy painting ScrollWindow, ScrollWindowEx scroll display window All or some Customer SETWINDOWCONTEXTHELPID Settings Syntie Scenes associated with the window ShowOWNedPopups hide or displays all keep-up pop-up window showWindow to the specified window for setting the window, including the window ShowWindowasync such as ShowWindowasync is similar to showWindow, adding the capWindow, which adds the Window of the other processes, TileWindows to display UpdateWindow, update any part of the window inside the window in the window. ValidateRect points out that all or part of the rectangles have been updated, no need to update, the flashwindow function is very interesting, you can try it. Back to top

转载请注明原文地址:https://www.9cbs.com/read-59377.html

New Post(0)