Windows Z order of modeless dialogs, CListCtrl questions

  • Hi,


    currently I'm writing a small C++ MFC application to configure and test the CAN port and have some apparently minor problems that nevertheless are slowing down development considerably as I don't find a solution. Maybe you can help me.


    • The application is dialog based, i.e. the main window is a dialog. By clicking a button in this dialog, the user can open a new dialog window. As every new press of the button should start a new window, these new windows have to be modeless. Now my problem is that, by default, these opened windows are owned by the main dialog, which means they always stay in front of the main window. Even if I click on the main window, it stays in the background. I read that the new window must be created as sibling to the main window to allow it to go behind the main window, not as an owned window. Regarding the instructions, this should be done by giving the same parent window in the creation of the new window. This should also insert a new entry in the taskbar, which is exactly what I want. However this does not work. The main window has 0 as parent, showing that it is partially owned by the desktop. But setting 0 in the Create() function of the new window automatically makes it owned by the application main window (see MFC documentation to CDialog::Create). Whatever I do, the new window has the main window as parent. How can I avoid this? How can I make the new window also be owned by the desktop, e.g. by having 0 as parent?


      Using the desktop itself by giving GetDesktopWindow() in Create(), as I read on the internet for a similar situation, does make a difference. Now it is possible to get the main window to the front. But this also does not work correctly, as it always brings up the desktop too, when clicking on the new window, hiding the main window behind the desktop. This is also not what I want. And the taskbar entry is still missing, too.


      Here is the code that I use right now to create the window. In the main window when pressing the button:

      Code
      1. CCanChannel *pCanChannel = new CCanChannel(hCanPort, dwAccess, GetParent());


      In the new window during construction:

      Code
      1. CCanChannel::CCanChannel(HANDLE hCanPort, DWORD dwAccess, CWnd* pParent /*=NULL*/)
      2. : CDialog(CCanChannel::IDD, pParent)
      3. {
      4. Create(CCanChannel::IDD, pParent);
      5. }


      I even tried to override the default settings by setting a new owner in PreCreateWindow() in several ways, for example like this. Nothing worked.

      Code
      1. BOOL CCanChannel::PreCreateWindow(CREATESTRUCT& cs)
      2. {
      3. cs.hwndParent = GetDesktopWindow()->GetSafeHwnd();
      4. cs.dwExStyle |= WS_EX_APPWINDOW;
      5. return CDialog::PreCreateWindow(cs);
      6. }



    • In my dialog I'm using a CListCtrl in Report style. As the dialog is rather small (should work on small displays, too), there is not much room in the list control. Only a few content lines are visible. Therefore I added a checkbox that should make it possible to hide (and show again) the header line of the control to make room for an additional line in the list. But how can this be done? I already tried to hide the CHeaderCtrl, which made the header disappear, but the list did not grow larger and did not use the space of the header line.

      Code
      1. m_clListCtrl.GetHeaderCtrl()->ShowWindow(FALSE);


      Do you have a quick idea how to switch on and off the header correctly? As the other styles of the CListCtrl also hide the header line, there should be some automatic way to do this, shouldn't it?



    • The same CListCtrl is empty at the beginning, but will grow with time. This means at some point the vertical scroll bar will appear. I want to avoid this behaviour and instead I want to see the vertical scrollbar from the beginning, but disabled. There is a setting SIF_DISABLENOSCROLL for windows to get exactly this behaviour. This works well for example with the main dialog window, but not with the CListCtrl window. Do you have any idea why not?

      Code
      1. SCROLLINFO cScroll;
      2. cScroll.cbSize = sizeof(SCROLLINFO);
      3. cScroll.fMask = SIF_DISABLENOSCROLL;
      4. m_clListCtrl.SetScrollInfo(SB_VERT, &cScroll);


    Thanks in advance for any help or hints that you can give me.


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.

  • OK, I found the solution to #2. The column headers can be switched by setting the window style LVS_NOCOLUMNHEADER. I wasn't aware that this value can be given as normal windows style (whose values usally begin with WS_) and therefore be modified with function ModifyStyle(). But it's as simple as that:


    Code
    1. void CCanChannel::OnBnClickedChHideheaders()
    2. {
    3. if (m_ccHideHeaders.GetCheck())
    4. m_clListCtrl.ModifyStyle(0, LVS_NOCOLUMNHEADER, 0);
    5. else
    6. m_clListCtrl.ModifyStyle(LVS_NOCOLUMNHEADER, 0, 0);
    7. }


    H. Keller

    F&S Elektronik Systeme GmbH
    As this is an international forum, please try to post in English.
    Da dies ein internationales Forum ist, bitten wir darum, Beiträge möglichst in Englisch zu verfassen.