locked
Visual Studio MFC dialog application. CListCtrl function RRS feed

  • Question

  • I created a dialog application in Visual Studio MFC.

    I use CListCtrl to list some date. (Item and Content)

    I don't change any code in CListCtrl's  cpp and h files but CListCtrl color was from gray to white.


    1) No change any code , I don't understand why CListCtrl color from gray to white?

    2) Any way to change CListCtrl color from white to gary?

    void XXX::Init()
    {
    LONG lStyle;
    lStyle = GetWindowLong(this->m_lst1.m_hWnd, GWL_STYLE);
    lStyle |= LVS_REPORT;
    SetWindowLong(this->m_lst1.m_hWnd, GWL_STYLE, lStyle);
    DWORD dwStyle = this->m_lst1.GetExtendedStyle();
    dwStyle |= LVS_EX_FULLROWSELECT;
    dwStyle |= LVS_EX_GRIDLINES;
    this->m_lst1.SetExtendedStyle(dwStyle);

    this->m_lst1.DeleteAllItems();
    this->m_lst1.InsertColumn(0, _T("Item"), LVCFMT_CENTER, 100);
    this->m_lst1.InsertColumn(1, _T("Content"), LVCFMT_CENTER, 160);

    this->m_lst1.SetExtendedStyle(this->m_lst1.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
    }


    • Edited by gsegria Friday, August 21, 2020 9:19 AM
    Friday, August 21, 2020 8:47 AM

Answers

  • Hi,

    Thank you for posting here.

    >>Any way to instead #program comment(linker, "\"/manifestdepend in dlg1.cpp only and don't affect CListCtrl.cpp ?
    If add #program comment(linker, "\"/manifestdepend....  Any way to draw gray color in CListCtrl.cpp ?

    I suggest you could try to turn off visual styles for a control or for all controls in a window by calling the SetWindowTheme function.

    SetWindowTheme(hwnd, L" ", L" ");

    hwnd is the handle of the window in which to disable visual styles. After the call, the control renders without visual styles.

    Best Regards,

    Jeanine Zhang


    "Visual c++" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    • Marked as answer by gsegria Tuesday, August 25, 2020 1:58 AM
    Monday, August 24, 2020 8:59 AM
  • Further to this suggestion I think the OP would also want to remove visual styles from the list view's header control.  For example, in OnInitDialog -

    	// TODO: Add extra initialization here
    	HRESULT hr = ::SetWindowTheme(m_List.GetSafeHwnd(), L"", L"");
    	hr = ::SetWindowTheme(m_List.GetHeaderCtrl()->GetSafeHwnd(), L"", L"");
    
    

    • Marked as answer by gsegria Tuesday, August 25, 2020 1:58 AM
    Monday, August 24, 2020 9:21 AM

All replies

  • I found out the issue 1) caused by xxx.cpp

    xxx.cpp

    #pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"").

    CListCtrl is in CListCtrl.cpp , 

    Why CListCtrl color is caused by xxx.cpp?





    • Edited by gsegria Friday, August 21, 2020 9:50 AM
    Friday, August 21, 2020 9:12 AM
  • I found out the issue 1) caused by xxx.cpp

    xxx.cpp

    #pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"").

    CListCtrl is in CListCtrl.cpp , 

    Why CListCtrl color is caused by xxx.cpp?





    This #pragma directive instructs Windows to load Version 6 of the common controls dll (which contains the List View control).  If the manifest dependency inserted by this directive is not present, then an earlier version of the Common Controls dll is used which 1) has a different version of the List View Control and 2) does not draw using visual styles.
    Friday, August 21, 2020 10:00 AM
  • Any way to fix this issue?

    Any way to instead #program comment(linker, "\"/manifestdepend in dlg1.cpp only and don't affect CListCtrl.cpp ?

    If add #program comment(linker, "\"/manifestdepend....  Any way to draw gray color in CListCtrl.cpp ?



    • Edited by gsegria Monday, August 24, 2020 7:54 AM
    Monday, August 24, 2020 7:45 AM
  • Any way to instead #program comment(linker, "\"/manifestdepend in dlg1.cpp only and don't affect CListCtrl.cpp ?

    See response from Jeanine Zhang.

    If add #program comment(linker, "\"/manifestdepend....  Any way to draw gray color in CListCtrl.cpp ?

    Use custom draw -- https://docs.microsoft.com/en-us/windows/win32/controls/about-custom-draw#custom-draw-with-list-view-and-tree-view-controls


    • Edited by RLWA32 Monday, August 24, 2020 9:03 AM Referred to Jeanine Zhang answer
    Monday, August 24, 2020 8:43 AM
  • Hi,

    Thank you for posting here.

    >>Any way to instead #program comment(linker, "\"/manifestdepend in dlg1.cpp only and don't affect CListCtrl.cpp ?
    If add #program comment(linker, "\"/manifestdepend....  Any way to draw gray color in CListCtrl.cpp ?

    I suggest you could try to turn off visual styles for a control or for all controls in a window by calling the SetWindowTheme function.

    SetWindowTheme(hwnd, L" ", L" ");

    hwnd is the handle of the window in which to disable visual styles. After the call, the control renders without visual styles.

    Best Regards,

    Jeanine Zhang


    "Visual c++" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    • Marked as answer by gsegria Tuesday, August 25, 2020 1:58 AM
    Monday, August 24, 2020 8:59 AM
  • Further to this suggestion I think the OP would also want to remove visual styles from the list view's header control.  For example, in OnInitDialog -

    	// TODO: Add extra initialization here
    	HRESULT hr = ::SetWindowTheme(m_List.GetSafeHwnd(), L"", L"");
    	hr = ::SetWindowTheme(m_List.GetHeaderCtrl()->GetSafeHwnd(), L"", L"");
    
    

    • Marked as answer by gsegria Tuesday, August 25, 2020 1:58 AM
    Monday, August 24, 2020 9:21 AM
  • Thanks for your examples.

    That is very clearly.


    • Edited by gsegria Tuesday, August 25, 2020 1:59 AM
    Tuesday, August 25, 2020 1:58 AM