ImageVerifierCode 换一换
格式:DOC , 页数:11 ,大小:38KB ,
资源ID:8729253      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-8729253.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(VB使用的几个技巧.doc)为本站会员(11xg27ws)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

VB使用的几个技巧.doc

1、VB 使用的几个技巧敬请留意:VB 使用的几个技巧收藏把 VB 标准的工具栏变成平面式 平面式的工具栏好象显得很酷!但 VB5 只提供了普通的凸起的工具栏。你是否想把它变成平面的?这似乎很不容易。但事实并非如此,试试: 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 “u

2、ser32“ 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:

3、 Private Sub MakeFlat()Dim style As LongDim hToolbar As LongDim r As LonghToolbar = FindWindowEx(Toolbar1.hwnd, 0&, “ToolbarWindow32“, vbNullString)style = SendMessageLong(hToolbar, TB_GETSTYLE, 0&, 0&)If style And TBSTYLE_FLAT Thenstyle = style Xor TBSTYLE_FLATElse: style = style Or TBSTYLE_FLATEnd

4、 Ifr = SendMessageLong(hToolbar, TB_SETSTYLE, 0, style)Toolbar1.RefreshEnd Sub注意:需要 4.70 或其以上版本的 comctl32.dll 支持。-在 Caption 中显示 & 符号 大家知道,& 符号是 Windows 的快捷键表示符号,如果要在 Caption 中显示 & ,方法很简单,连续输入两个 & 符号即可。如在 Caption 中输入 Save & Exit,则显示 Save & Exit。 返回技巧索引 -让窗口一直在上面 很多流行软件都有这样一个选项:Always on Top。它可以让窗口在最上

5、面,别的窗口不能覆盖它。我们在 VB 中,可以使用下面的方法来实现: 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 = &H8

6、0Private 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 “

7、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) As LongPrivate mbOnTop As BooleanPrivate Property Let OnTop(Setting As Boolean)if Setting ThenSetWindowPos hwnd, -1, 0, 0, 0, 0, SWP_NOMOVE

8、Or SWP_NOSIZEElseSetWindowPos hwnd, -2, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZEEnd IfmbOnTop = SettingEnd Property Private Property Get OnTop() As BooleanReturn the private variable set in Property LetOnTop = mbOnTopEnd Property 调用 OnTop=True 即可让窗口 Always OnTop。 此技巧由 eaboy 提供。 返回技巧索引 -播放资源文件文件中的声音 VB 提

9、供的方法使我们可以很容易地使用资源文件中的字符、图片等资源。我们可以用以下方法播放资源文件中的 wav 声音: 首先,在你的资源文件的源文件 (RC) 文件加入下面一行: MySound WAVE c:musicvanhalen.wav 然后将其编译为 RES 文件。最后使用下面的声明及代码: Private Declare Function PlaySound Lib _ “winmm.dll“ Alias “PlaySoundA“ ( _ ByVal lpszName As String, _ ByVal hModule As Long, _ ByVal dwFlags As Long)

10、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 +

11、 _ SND_NODEFAULT lRet = PlaySound(sSoundName, hInst, lFlags) End Sub 返回技巧索引 -使用枚举变量 VB5 引入枚举变量,使用它,我们可以显著地改变应用程序的易读性: Public Enum TimeOfDayMorning = 0Afternoon = 1Evening = 2End EnumSub Main()Dim RightNow As TimeOfDayIf Time = #12:00:00 AM# And Time = #12:00:00 PM# And Time = #6:00:00 PM# ThenRightN

12、ow = EveningEnd IfEnd Sub 返回技巧索引 -动态改变屏幕设置 我们经常看到许多 Win95 的应用程序(尤其是游戏)在运行它的时候改变屏幕的设置,运行完后恢复,在 VB 中,我们可以用以下方法实现: - 定义Private Declare Function lstrcpy _Lib “kernel32“ Alias “lstrcpyA“ _(lpString1 As Any, lpString2 As Any) _As LongConst CCHDEVICENAME = 32Const CCHFORMNAME = 32Private Type DEVMODEdmDevi

13、ceName As String * CCHDEVICENAMEdmSpecVersion As IntegerdmDriverVersion As IntegerdmSize As IntegerdmDriverExtra As IntegerdmFields As LongdmOrientation As IntegerdmPaperSize As IntegerdmPaperLength As IntegerdmPaperWidth As IntegerdmScale As IntegerdmCopies As IntegerdmDefaultSource As IntegerdmPri

14、ntQuality As IntegerdmColor As IntegerdmDuplex As IntegerdmYResolution As IntegerdmTTOption As IntegerdmCollate As IntegerdmFormName As String * CCHFORMNAMEdmUnusedPadding As IntegerdmBitsPerPel As IntegerdmPelsWidth As LongdmPelsHeight As LongdmDisplayFlags As LongdmDisplayFrequency As LongEnd Type

15、Private Declare Function _ChangeDisplaySettings Lib _“User32“ Alias “ChangeDisplaySettingsA“ (_ByVal lpDevMode As Long, _ByVal dwflags As Long) As Long- 函数Public Function SetDisplayMode(Width As _Integer,Height As Integer, Color As _Integer) As LongConst DM_PELSWIDTH = &H80000Const DM_PELSHEIGHT = &

16、H100000Const DM_BITSPERPEL = &H40000Dim NewDevMode As DEVMODEDim pDevmode As LongWith NewDevMode.dmSize = 122If Color = -1 Then.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHTElse.dmFields = DM_PELSWIDTH Or _DM_PELSHEIGHT Or DM_BITSPERPELEnd If.dmPelsWidth = Width.dmPelsHeight = HeightIf Color -1 Then.dmBi

17、tsPerPel = ColorEnd IfEnd WithpDevmode = lstrcpy(NewDevMode, NewDevMode)SetDisplayMode = ChangeDisplaySettings(pDevmode, 0)End Function例子调用:改变为 640x480x24 位: i = SetDisplayMode(640, 480, 24) 如果成功返回 0 。 返回技巧索引 -移动没有标题栏的窗口 我们一般是用鼠标按住窗口的标题栏,然后移动窗口,当窗口没有标题栏时,我们可以用下面的方法来移动窗口: 在 BAS 文件中声明: Declare Functio

18、n 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 然后,在 Form_MouseDown 事件中: Private Sub Form_Mou

19、seDown(Button As Integer, Shift As Integer, X As Single, Y As Single)ReleaseCaptureSendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&End Sub 返回技巧索引 -快速选择全部项目 我们在使用 List 控件时,经常需要全部选择其中的项目,在项目较少时,我们可以逐项设置 Selected 来选择全部的项目,但当项目较多时,这样做就比较费时,其实,我们可以用 API 函数来简单实现此功能: Dim nRet As Long Dim bState as Boolean

20、 bState=True nRet = SendMessage(lstList.hWnd, LB_SETSEL, bState, -1) 函数声明: Public Declare Function SendMessage Lib “User32“ Alias “SendMessageA“ ( 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_US

21、ER + 6) 返回技巧索引 -真正删除数据库的记录 大家知道,缺省情况下,VB 删除记录只是把记录作上个删除标志而已,并没有真正删除。要真正删除记录,你可以使用 VB 提供的以下方法:BeginTrans、CommitTrans、RollBack。其中,BeginTrans 方法开始记录数据库的变动,CommitTrans 方法确认数据库的变动,而 RollBack 方法则可以恢复被删除或修改的记录。它们可以嵌套使用。因此,要恢复被删除的记录,应该在使用 BeginTrans 方法之后及使用 CommiTrans 方法之前使用 RollBack 方法。 返回技巧索引 -显示动画鼠标图标 Wi

22、n95 的动画鼠标为应用程序增色不少,而 VB 则只提供一般的鼠标图标支持。要用 VB 显示动画鼠标形状,你可以使用以下方法: 函数声明: Public Const GCL_HCURSOR = -12Declare Function ClipCursor Lib “user32“ (lpRect As Any) As LongDeclare Function DestroyCursor Lib “user32“ (ByVal hCursor As Any) As LongDeclare Function LoadCursorFromFile Lib “user32“ Alias “LoadCu

23、rsorFromFileA“ (ByVal lpFileName As String) As LongDeclare Function SetClassLong Lib “user32“ Alias “SetClassLongA“ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongDeclare Function GetClassLong Lib “user32“ Alias “GetClassLongA“ (ByVal hwnd As Long, ByVal nIndex As Long) As Long使用: Dim mhBaseCursor As Long, mhAniCursor As LongDim lResult As LongmhAniCursor = LoadCursorFromFile(“c:windowscursorsappstart.ani“)lResult = SetClassLong(hwnd), GCL_HCURSOR, mhAniCursor)本文来自 CSDN 博客,转载请标明出处:http:/

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报