Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Find Parent Dialog data in custom control on dialog? [modified]

Find Parent Dialog data in custom control on dialog? [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++data-structureshelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ldsdbomber
    wrote on last edited by
    #1

    I've used a customised list control that does alternate row shading but am also reading an article on how to get red text programmatically. As I'd like this too, I have added the necessary handling of NM_CUSTOMDRAW etc (well, I've found it in the shaded row source file), what I want to do now is if(some member variable in my single dialog) then write this line in red otherwise write it in black since I am in the function void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) what I want to know is how I can "get at" the parent dialog itself that has this listcontrol within it something like .accessvariable maybe CWnd *GetParent(); is the first part, but then how do you get at the member variable (integer array that's within the parent dialog I then thought of something like CTestFolderBrowseDlg* myDlg = (CTestFolderBrowseDlg*)mainDlg; and then using mainDlg as normal, but I can't include the header for my main dialog in this source file without it complaining, so I think I'm not doing this in the proper manner for example if I put #include "TestFolderBrowseDlg.h" into ColoredListCtrl.cpp it starts complaining about testfolderbrowsedlg.h(33) : error C2065: 'IDD_TESTFOLDERBROWSE_DIALOG' : undeclared identifier testfolderbrowsedlg.h(33) : error C2057: expected constant expression which aren't present without the include to TestFolderBrowseDlg, but then the cast to myDlg from CWnd doesn't work -- modified at 12:16 Monday 11th June, 2007

    L 1 Reply Last reply
    0
    • L ldsdbomber

      I've used a customised list control that does alternate row shading but am also reading an article on how to get red text programmatically. As I'd like this too, I have added the necessary handling of NM_CUSTOMDRAW etc (well, I've found it in the shaded row source file), what I want to do now is if(some member variable in my single dialog) then write this line in red otherwise write it in black since I am in the function void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) what I want to know is how I can "get at" the parent dialog itself that has this listcontrol within it something like .accessvariable maybe CWnd *GetParent(); is the first part, but then how do you get at the member variable (integer array that's within the parent dialog I then thought of something like CTestFolderBrowseDlg* myDlg = (CTestFolderBrowseDlg*)mainDlg; and then using mainDlg as normal, but I can't include the header for my main dialog in this source file without it complaining, so I think I'm not doing this in the proper manner for example if I put #include "TestFolderBrowseDlg.h" into ColoredListCtrl.cpp it starts complaining about testfolderbrowsedlg.h(33) : error C2065: 'IDD_TESTFOLDERBROWSE_DIALOG' : undeclared identifier testfolderbrowsedlg.h(33) : error C2057: expected constant expression which aren't present without the include to TestFolderBrowseDlg, but then the cast to myDlg from CWnd doesn't work -- modified at 12:16 Monday 11th June, 2007

      L Offline
      L Offline
      ldsdbomber
      wrote on last edited by
      #2

      OK, this is what I am now trying in the function from the alternate shaded list view void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) ... //////////// LVITEM lvi; memset(&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT; lvi.state = 0; lvi.stateMask = 0; unsigned char LVtext[16]; lvi.cchTextMax = 15; // Length of string to be copied into pszText member lvi.pszText = (LPTSTR)LVtext; // String buffer for pszText member // Nota bene : starts at zero (item) and ends at 'lCols' (last subitem) : lvi.iSubItem = 5; // 6 columns in total, I assume that means 5 is the last one, also tried 4 // Retrieve the text in an item or a subitem of line 'i' : mainDlg->SendMessage(LVM_GETITEMTEXT, (WPARAM) 0, (LPARAM) &lvi); CString resultText(LVtext); if(!strcmp((LPCSTR)LVtext, "Failed")) { do stuff... } /////////// it's never going into the do stuff bit. "Failed" is definitely being written/drawn in the listview report in the last column as per a SetItem call. It would be easier if I could work out how to just get at data belonging to the dialog class itself that holds the listview control, but failing that, am not sure what I am doing wrong here.

      M 1 Reply Last reply
      0
      • L ldsdbomber

        OK, this is what I am now trying in the function from the alternate shaded list view void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) ... //////////// LVITEM lvi; memset(&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT; lvi.state = 0; lvi.stateMask = 0; unsigned char LVtext[16]; lvi.cchTextMax = 15; // Length of string to be copied into pszText member lvi.pszText = (LPTSTR)LVtext; // String buffer for pszText member // Nota bene : starts at zero (item) and ends at 'lCols' (last subitem) : lvi.iSubItem = 5; // 6 columns in total, I assume that means 5 is the last one, also tried 4 // Retrieve the text in an item or a subitem of line 'i' : mainDlg->SendMessage(LVM_GETITEMTEXT, (WPARAM) 0, (LPARAM) &lvi); CString resultText(LVtext); if(!strcmp((LPCSTR)LVtext, "Failed")) { do stuff... } /////////// it's never going into the do stuff bit. "Failed" is definitely being written/drawn in the listview report in the last column as per a SetItem call. It would be easier if I could work out how to just get at data belonging to the dialog class itself that holds the listview control, but failing that, am not sure what I am doing wrong here.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        ldsdbomber wrote:

        mainDlg->SendMessage(LVM_GETITEMTEXT, (WPARAM) 0, (LPARAM) &lvi);

        The wParam should be the index of the item - are you always looking at item 0? Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        L 1 Reply Last reply
        0
        • M Mark Salsbery

          ldsdbomber wrote:

          mainDlg->SendMessage(LVM_GETITEMTEXT, (WPARAM) 0, (LPARAM) &lvi);

          The wParam should be the index of the item - are you always looking at item 0? Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          L Offline
          L Offline
          ldsdbomber
          wrote on last edited by
          #4

          no, I tried passing iRow first and that didn't work either (iRow presumably is the right parameter) void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = 0; LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR; int iRow = lplvcd->nmcd.dwItemSpec; switch(lplvcd->nmcd.dwDrawStage) { case CDDS_PREPAINT : { *pResult = CDRF_NOTIFYITEMDRAW; return; } // Modify item text and or background case CDDS_ITEMPREPAINT: { // ACCESS errTable here, and change font accordingly CWnd* mainDlg = GetParent(); // CTestFolderBrowseDlg* myDlg = (CTestFolderBrowseDlg*)mainDlg; //////////// LVITEM lvi; memset(&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT; lvi.state = 0; lvi.stateMask = 0; unsigned char LVtext[16]; lvi.cchTextMax = 15; // Length of string to be copied into pszText member lvi.pszText = (LPTSTR)LVtext; // String buffer for pszText member // Nota bene : starts at zero (item) and ends at 'lCols' (last subitem) : lvi.iSubItem = 5; // Retrieve the text in an item or a subitem of line 'i' : mainDlg->SendMessage(LVM_GETITEMTEXT, (WPARAM) iRow, (LPARAM) &lvi); CString resultText(LVtext); if(!strcmp((LPCSTR)LVtext, "Failed")) { do something here... } /////////// lplvcd->clrText = RGB(0,0,0); // If you want the sub items the same as the item, // set *pResult to CDRF_NEWFONT *pResult = CDRF_NOTIFYSUBITEMDRAW; return; } // Modify sub item text and/or background case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM: { if(iRow %2){ lplvcd->clrTextBk = m_colRow2; } else{ lplvcd->clrTextBk = m_colRow1; } *pResult = CDRF_DODEFAULT; return; } } }

          M 1 Reply Last reply
          0
          • L ldsdbomber

            no, I tried passing iRow first and that didn't work either (iRow presumably is the right parameter) void CColoredListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = 0; LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR; int iRow = lplvcd->nmcd.dwItemSpec; switch(lplvcd->nmcd.dwDrawStage) { case CDDS_PREPAINT : { *pResult = CDRF_NOTIFYITEMDRAW; return; } // Modify item text and or background case CDDS_ITEMPREPAINT: { // ACCESS errTable here, and change font accordingly CWnd* mainDlg = GetParent(); // CTestFolderBrowseDlg* myDlg = (CTestFolderBrowseDlg*)mainDlg; //////////// LVITEM lvi; memset(&lvi, 0, sizeof(lvi)); lvi.mask = LVIF_TEXT; lvi.state = 0; lvi.stateMask = 0; unsigned char LVtext[16]; lvi.cchTextMax = 15; // Length of string to be copied into pszText member lvi.pszText = (LPTSTR)LVtext; // String buffer for pszText member // Nota bene : starts at zero (item) and ends at 'lCols' (last subitem) : lvi.iSubItem = 5; // Retrieve the text in an item or a subitem of line 'i' : mainDlg->SendMessage(LVM_GETITEMTEXT, (WPARAM) iRow, (LPARAM) &lvi); CString resultText(LVtext); if(!strcmp((LPCSTR)LVtext, "Failed")) { do something here... } /////////// lplvcd->clrText = RGB(0,0,0); // If you want the sub items the same as the item, // set *pResult to CDRF_NEWFONT *pResult = CDRF_NOTIFYSUBITEMDRAW; return; } // Modify sub item text and/or background case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM: { if(iRow %2){ lplvcd->clrTextBk = m_colRow2; } else{ lplvcd->clrTextBk = m_colRow1; } *pResult = CDRF_DODEFAULT; return; } } }

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            >>lvi.iSubItem = 5; // 6 columns in total, I assume that means 5 is the last one, also tried 4 Also. subitems are 1 based. If you have 6 columns, subitem 6 is the last column.

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups