Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

ListView_InsertColumn returning -1

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
_Zaphod
Asked:
_Zaphod
  • 3
  • 2
  • 2
  • +2
1 Solution
 
galkinCommented:
Could you sent a piece od code
0
 
_ZaphodAuthor Commented:
Edited text of question
0
 
chensuCommented:
It seems that ListView_InsertColumn(list, 0, &item) should be ListView_InsertColumn(list, i, &item);
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
_ZaphodAuthor Commented:
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
 
RLMCommented:
Try including LVCF_SUBITEM in item.mask and set item.iSubItem to 0 before calling.
0
 
alexoCommented:
1) Reset all members of the item before the call:
  LV_COLUMN item = { 0 };

2) Use GetLastError() for a possible explanation.

0
 
_ZaphodAuthor Commented:
*shrug* Didn't work.
0
 
alexoCommented:
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
 
RLMCommented:
Take 45 from dresser. Load. Point at computer. Pull trigger.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now