在VB程序中,通过代码改变Combo控件只读属性Style值
2001-08-30 14:18
489 查看
在VB程序中,如果你用如下语句动态创建一个Combo控件
Dim WithEvents cmbDropList As ComboBox
...
Set cmbDropList = Controls.Add("VB.ComboBox", "cmbDropList")
后,Combo控件的Style值是1 (VbComboDropDown 下拉式组合框,包括一个下拉式列表和一个文本框。可以从列表选择或在文本框中输入 ),若想把Style的值更改2 (VbComboDrop-DownList 2 下拉式列表。这种样式仅允许从下拉式列表中选择 )
通过语句Combo1.Style=2是不行的,因为Style是只读属性。为了突破这个限制,我动用的Spy++这个武器,对两种不同Style值的combo控件进行侦察,发现了两处不同
1、combo控件的style的值为1-VbComboDropDown时,combo控件窗口的Styles=&H54010242,而combo控件的style的值为2-VbComboDrop-DownList时,combo控件窗口的Styles=&H54010243
2、combo控件的style的值为1-VbComboDropDown时,combo控件里有一个Edit文本框窗口,而combo控件的style的值为2-VbComboDrop-DownList时,则没有Edit文本框窗口
我首先试着用API函数改变combo控件窗口的Styles值,
Call SetWindowLong(Combo1.hwnd, GWL_STYLE,&H54010243)
看Combo控件有没有什么改变,结果大失所望,
我再次试着用API函数杀死Combo控件里的那个Edit窗口,耶~~~,成功了
下面是我的实现代码:
Private Const GWL_STYLE = (-16)
Private Const GW_CHILD = 5
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Const SW_HIDE = 0
Const SW_SHOW = 5
Dim WithEvents cmbDropList As ComboBox
Private Sub cmbDropList_Click()
MsgBox cmbDropList.Text
End Sub
Private Sub Command1_Click()
Dim ChildHwnd As Long
Set cmbDropList = Controls.Add("VB.ComboBox", "cmbDropList")
cmbDropList.Visible = True
cmbDropList.AddItem "One"
cmbDropList.AddItem "Two"
ChildHwnd = GetWindow(cmbDropList.hwnd, GW_CHILD) '取edit句柄
Call DestroyWindow(ChildHwnd) 'Kill edit窗口
'改变cmbDropList的Style,这一语句可有可无~~~~,
Call SetWindowLong(cmbDropList.hwnd, GWL_STYLE, GetWindowLong(cmbDropList.hwnd, GWL_STYLE) + 1)
End Sub
相关文章推荐
- 在VB程序中,通过代码改变Combo控件只读属性Style值
- jQuery Validate 表单验证插件----通过name属性来关联字段来验证,改变默认的提示信息,将校验规则写到 js 代码中
- Android通过Style改变窗体,控件的样式
- c#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值
- 【asp.net 】使用js结合hidden控件实现在后台运行一段程序后提示确认,确认通过后继续执行后台代码~~~
- 编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]
- VB用户控件制作讲解与实例-----用户控件属性或函数的描述信息如何写入程序
- 设置上传文件控件文本框只读属性代码
- C#通过SendMessage发送消息,改变其他程序的下拉框控件(ComboBox)的值
- Javascript获取标签ID改变style属性的代码
- 通过cssText属性访问style中的CSS代码
- 如何在程序运行中动态改变对象属性在PropertyGrid可见性和只读属性
- [VB.NET]如何在DataGridView控件中增加、删除和修改记录(用程序代码的方法)
- 在Repeater控件中通过Eval的方式绑定Style样式代码
- 编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]
- android通过style.xml文件定义相同控件的通用属性
- control picture 大小如何设定 mfc MFC中怎么通过程序改变Picture Control控件的大小
- Javascript获取标签ID改变style属性的代码
- [VB.NET]改变窗体的width或height属性,程序运行后窗体的大小却不发生变化
- 在Repeater控件中通过Eval的方式绑定Style样式代码