Solved

Problem with HDM_GETITEM

Posted on 2000-05-18
11
868 Views
Last Modified: 2008-03-06
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...
0
Comment
Question by:Olli083097
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 2821181
>Debug.Print SendMessage(hHeader, HDM_GETITEM, 2, HDI)

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
0
 

Author Comment

by:Olli083097
ID: 2821218
I know that but all the properties is 0 and "". And the SendMessage should return True?!?
0
 
LVL 15

Expert Comment

by:ameba
ID: 2821287
If your header has 2 columns, the second column has index 1.
  ret = SendMessage(hHeader, HDM_GETITEM, 1, HDI)
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:Olli083097
ID: 2821294
I know! It has 5 columns...
0
 

Author Comment

by:Olli083097
ID: 2821298
BTW: Have you checked my type def and my constant?
0
 
LVL 15

Expert Comment

by:ameba
ID: 2821320
>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?
0
 

Author Comment

by:Olli083097
ID: 2821336
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?
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 2821611
Found something. I tested and everything works with VB5 Listview.
You have your constants OK, here are some you didn't mention:

Const HDM_FIRST = &H1200
Const LVM_FIRST = &H1000
Const LVM_GETHEADER = (LVM_FIRST + 31)
Const HDM_GETITEM = (HDM_FIRST + 3)

Private Declare Function SendMessageAny Lib "user32" _
    Alias "SendMessageA" _
    (ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
 
Private 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

Private Sub Form_Click()
    Dim r As Long
    Dim hHeader As Long
    Dim HD As HD_ITEM
    hHeader = SendMessageLong(ListView1.hWnd, LVM_GETHEADER, 0, 0)
   
    With HD
        .mask = HDI_TEXT
        .cchTextMax = 255
        .pszText = Space(255) ' prepare buffer
       
        r = SendMessageAny(hHeader, HDM_GETITEM, 1, HD)  ' second column
        ' remove unneeded charavcters
        r = InStr(.pszText, Chr(0))
        MsgBox "Column text = '" & Left(.pszText, r - 1) & "'"
       
        .mask = HDI_WIDTH
        r = SendMessageAny(hHeader, HDM_GETITEM, 1, HD)  ' second column
        MsgBox "Width = " & .cxy & " pts"
       
    End With
End Sub
0
 

Author Comment

by:Olli083097
ID: 2824515
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!
0
 

Author Comment

by:Olli083097
ID: 2824602
BTW:
How about the HDM_SETITEM? Can't quite make it work...
0
 
LVL 15

Expert Comment

by:ameba
ID: 2825018
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(colNo + 1).Text
        .iImage = imgIconNo
    End With
    r = SendMessageAny(hHeader, HDM_SETITEM, colNo, HD)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question