VB calls the API function to keep the window at the top

zhaozj2021-02-11  172

VB calls the API function to keep the window at the top

Transfer from: VB Programming Garden ---- We see whether the app is allowed to keep the window in the top, the common Microsoft Word file opens and edits the window is like this. This function can be implemented by calling the setWindowsPOS () API function in VB development. The function is declared as follows: Private Declare Function SetWindowPosLib "user32" (ByVal hwnd As Long, _ByVal hWndInsertAfter As Long, ByValx As Long, ByVal y As Long, _ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long- --- hWnd variable element is the handle of the window; X, Y is the coordinate of the upper left corner of the window; CX, CY is the width and height of the window; HWndInsertAfter zoning is the window handle in front of the HWND window in the window list, there are four optional Value: Selected value of serial number 1 HWND_BOTTOM puts the window in the bottom of the window list 2 HWND_TOP Put the window in the window list 3 HWnd_topmost put the window on the top of the window list 4 HWnd_notopmost put the window on the top of the window list Under the uppermost window ---- WFLAGS variable yuan is integer, there are eight optional values: serial number optional value 1 SWP_DRAWFRAME draw a box around the window 2 SWP_HIDEWINDOW Hide Window 3 SWP_NOACTIVATE Do not activate the window 4 SWP_NOMOVE Keep window Current location 5 SWP_NOREDRAW window Not Auto STD 6 SWP_NOSize Hold window Current Size 7 SWP_NOZORDER Keep window in the current position of the window in the list 8 SWP_SHOWINDOW display window ---- The following example TEST demonstrates the above 7 After the correct choice is changed, the window can always stay at the top after the application runs, the program list is as follows: Option ExplicitPrivate Declare function setWindowPoslib "User32" (Byval HwndInsertAfter As Long, Byval X as long, byval y) As long, _byval cx as long, byval cy as long, byval wflags as long) As longprivate const hwnd_topmost = -1private const swap_showwindows = & h4 0Private Sub Form_Load () DIM RETVALUE As LongretValue = SetWindowPos (Me.hwnd, Hwnd_topmost, Me.currentx, _me.currenty, 300, 300, SWP_SHOWINDOWS) End Sub ---- Note: When writing a function declaration, the entire function declaration must be After writing, you can not be proposed. It is generally automatically obtained from the system to obtain a function declaration, and the method is to start the "API Browse" program from the VB's external program management. Find the required function declaration in the API Browse program and then copy to the VB code.

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

New Post(0)