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

ListView_InsertColumn returning -1

Posted on 1998-04-23
9
638 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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: 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

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…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…

791 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