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
Solved

Problem with HDM_GETITEM

Posted on 2000-05-18
11
852 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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