Anonymous
Anonymous

Reputation: 1

ListView scrollbar flickering

I am coding my first program with GUI using only pure WinAPI. But I faced some strange problem.

There are 2 ListView elements on the form to output some values. When scrollbar appears on second ListView, all child objects on the form disappears. And scrollbar of that ListView is flickering. And when I push on that ListView all get back to normal. I don't know what to do.

But this problem applies only to the second ListView element, hListViewCh on the form. There is all ok with the first element.

Here is the code:

case WM_CREATE:
    {
    GetClientRect(hWnd, &Rect);

    h_Chk1 = CreateWindow(TEXT("button"), TEXT("Graphic"),
             WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
             Rect.right - 550, 
     300  + 10, 
     100, 
     20,
     hWnd, (HMENU)0xCB01, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
        h_Chk2 = CreateWindow(TEXT("button"), TEXT("Diagram"),
             WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
             Rect.right - 550, 
     300  + 35, 
     100, 
     20,
     hWnd, (HMENU)0xCB02, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
        CheckDlgButton(hWnd, 0xCB01, BST_UNCHECKED);
    CheckDlgButton(hWnd, 0xCB02, BST_UNCHECKED);

            hListViewCh = CreateWindow(
                WC_LISTVIEW, 
                _T("MyList"),
                LVS_REPORT|WS_CHILD|WS_VISIBLE,
                Rect.right - 265,
                377,
                     250,
                200,
                hWnd, (HMENU)listViewCh, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
            //--
            LVCOLUMN lvColumn = {0};
            lvColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT;
            lvColumn.fmt = LVCFMT_CENTER;
            lvColumn.pszText = "№";
            lvColumn.cx = 30;
            ListView_InsertColumn(hListViewCh, 0, &lvColumn);
            lvColumn.pszText = "Property";
            lvColumn.cx = 70;
            ListView_InsertColumn(hListViewCh, 1, &lvColumn);
            lvColumn.pszText = "Value";
            lvColumn.cx = 120;
            ListView_InsertColumn(hListViewCh, 2, &lvColumn);
            //--
         hListView = CreateWindow(
          WC_LISTVIEW,
          _T("Set of variate values"),
          LVS_REPORT|WS_CHILD|WS_VISIBLE,
          Rect.right - 550,
          Rect.top   +  15,
          535,
          275,
          hWnd,
          (HMENU)listView,
          (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
          NULL);
            //--
            lvColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT;
            lvColumn.pszText = "No";
            lvColumn.fmt = LVCFMT_CENTER;
            lvColumn.cx = 43;
                            ListView_InsertColumn(hListView, 0, &lvColumn);
            //--
            lvColumn.pszText = "[ a[i-1]      ,         a[i] )";
            lvColumn.cx = 151;
            ListView_InsertColumn(hListView, 1, &lvColumn);
            //--
            lvColumn.pszText = "xi";
            lvColumn.cx = 85;
            ListView_InsertColumn(hListView, 2, &lvColumn);
            //--
            lvColumn.pszText = "ni";
            ListView_InsertColumn(hListView, 3, &lvColumn);
            //--
            lvColumn.pszText = "V";
            ListView_InsertColumn(hListView, 4, &lvColumn);
            //--
            lvColumn.pszText = "EV";
            ListView_InsertColumn(hListView, 5, &lvColumn);
            break;
}

There is some redraw functions in WM_PAINT to make ListViews move with a window on maximizing.

        //-- LISTVIEW POSITION
        SetWindowPos(hListViewCh, NULL,\
                            Rect.right - 265,
                            312,
                            250,
                            200,
                            SWP_NOSIZE);
        //-- LISTVIEW POSITION
        SetWindowPos(hListView, NULL,\
                            Rect.right - 550,\
                            Rect.top   +  15,\
                            535,\
                            340,\
                            SWP_NOSIZE|SWP_NOZORDER);
        //--

Upvotes: 0

Views: 931

Answers (1)

David Heffernan
David Heffernan

Reputation: 612934

Resizing child windows in a WM_PAINT is simply wrong and I suspect this to be a big part of your problems.

The code to position the child windows should be run in response to the WM_WINDOWPOSCHANGED message.

Upvotes: 3

Related Questions