Solved

ListView_InsertColumn returning -1

Posted on 1998-04-23
9
640 Views
Last Modified: 2013-12-03
What can possibly be the cause of that? Note that it only happens on some computers, on most of them it works no problem. Here's the code:

void CreateListView(HWND hWnd)
{
      LV_COLUMN item;
      int i;
      char *cpitem[] = {"Date", "To", "Subject", "Address", "From"};
      
      InitCommonControls();

      if ((list = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
            WS_VISIBLE | WS_CHILD | LVS_ALIGNLEFT | LVS_REPORT,
            0, 0, 0, 0, hWnd, (HMENU)55, hInst,
            NULL)) == NULL)
            return;
      
      item.mask      = LVCF_TEXT | LVCF_FMT | LVCF_WIDTH;
      item.fmt      = LVCFMT_LEFT;
      item.cx            = WIDTH / ((sizeof cpitem / sizeof cpitem[0]) + 1);
      for (i = 0; i < sizeof cpitem / sizeof cpitem[0]; ++i)
      {
            item.pszText = cpitem[i];
            item.cchTextMax = strlen(cpitem[i]);
            if (ListView_InsertColumn(list, 0, &item) == -1)
                  MessageBox(hWnd, "Failed to create column", appname, MB_OK);
      }
}
0
Comment
Question by:_Zaphod
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1396992
Could you sent a piece od code
0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396993
Edited text of question
0
 
LVL 23

Expert Comment

by:chensu
ID: 1396994
It seems that ListView_InsertColumn(list, 0, &item) should be ListView_InsertColumn(list, i, &item);
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 1

Author Comment

by:_Zaphod
ID: 1396995
That's not true, I want the columns to be in the opposite order than that in which I wrote the char*[]. The reason for that is that I was stupid first and lazy later :)
And besides, that's no reason for it to fail (I always thought).
0
 

Expert Comment

by:RLM
ID: 1396996
Try including LVCF_SUBITEM in item.mask and set item.iSubItem to 0 before calling.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1396997
1) Reset all members of the item before the call:
  LV_COLUMN item = { 0 };

2) Use GetLastError() for a possible explanation.

0
 
LVL 1

Author Comment

by:_Zaphod
ID: 1396998
*shrug* Didn't work.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1396999
What did GetLastError() return?  (see WINERR.H for a translation of the error codes).

This way:

    if (ListView_InsertColumn(list, 0, &item) == -1)
    {
        int err = GetLastError();
        // ...
    }
0
 

Accepted Solution

by:
RLM earned 50 total points
ID: 1397000
Take 45 from dresser. Load. Point at computer. Pull trigger.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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