★★★ Please pay attention to ★★★: Several skills used by VB

zhaozj2021-02-11  191

The toolbar of the VB standard becomes a flat planar toolbar, it seems cool! However, VB5 only provides ordinary raised toolbars. Do you want to turn it into a plane? This seems not easy. But that is not the case, try: BAS: Public Const WM_USER = & H400Public Const TB_SETSTYLE = WM_USER 56Public Const TB_GETSTYLE = WM_USER 57Public Const TBSTYLE_FLAT = & H800Public Declare Function SendMessageLong Lib "user32" Alias ​​"SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As LongPublic Declare Function FindWindowEx Lib "user32" Alias ​​"FindWindowExA" _ (ByVal hWnd1 As Long, _ ByVal hWnd2 As Long, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As LongSUB: Private Sub MakeFlat () Dim style As Long Dim hToolbar As Long Dim r As Long hToolbar = FindWindowEx (Toolbar1.hwnd, 0 &, "ToolbarWindow32", vbNullString) style = SendMessageLong (hToolbar, TB_GETSTYLE, 0 & , 0 &) If style And TBSTYLE_FLAT Then style = style Xor TBSTYLE_FLAT Else: style = style or TBSTYLE_FLAT End If r = SendMessageLong (hToolbar, TB_SETSTYLE, 0, style) Toolbar1.RefreshEnd Sub Note: a version 4.70 or above comctl32.dll stand by. -------------------------------------------------- ------------------------------ Display & Symbols in CAPTION know, the & symbol is the shortcut key of Windows indicates the symbol, if To display the &, the method is simple in the capen, and you can enter two & symbols. If you enter Save && Exit in CAPTION, Save & Exit is displayed. [Return to the skill index] --------------------------------------------- ----------------------------------- Let the window have been on the top of many popular software: Always On top. It allows the window to be on the top, and other windows cannot overwrite it.

We in VB, you can use the following methods to achieve: Private Const SWP_NOSIZE = & H1Private Const SWP_NOMOVE = & H2Private Const SWP_NOZORDER = & H4Private Const SWP_NOREDRAW = & H8Private Const SWP_NOACTIVATE = & H10Private Const SWP_FRAMECHANGED = & H20Private Const SWP_SHOWWINDOW = & H40Private Const SWP_NOCOPYBITS = & H80Private Const SWP_NOOWNERZORDER = & H200Private const SWP_DRAWFRAME = SWP_FRAMECHANGEDPrivate const SWP_NOREPOSITION = SWP_NOOWNERZORDER Private const HWND_TOP = 0Private const HWND_BOTTOM = 1Private const HWND_TOPMOST = -1Private const HWND_NOTOPMOST = -2 Private Declare Function SetWindowPos Lib "user32" (_ ByVal hwnd As Long, _ ByVal hWndInsertAfter As Long, _ ByVal X as long, _ byval y as long, _ byval cx as long, _ byval cy as long, _ byval wflags as long) is longprivate mbontop ask (setting as boolean) ing setting the setWindowPos HWnd, -1 , 0, 0, 0, 0, swp_nom OVE Or SWP_NOSIZE Else SetWindowPos hwnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End If mbOnTop = SettingEnd Property Private Property Get OnTop () As Boolean 'Return the private variable set in Property Let OnTop = mbOnTopEnd Property call OnTop = True can let the window Always Ontop. This trick is provided by eaboy. [Return to the skill index] --------------------------------------------- ----------------------------------- Sound VB provided in the resource file file provides us Easily use resources such as characters, images in the resource file. We can use the following methods to play the WAV sound in the resource file: First, add the following line in your resource file (RC) file: mysound Wave C: /Music/vanhalen.wav then compile it to the Res file.

