Solved

Problem with HDM_GETITEM

Posted on 2000-05-18
11
841 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 66
VBA error replacing data 6 37
Set email body to html using vbscript 6 28
MS Access 03, TransferText, decimal places 8 47
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now