Find Parent Dialog data in custom control on dialog? [modified]
-
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
-
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
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.
-
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.
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
-
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
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; } } }
-
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; } } }
>>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