321、如何把 VB 标准的工具栏变成平面式? 322、如何在 Caption 中显示 & 符号? 323、如何播放资源文件文件中的声音? 324、如何使用枚举变量? 325、如何移动没有标题栏的窗口?
321、如何把
VB 标准的工具栏变成平面式?
平面式的工具栏好象显得很酷!但 VB5 只提供了普通的凸起的工具栏。你是否想把它变成平面的?这似乎很不容易。但事实并非如此,试试: BAS: Public Const WM_USER = &H400 Public Const TB_SETSTYLE = WM_USER + 56 Public Const TB_GETSTYLE = WM_USER + 57 Public Const TBSTYLE_FLAT = &H800 Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, _ ByVal hWnd2 As Long, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long SUB: 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.Refresh End Sub 注意:需要 4.70 或其以上版本的 comctl32.dll 支持。
322、如何在 Caption 中显示 & 符号?
大家知道,& 符号是 Windows 的快捷键表示符号,如果要在 Caption 中显示 & ,方法很简单,连续输入两个 & 符号即可。如在 Caption 中输入 Save && Exit,则显示 Save & Exit。
[返回索引]
323、如何播放资源文件文件中的声音?
VB 提供的方法使我们可以很容易地使用资源文件中的字符、图片等资源。我们可以用以下方法播放资源文件中的 wav 声音: 首先,在你的资源文件的源文件 (RC) 文件加入下面一行: MySound WAVE c:\music\vanhalen.wav 然后将其编译为 RES 文件。最后使用下面的声明及代码: 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 = PlaySound(sSoundName, hInst, lFlags) End Sub
[返回索引]
324、如何使用枚举变量?
VB5 引入枚举变量,使用它,我们可以显著地改变应用程序的易读性: Public Enum TimeOfDay Morning = 0 Afternoon = 1 Evening = 2 End Enum Sub Main() Dim RightNow As TimeOfDay If Time >= #12:00:00 AM# And Time < #12:00:00 PM# Then RightNow = Morning ElseIf Time >= #12:00:00 PM# And Time < #6:00:00 PM# Then RightNow = Afternoon ElseIf Time >= #6:00:00 PM# Then RightNow = Evening End If End Sub
[返回索引]
325、如何移动没有标题栏的窗口?
我们一般是用鼠标按住窗口的标题栏,然后移动窗口,当窗口没有标题栏时,我们可以用下面的方法来移动窗口: 在 BAS 文件中声明: Declare Function ReleaseCapture Lib "user32" () As Long Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" ( _ ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Public Const HTCAPTION = 2 Public Const WM_NCLBUTTONDOWN = &HA1 然后,在 Form_MouseDown 事件中: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) ReleaseCapture SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0& End Sub |