|
Thanks for all your help!!!
Rob
|
|
|
|
|
Hi,
I've written a very simple custom static control that allows you certain control over formatting via HTML type tags (bold, italic and underlined).
I've got it working, but when you drag a window over the control and it gets repainted, the memory usage for the program goes up collosally, which is obviously a memory leak.
I've traced the problem to creating the fonts, via CFont, but despite DeleteObjects and just plain deletes of the CFont object/pointer, the memory leak is still there.
I'm creating a font every time the WM_PAINT message is called using the CreateFont() function. I've tried saving the old font then restoring the old font at the end but this doesn't help either.
Is anyone who knows what they're doing with GDI willing to have a look through the code (180 lines .cpp and .h) if I email it to them, as I really haven't a clue what's wrong.
Many thanks,
Peter
|
|
|
|
|
This is a classic. You're trying to call DeleteObject on a GDI object selected into device context. If you're dealing with font, save the CFont pointer returned SelectObject, and select it back before calling DeleteObject:
CFont f;
f.CreateFont(...);
CFont *pOldFont = dc.SelectObject(&font);
dc.SelectObject(pOldFont);
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for the tips but it didn't help.
I've posted the full OnPaint code under the original thread so maybe that will help?
Cheers,
Peter
|
|
|
|
|
I've just realized that you're already restoring the old font. Sorry for first response - email the code to shooltz@shooltz.com - I'll have a look.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Right here's the OnPaint code:
void CCustStatic::OnPaint()
{
CPaintDC dc(this);
CString strText;
GetWindowText(strText);
CRect rect;
GetClientRect(rect);
rect.DeflateRect(CSize(1, 1));
dc.FillSolidRect(rect, m_Colour);
int nMode = dc.SetBkMode(TRANSPARENT);
if (m_bSimple == TRUE)
{
CFont font;
font.CreateFont(-MulDiv(m_nSize, GetDeviceCaps(CreateCompatibleDC(NULL), LOGPIXELSY), 72),0,0,0,m_nWeight,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial");
CFont *oldfont = dc.SelectObject(&font);
if (m_bCentred == TRUE)
{
CSize Extent = dc.GetTextExtent(strText);
CPoint pt(rect.CenterPoint().x - Extent.cx/2,
rect.CenterPoint().y - Extent.cy/2);
if (!strText.IsEmpty())
{
dc.TextOut(pt.x, pt.y, strText);
}
}
else
{
CRect rect2 = rect;
rect2.DeflateRect(CSize(2,2));
dc.DrawText(strText, strText.GetLength(), rect2, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX);
}
dc.SelectObject(oldfont);
}
else
{
int nX, nY = 0;
if (m_bCentred == TRUE)
{
CString strTextTemp = "";
for (int j = 0; j < strText.GetLength(); j++)
{
if (strText[j] == '<')
{
if (strText[j + 1] == '/')
{
j ++;
}
j ++;
j ++;
j ++;
}
else
{
strTextTemp += strText[j];
}
}
CFont font;
font.CreateFont(-MulDiv(m_nSize, GetDeviceCaps(CreateCompatibleDC(NULL), LOGPIXELSY), 72),0,0,0,m_nWeight,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial");
CFont *oldfont = dc.SelectObject(&font);
CSize Extent = dc.GetTextExtent(strTextTemp);
nX = rect.CenterPoint().x - Extent.cx/2;
nY = rect.CenterPoint().y - Extent.cy/2;
dc.SelectObject(oldfont);
}
else
{
nX = rect.left;
nY = rect.top;
}
BOOL bInsideTag = FALSE;
BOOL bBold = FALSE;
BOOL bItalic = FALSE;
BOOL bUnderLined = FALSE;
BOOL bEndTag = FALSE;
for (int i = 0; i < strText.GetLength(); i++)
{
if (!bInsideTag)
{
if (strText[i] == '<')
{
bInsideTag = TRUE;
continue;
}
CFont font;
if (bBold == TRUE)
{
font.CreateFont(-MulDiv(m_nSize, GetDeviceCaps(CreateCompatibleDC(NULL), LOGPIXELSY), 72), 0, 0, 0, m_nWeight + 200, bItalic, bUnderLined, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial");
}
else
{
font.CreateFont(-MulDiv(m_nSize, GetDeviceCaps(CreateCompatibleDC(NULL), LOGPIXELSY), 72), 0, 0, 0, m_nWeight, bItalic, bUnderLined, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial");
}
CFont *oldfont = dc.SelectObject(&font);
CString strChar = strText[i];
CSize sSize = dc.GetTextExtent(strChar);
dc.TextOut(nX, nY, strChar);
nX += sSize.cx;
dc.SelectObject(oldfont);
}
else
{
if (strText[i] == 'b')
{
if (strText[i - 1] == '/')
{
bBold = FALSE;
}
else
{
bBold = TRUE;
}
continue;
}
else if (strText[i] == 'i')
{
if (strText[i - 1] == '/')
{
bItalic = FALSE;
}
else
{
bItalic = TRUE;
}
continue;
}
else if (strText[i] == 'u')
{
if (strText[i - 1] == '/')
{
bUnderLined = FALSE;
}
else
{
bUnderLined = TRUE;
}
continue;
}
else if (strText[i] == '>')
{
bInsideTag = FALSE;
continue;
}
}
}
}
dc.SetBkMode(nMode);
}
m_nSize, m_nWeight and m_Colour are all member variables of the control.
Thanks,
Peter
|
|
|
|
|
GetDeviceCaps(CreateCompatibleDC(NULL), LOGPIXELSY)
You're creating and leaking two DCs in each OnPaint. Use dc.GetDeviceCaps instead.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks for that!
I'd never have found that.
Cheers,
Peter
|
|
|
|
|
Hi,
I am trying to find the difference between 2 CTime objects so that I'll know the difference in number of days. But it doesn't seem to work right. Attached is my code. nDays is returning a large negative number while I thought it should return the no. of days difference between the two CTime objects. Any suggestions/ideas/comments would be greatly appreciated.
CTime fileCreatedTime;
....
....
//Find the file's creation time
inputFinder.GetCreationTime(fileCreatedTime);
CTime currentTime = CTime::GetCurrentTime();
CTimeSpan timeDifference = currentTime - fileCreatedTime;
long nDays = timeDifference.GetDays();
Thanks,
|
|
|
|
|
|
|
I'd suspect fileCreatedTime variable - here's the excerpt from CFileFind::GetCreationTime docs:
Note Not all file systems use the same semantics to implement the time stamp returned by this function
Check what's returned from CFileFind::GetCreationTime - is it TRUE?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Yes, I am checking for what it is returning. But I believe I found the problem. I was off by 2 minutes from the when it was created yesterday versus when I ran it today. So, it considered the nDays to be 0 since it did not match up to the exact minute/seconds.
Thanks a lot for your help.
|
|
|
|
|
Hi,
I am using CHTMLview as a convenient activeX document container for a Word document.
The problem is i would like
Does anyone know if this is possible? Or any good resource for creating my own activeX document container
I know GetHTMLDocument returns a IUnknown.
Cheers
Richard
|
|
|
|
|
I am trying to query a DB2 database to get MAX(CCP_START_DT) where CCP_END_DT = database null. Following is my code for the main function. I've created the recordset member variable as well as the parameter variable as COleDateTime object. But I don't seem to get anything back. Is there something I am doing wrong? Any ideas/suggestions would be greatly appreciated.
void RetrieveMaxAddressStartDate()
{
rsDlrAdStartDate.m_CNSMR_NBRParam = nDlrConsumerNbr;
rsDlrAdStartDate.m_CNTCT_CDParam = 10;
rsDlrAdStartDate.m_MAIL_RSTRN_CDParam = 9;
rsDlrAdStartDate.m_CCP_END_DTParam.SetStatus(COleDateTime::null);
rsDlrAdStartDate.SetParamNull(3, TRUE);
rsDlrAdStartDate.m_CCP_STRT_DT.SetStatus(COleDateTime::valid);
rsDlrAdStartDate.m_strFilter =
"CNSMR_NBR = ? AND CNTCT_CD = ? AND MAIL_RSTRN_CD != ? AND CCP_END_DT = ?
WITH UR";
CString strCmd =
"SELECT MAX(CCP_STRT_DT) FROM GM99GCP1.CNSMR_CNTCT_PT ";
if (rsDlrAdStartDate.Open(CRecordset::forwardOnly, strCmd) != 0)
{
//Loop through the recordset to retrieve data
short nFields = rsDlrAdStartDate.GetODBCFieldCount();
while (!rsDlrAdStartDate.IsEOF())
{
CString addressStartDateFormat = rsDlrAdStartDate.m_CCP_STRT_DT.Format("%m%d%Y");
addressStartDate = rsDlrAdStartDate.m_CCP_STRT_DT;
rsDlrAdStartDate.MoveNext();
}
rsDlrAdStartDate.Close();
}
Thanks,
|
|
|
|
|
Hi,
I Try to write A single ISAPI for some uses , At the first My .DLL must Authenticate user then load a new page and with given User/Pass do something, But I didn't used from .ASP and I want to have my all of functions and pages in my ISAPI.DLL but when I use an Global variable, it is available in all sessions.
In ASP we can define variable like Session("value"), and and can access it from an another .ASP but I don't want use any .ASP only my dll, Please tell me if you can, VERY IMPORTANT.
Regards,
|
|
|
|
|
Hi,
I have a CListCtrl with one column in a dialogbox. The DialogBox is a System Modal Dialog Box.
The user is allowed to click on the List items and modify them. However, there should not be any duplicates.
To prevent duplicate enteries, the system checks for the user enteries and throws a dialog box indicating an error. This dialog box is also System Modal.
When the user modifies the contents of one item and sets it to a duplicate value and then presses enter, the error dialog box appears and has the focus and can be clicked.
However, when the user modifies the contents of one item and sets it to a duplicate value and then clicks on the side, the error dialog box appears, but its OK button does not have a focus and thus things appear to be all locked up.
Any idea why this happens?
|
|
|
|
|
Actually I noticed that my problem is that I lose focus when I click. When I enter, the focus still remains on the modified element.
So how do I make sure that the selected item maintains its focus both with the Enter and Click?
|
|
|
|
|
I think this is the standard listctrl behavior, that is when you click outside the control it loses focus, and unfortunately I think there's no simple work-around.
You could try to set againg the focus to the listctrl when the parent dialog becomes active, that is it's receiving a WM_ACTIVATE message. Maybe you should do it once only after the warning messagebox is closed, otherwise every activation would set the focus to the listctrl and the user could get confused.
I think you can't set the focus in the notification handler for the LVN_ENDLABELEDIT, because the WM_KILLFOCUS message can't be processed while you are in a message handler, so the control still has the focus there.
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
What is the command to set the focus on one of the Listview items in random?
I mean if I go SendMessage, what parameters should I send?
|
|
|
|
|
Hi
Unhandled Exception in .....!
Dump of ExceptionPointer structure:
Exception Code:c0000005. Exception Address: bfdf388d
this is the log file from my application. how can I find where is this addres.
|
|
|
|
|
Hi,
I don't think you're going to be able to find this address. If you run the Dependency Viewer (depends.exe) you'll be able to see all of the function entry points of the various modules included in your program, but I'd say that bfdf388d is way out of their address range.
Have you tried running your program in the debugger and catching ALL exceptions? Then the debugger will stop at the point at which the exception is raised which should help you track down the problem.
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
this is log file is generated by the app runing on client machine. I cant put debuger there.
Thanks anyway.
|
|
|
|
|
Okay, I have been working on this forever, but I have a file properties dialog in our application. I also have Windows Explorer using my DLL. I need to research the following things, and I hope y'all can help a confused gal:
(1) How can I have the Windows Explorer provided General Tab Property page show up in my application? I have created my own, but I prefer using the system's.
(2) Where in the world is the data persisted? Stuff like Comments, Author and other data located on the Summary Tab- where is this saved? On the registry? How can I obtain and save it myself? I have been just persisting and reading from an XML file, but I have no idea what's going on with the system stuff.
Please Help
Thanks,
Lilian
|
|
|
|
|
Where in the world is the data persisted?
If you're using W2K, it's stored in a 'Document Summary Info' stream. Alternate file streams are a NTFS-only feature. Write something at a 'Summary' page, then drag the file to A: - you'll see the warning about data loss; only the main stream will be copied to floppy.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|