|
The error message says it all. You have tried (probably unintentionally ) to read from an
adddress you are not allowed to read from.
If you run in the debugger you should be able to trace back to the offending code when the
exception occurs.
There's a bad pointer problem somewhere.
Mark
|
|
|
|
|
I have a CListCtrl (m_ListCtrlStyled) on a form (A CFormView based application, developed in VC 6.0 SP6).
I initiate the CListCtrl in the OnInitialUpdate() function like the following.
<br />
<br />
DWORD dwStyle = ::GetWindowLong(m_ListCtrlStyled.m_hWnd, GWL_STYLE); <br />
dwStyle &= ~(LVS_TYPEMASK);<br />
dwStyle &= ~(LVS_EDITLABELS);<br />
SetWindowLong(m_ListCtrlStyled.m_hWnd, GWL_STYLE, dwStyle| LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);<br />
<br />
DWORD styles = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES;<br />
ListView_SetExtendedListViewStyleEx(m_ListCtrlStyled.m_hWnd, styles, styles );<br />
<br />
m_ListCtrlStyled.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);<br />
<br />
<br />
TCHAR rgtsz[3][10] = {_T("SerialNumber"), _T("Doc"), _T("Score")};<br />
<br />
LV_COLUMN lvcolumn;<br />
CRect rect;<br />
m_ListCtrlStyled.GetWindowRect(&rect);<br />
for(int i=0;i<3;i++)<br />
{<br />
lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;<br />
lvcolumn.fmt = LVCFMT_LEFT;
lvcolumn.pszText = rgtsz[i];<br />
lvcolumn.iSubItem = i;<br />
lvcolumn.iOrder = i;<br />
switch (i)<br />
{<br />
case 0 :<br />
lvcolumn.cx = rect.Width()*1/10 ;
break;<br />
case 1:<br />
lvcolumn.cx = rect.Width()*7/10 ;
break;<br />
case 2:<br />
lvcolumn.cx = rect.Width()*2/10 ;
break;<br />
}<br />
<br />
m_ListCtrlStyled.InsertColumn(i, &lvcolumn);<br />
}<br />
<br />
CFont m_font;<br />
<br />
m_font.CreateFont(16, 0,0,0,FW_REGULAR, 0,0,0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier"); <br />
<br />
<br />
<br />
m_ListCtrlStyled.SetFont(&m_font);<br />
<br />
m_ListCtrlStyled.SetBkColor(RGB(247,247,255)); <br />
m_ListCtrlStyled.SetTextBkColor(RGB(247,247,255));<br />
<br />
<br />
The problem is that there was no change of the font when I change "arial" of m_font to other font name, say "courier".
i also tried with the following code , but failed again.
<br />
CWnd *pWnd=GetDlgItem(IDC_LIST2);<br />
CDC *pDC=pWnd->GetDC();<br />
CFont font;<br />
LOGFONT stFont;<br />
memset(&stFont,0,sizeof(LOGFONT));<br />
stFont.lfHeight=MulDiv(12,pDC->GetDeviceCaps(LOGPIXELSY),72); <br />
stFont.lfWeight=FW_NORMAL;<br />
stFont.lfCharSet=GB2312_CHARSET;<br />
strcpy(stFont.lfFaceName,"Arial");
font.CreateFontIndirect(&stFont);<br />
<br />
pWnd->SetFont(&font,TRUE);<br />
<br />
Please help me my friends
-- modified at 3:51 Saturday 2nd December, 2006
|
|
|
|
|
Isn`t UpdateData() needed here? Sorry if I`m wrong
|
|
|
|
|
Hi, Makakuin,
Makakuin wrote: Isn`t UpdateData() needed here? Sorry if I`m wrong
What do you mean. I did not use UpdateData in the my code.
|
|
|
|
|
Try to call UpdateData() right after all changes you need to make to ListCtrl as UpdateData really does "Update data"... This might help..
|
|
|
|
|
Is your CFont object going out of scope before any text is actually displayed?
Try making "CFont m_font;" a member variable instead of a local variable.
Mark
|
|
|
|
|
By the way gtsz[3][10] is too small. It should be gtsz[3][13]. (The strings really shouldn't be hard coded, but I assume this is a test app.)
And the problem as indicated above is that m_font is local and the font handle is being deleted. (The list control is robust enough that it recovers from this error.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
finaly, i found the answer, i should have declare m_font as a class member variable instead of a local variable, since i initiate the CListCtrl in OnInitialUpdate() and use it in another function. A local variable will go out of scope.
|
|
|
|
|
Hi
How can I change(set) the background color of my dialog box?
Thanks in advance
Taruni
|
|
|
|
|
Use SetDialogBkColor()
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
You should handle the WM_CTLCOLOR message.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi All,
I need to know how to set a default value in Combo Box. For example, right now I have a combo box with 3 times in it (Train, Bus, Both). I need to set "BOTH" as a default value in the combo box.
Thanks in advance
C++Prog
|
|
|
|
|
You can send the combobox a CB_SETCURSEL message (CComboBox::SetCurSel() in MFC).
Mark
|
|
|
|
|
Thanks a lot
Can I do it in 'Combo Box properties dialog'..or need to write a code for it?
C++Prog
|
|
|
|
|
Only at runtime, anytime after the Windows object (HWND) is created.
In response to the WM_INITDIALOG message is a good place
Mark
|
|
|
|
|
And...you'll want to do that AFTER you add items to the combobox!
Mark
|
|
|
|
|
I got it.....its working.....Thanks a bunch.
C++Prog
|
|
|
|
|
Here comes another thing...I need to do it dynamically. SetCurSel will make it static.
Thanks again
C++Prog
|
|
|
|
|
Preeti9 wrote: I need to do it dynamically. SetCurSel will make it static.
How so? It should just select/highlight the string, scrolling it into view if necessary.
|
|
|
|
|
o okay...I got it....
Thanks
C++Prog
|
|
|
|
|
|
I`m trying to write SDI MFC application with view class CRichEditCtrl. In my CMyAppView I used GetRichEditCtrl() to access the main RichEditCtrl. Now I want to create an independent class to write to RichEditCtrl lets call it CTextEditor.
What I don`t understand is how to tell the class to find CRichEditCtrl as I`m not able to use GetRichEditCtrl() outside the CMyApp class. I`ve tried to do something like:
<br />
int CTextEditor::WriteText(CRichEditCtrl *wnd,CString str,CHARFORMAT cf)<br />
{<br />
int nOldLines = 0, nNewLines = 0, nScroll = 0;<br />
long nInsertionPoint = 0;<br />
nOldLines = wnd->GetLineCount();<br />
nInsertionPoint = wnd->GetWindowTextLength();<br />
wnd->SetSel(nInsertionPoint, -1);<br />
wnd->SetSelectionCharFormat(cf);<br />
wnd->ReplaceSel(str);<br />
nNewLines = wnd->GetLineCount();<br />
nScroll = nNewLines - nOldLines;<br />
wnd->LineScroll(nScroll);<br />
return 0;<br />
} <br />
And then call it from CMyapView like this:
<br />
CHARFORMAT cf;<br />
cf.dwEffects = CFE_BOLD;<br />
cf.dwMask = CFM_BOLD;<br />
cf.cbSize = sizeof(CHARFORMAT);<br />
CTextEditor editor;<br />
editor.WriteText(&GetRichEditCtrl(),"Mytext",cf); <br />
But I get the unresolved externals error..
What am I doing wrong?
Please help - no clue bout how to use pointers...
|
|
|
|
|
Can you paste error text ?
|
|
|
|
|
Here`s what the build log says...
TestAppView.obj : error LNK2019: unresolved external symbol "public: int __thiscall CTextEditor::WriteText(class CRichEditCtrl *,class ATL::CStringT<char,class strtraitmfc_dll<char,class="" atl::chtraitscrt<char=""> > >,struct _charformat)" (?WriteText@CTextEditor@@QAEHPAVCRichEditCtrl@@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@U_charformat@@@Z) referenced in function "public: void __thiscall CTestAppView::OnPortOpen(void)" (?OnPortOpen@CTestAppView@@QAEXXZ)
C:\Documents and Settings\Raivo\My Documents\Visual Studio 2005\Projects\TestApp\Debug\TestApp.exe : fatal error LNK1120: 1 unresolved externals
|
|
|
|
|
It seems like, somehow CTextEditor class definition is not included in project. Just curious to know, whether you have added cpp containing CTextEditor in to your project.
Because, from error text, its seems so.
|
|
|
|