Solved

Problem with HDM_GETITEM

Posted on 2000-05-18
11
828 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
Comment Utility
>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
Comment Utility
I know that but all the properties is 0 and "". And the SendMessage should return True?!?
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
If your header has 2 columns, the second column has index 1.
  ret = SendMessage(hHeader, HDM_GETITEM, 1, HDI)
0
 

Author Comment

by:Olli083097
Comment Utility
I know! It has 5 columns...
0
 

Author Comment

by:Olli083097
Comment Utility
BTW: Have you checked my type def and my constant?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 15

Expert Comment

by:ameba
Comment Utility
>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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
BTW:
How about the HDM_SETITEM? Can't quite make it work...
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now