如何在VB里用API函数SendMessage实现重载DrawItem函数功能?

Gempin 2000-08-14 10:01:00
大家一定在VC里重载过CWnd类的DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct),如何在VB里用API函数SendMessage实现重载DrawItem功能,例如在ComboBox里分别重绘各个ListItem(每个ListItem均不同)。有例子为好!
...全文
305 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
NiceFeather 2000-09-17
  • 打赏
  • 举报
回复
你应该去参考MSDN的Win32 API SDK,那里有完整的文档说明及示例,你会搞定的!
Gempin 2000-08-31
  • 打赏
  • 举报
回复
shines:你说的方法好象不行吧,当然你参考的源代码可以,因为Call CopyMem(DrawInfo, ByVal lParam, LenB(DrawInfo))已将lParam的值赋予了DrawInfo,而你的菜单代码为:
Dim DrawInfo As DRAWITEMSTRUCT
Call CopyMem(ByVal lParam, DrawInfo, LenB(DrawInfo))
SendMeesage hwnd, WM_DRAWITEM, 0, lParam
DRAWITEMSTRUCT为不可预料值,lParam则会是什么呢?
注:上面是我个人意见,不一定对,仅供参考!
shines77 2000-08-23
  • 打赏
  • 举报
回复
我只知道对于菜单是:
SendMeesage hwnd, WM_DRAWITEM, 0, lParam

lParam好像等于
Dim DrawInfo As DRAWITEMSTRUCT
Call CopyMem(ByVal lParam, DrawInfo, LenB(DrawInfo))

我是参考下列源代码得来的,我不知道这样这样反过来用对不对
------------------------------------------------------
Private Declare Sub CopyMem Lib "kernel32" Alias _
"RtlMoveMemory" (pDest As Any, pSource As Any, _
ByVal ByteLen As Long)

Dim DrawInfo As DRAWITEMSTRUCT

If wMsg = WM_DRAWITEM Then
If wParam = 0 Then 'It was sent by the menu
'Get DRAWINFOSTRUCT -- copy it to our
'empty structure from the pointer in lParam
Call CopyMem(DrawInfo, ByVal lParam, LenB(DrawInfo))
IsSep = IsSeparator(DrawInfo.itemID)

'===Set the menu font through its hDC...===
MyFont = SendMessage(Me.hWnd, WM_GETFONT, 0&, 0&)
OldFont = SelectObject(DrawInfo.hdc, MyFont)
...........................
End If
........................
End If
Keri 2000-08-22
  • 打赏
  • 举报
回复
这个例子演示了如何强制重画窗口某一区域.有时这是很需要的,例如当你使用LockWindowUpdate API 函数来加快某一控件的数据加载速度时. 新建一个工程,添加一个模块,代码如下:

Private Type RECT
 Left As Long
 Top As Long
 Right As Long
  Bottom As Long
End Type
Private Type POINTAPI
 X As Long
 Y As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Sub RepaintWindow( ByRef objThis As Object, Optional ByVal bClientAreaOnly As Boolean = True )
 Dim tR As RECT
 Dim tP As POINTAPI
 If (bClientAreaOnly) Then
   GetClientRect objThis.hWnd, tR
 Else
   GetWindowRect objThis.hWnd, tR
   tP.X = tR.Left: tP.Y = tR.Top
   ScreenToClient objThis.hWnd, tP
   tR.Left = tP.X: tR.Top = tP.Y
   tP.X = tR.Right: tP.Y = tR.Bottom
   ScreenToClient objThis.hWnd,
   tP tR.Right = tP.X: tR.Bottom = tP.Y
 End If
 InvalidateRect objThis.hWnd, tR, 1
End Sub
在窗体上放置一个按钮和列表框.使列表框足够大以便观察效果.然后添加以下代码:
Private Sub Command1_Click()
 RepaintWindow List1
End Sub
Private Sub Form_Load()
 Dim i As Long
 For i = 1 To 200
  List1.AddItem "TestItem " & I
 Next i
End Sub
Gempin 2000-08-21
  • 打赏
  • 举报
回复
诸位大虾们,sendmessage函数的高手们,快来轻松地取走这100分吧!
Gempin 2000-08-20
  • 打赏
  • 举报
回复
我提的问题总是数天无人搭理,各位大虾是嫌分数太低,还是觉得此问题不屑一顾?
Gempin 2000-08-19
  • 打赏
  • 举报
回复
Un1能否给我具体讲一讲如何在这个winproc中实现ComboBox的DrawItem,另DRAWITEMSTRUCT再此起什么作用?谢谢!希望其他全国各路VC、VB高手也来讨论!
Gempin 2000-08-19
  • 打赏
  • 举报
回复
Un1能否给我具体讲一讲如何在这个winproc中实现ComboBox的DrawItem,另DRAWITEMSTRUCT再次起什么作用?谢谢!希望其他全国各路VC、VB高手也来讨论!
Un1 2000-08-15
  • 打赏
  • 举报
回复
当然是获得combobox.hwnd以后用setwindowlong设置winproc啦!
Gempin 2000-08-15
  • 打赏
  • 举报
回复
hook(钩子)?什么地方的hook?请问Un1.
Un1 2000-08-15
  • 打赏
  • 举报
回复
重载是hook, 不是sendmessage, sendmessage只能调用,和直接call 没有区别。
Gempin 2000-08-15
  • 打赏
  • 举报
回复
我的这个问题是太简单了还是太难了,诸位大虾们,这儿可有100分啊!

1,485

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