Olli083097
asked on
Problem with HDM_GETITEM
The following code returnes 0, why?
HDI.mask = HDI_WIDTH
Debug.Print SendMessage(hHeader, HDM_GETITEM, 2, HDI)
This is my Type def:
Public Type HD_ITEM
mask As Long
cxy As Long
pszText As String
hbm As Long
cchTextMax As Long
fmt As Long
lParam As Long
iImage As Long
iOrder As Long
End Type
This are my constants:
Public Const HDI_WIDTH As Long = &H1
Public Const HDI_HEIGHT As Long = HDI_WIDTH
Public Const HDI_TEXT As Long = &H2
Public Const HDI_FORMAT As Long = &H4
Public Const HDI_LPARAM As Long = &H8
Public Const HDI_BITMAP As Long = &H10
Public Const HDI_IMAGE As Long = &H20
Public Const HDI_DI_SETITEM As Long = &H40
Public Const HDI_ORDER As Long = &H80
I know that the handle is corect. And my guess is that my type def or my constant is wrong...
HDI.mask = HDI_WIDTH
Debug.Print SendMessage(hHeader, HDM_GETITEM, 2, HDI)
This is my Type def:
Public Type HD_ITEM
mask As Long
cxy As Long
pszText As String
hbm As Long
cchTextMax As Long
fmt As Long
lParam As Long
iImage As Long
iOrder As Long
End Type
This are my constants:
Public Const HDI_WIDTH As Long = &H1
Public Const HDI_HEIGHT As Long = HDI_WIDTH
Public Const HDI_TEXT As Long = &H2
Public Const HDI_FORMAT As Long = &H4
Public Const HDI_LPARAM As Long = &H8
Public Const HDI_BITMAP As Long = &H10
Public Const HDI_IMAGE As Long = &H20
Public Const HDI_DI_SETITEM As Long = &H40
Public Const HDI_ORDER As Long = &H80
I know that the handle is corect. And my guess is that my type def or my constant is wrong...
ASKER
I know that but all the properties is 0 and "". And the SendMessage should return True?!?
If your header has 2 columns, the second column has index 1.
ret = SendMessage(hHeader, HDM_GETITEM, 1, HDI)
ret = SendMessage(hHeader, HDM_GETITEM, 1, HDI)
ASKER
I know! It has 5 columns...
ASKER
BTW: Have you checked my type def and my constant?
>Have you checked my type def and my constant?
No. I don't use header control, I'm just looking at a similar code, but with other structure.
What is your SendMessage declarations?
No. I don't use header control, I'm just looking at a similar code, but with other structure.
What is your SendMessage declarations?
ASKER
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd&, ByVal wMsg&, wParam As Any, lParam As Any) As Long
It works when I send othe messages!
Do you know where I can get the type def and the constats?
It works when I send othe messages!
Do you know where I can get the type def and the constats?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ameba:
I have found the error, thanks to you!
The entire problem was in my SendMessage decleration: "wParam As Any"
it shuld be "As Long"
That's what happen when I get the decleration for other places than the MS textfile that comes with API Viewer...
Thanx!
I have found the error, thanks to you!
The entire problem was in my SendMessage decleration: "wParam As Any"
it shuld be "As Long"
That's what happen when I get the decleration for other places than the MS textfile that comes with API Viewer...
Thanx!
ASKER
BTW:
How about the HDM_SETITEM? Can't quite make it work...
How about the HDM_SETITEM? Can't quite make it work...
Thanks for the points
SendMessage can be used with different types of lParam and wParam parameters, which can be passed ByVal or ByRef. The best practice is to include specific declaration, e.g. SendMessageString, SendMessagePT, SendMessageRect.
HDM_SETITEM:
With HD
.mask = HDI_IMAGE Or HDI_FORMAT
.fmt = HDF_LEFT Or HDF_STRING
.pszText = ListView1.ColumnHeaders(co lNo + 1).Text
.iImage = imgIconNo
End With
r = SendMessageAny(hHeader, HDM_SETITEM, colNo, HD)
SendMessage can be used with different types of lParam and wParam parameters, which can be passed ByVal or ByRef. The best practice is to include specific declaration, e.g. SendMessageString, SendMessagePT, SendMessageRect.
HDM_SETITEM:
With HD
.mask = HDI_IMAGE Or HDI_FORMAT
.fmt = HDF_LEFT Or HDF_STRING
.pszText = ListView1.ColumnHeaders(co
.iImage = imgIconNo
End With
r = SendMessageAny(hHeader, HDM_SETITEM, colNo, HD)
You don't need to print return value, but some property of your structure
HDI.mask = HDI_WIDTH
ret = SendMessage(hHeader, HDM_GETITEM, 2, HDI)
Debug.Print HDI.cxy & " " & HDI.lParam