Finally, using the following declaration and Code: Private Declare Function PlaySound Lib _ "winmm.dll" Alias ​​"PlaySoundA" (_ ByVal lpszName As String, _ ByVal hModule As Long, _ ByVal dwFlags As Long) As Long Private Const SND_ASYNC & = & H1 Private const SND_NODEFAULT & = & H2 Private const SND_RESOURCE & = & H40004 Dim hInst As Long Dim sSoundName As String Dim lFlags As Long Dim lRet As Long Private Sub Command1_Click () hInst = App.hInstance sSoundName = "mySound" lFlags = SND_RESOURCE SND_ASYNC _ SND_NODEFAULT lRet = Plays (SSoundName, Hinst, LFlags) End Sub [Return Tips Index] ----------------------------------- -------------------------------------------- Use the enumerated variable VB5 Introduced into the enumeration variable, use it, we can significantly change the readability of the application: public enum timeofDay Morning = 0Afternoon = 1 EVENING = 2nd enumsub main () DIM Rightnow as timeofDay if Time> = # 12: 00: 00 Am # and time <# 12: 00 pm #1 Rightnow = MORNING ELSEIF TIME> = # 12: 00: 00 pm # and time <# 6: 00: 00 Pm # THEN RightNow = Afternoon Elseif Time> = # 6 : 00: 00 PM # T RightNow = EVENING END IFEND SUB [Return Tips Index] ------------------------------------- ------------------------------------------ Dynamic change screen settings We often look To many Win95 applications (especially games) change the screen settings when running it, recover after running, in VB, we can implement the following methods: '- Defining private declare function lstrcpy _ lib "kernel32" alias "lstring1 as any, lpstring2 as any) _ as longconst cchdevicename = 32const cchFormName =

32Private Type DEVMODE dmDeviceName As String * CCHDEVICENAME dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * CCHFORMNAME dmUnusedPadding As Integer dmBitsPerPel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As LongEnd TypePrivate Declare Function _ ChangeDisplaySettings Lib _ "User32" Alias ​​"ChangeDisplaySettingsA" ( _BYVAL LPDEVMODE As Long, _ Byval dwflags as long) AS long'-function public function setDisplaymode (width as _ integer, height as integer, color as _ integer) A s LongConst DM_PELSWIDTH = & H80000Const DM_PELSHEIGHT = & H100000Const DM_BITSPERPEL = & H40000Dim NewDevMode As DEVMODEDim pDevmode As LongWith NewDevMode .dmSize = 122 If Color = -1 Then .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Else .dmFields = DM_PELSWIDTH Or _ DM_PELSHEIGHT Or DM_BITSPERPEL End If .dmPelsWidth = Width .dmPelsHeight = Height If Color <> -1 Then .dmBitsPerPel = Color End IfEnd WithpDevmode = lstrcpy (NewDevMode, NewDevMode) SetDisplayMode = ChangeDisplaySettings (pDevmode, 0) End Function call examples: 640x480x24 bits is changed to: i = SetDisplayMode (640, 480 24) If it successfully returns 0.

[Return to the skill index] --------------------------------------------- ----------------------------------- Mobile window without the title bar We generally hold the window with the mouse The title bar, then moving the window, when the window does not have the title bar, we can move the window with the following method: declare in the BAS file: Declare function releasecapture lib "user32" () as longdeclare function sendMessage lib "User32" _ALIAS "SendMessagea "(_ByVal hwnd As Long, ByVal wMsg As Long, _ByVal wParam As Long, lParam As Any) As LongPublic Const HTCAPTION = 2Public Const WM_NCLBUTTONDOWN = & HA1 then, in Form_MouseDown event: Private Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single) ReleaseCapturesendMessage HWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0 & End Sub [Returns Skill Index] ------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- - Quickly select All Projects When we use the List control, you often need all items. When we are less project, we can set the selected selected to select all items, but when the project is more, it is time consuming. In fact, we can use the API function to simply implement this feature: DIM NRET AS long Dim BState as boolean bstate = true nret = sendMessage (Lstlist.hwnd, lb_setsel, bstate, -1) function declaration: public declare function sendMessage lib "User32 Alias ​​Sendmes Sagea "(Byval HWnd As Long, Byval WMSG AS INTEGER, BYVAL WPARAM As Long, Byval LParam as long) As longpublic const wm_user = & h400public const lb_setsel = (WM_USER 6) [Return to skill index] ---------------- -------------------------------------------------- ---------------------- Really delete the database, you know that by default, the VB delete record just puts the records to delete the flag, no Really deleted. To really delete records, you can use the following methods provided by VB: Begintrans, CommitTrans, Rollback. Among them, the Begintrans method starts to record the changes in the database, and the committrans method confirms the change of the database, and the Rollback method can recover the recorded or modified record. They can be used nested.

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

New Post(0)