|
Alexpro wrote:
This was a possbility. However, I would do a second approach. Create a DataSet object in the caller function and pass it as a pointer or reference to the method that parses the file. Like this
That is a good idea, thanks Alexandru. Hopefully I can fit some of this exception handling into my article
regards,
Paul Watson
Bluegrass
Cape Town, South Africa
The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge
Alison Pentland wrote:
I now have an image of you in front of the mirror in the morning, wearing your knickers, socks and shoes trying to decided if they match!
|
|
|
|
|
Paul Watson wrote:
Should I then let the caller handle it via the exception thrown, or should I trap that exception, handle it
If you decide to handle the exception, you're basically translating the exception to error code. Your client (caller of this function) will have to check for error code. And we all know that it's very easy to forget about this.
We have XXI century now, exceptions are bread and butter of C++; this also applies to this bastard MC++ . And don't worry about performance overhead.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I managed to successfully do this before but I can't remember if it was under OnDrawItem or OnPaint .
Anyways heres what i've managed so far:
CDC* pDC = CDC::FromHandle(LpDIS->hDC);
CBitmap bit;
CRect rect;
CDC dc;
GetClientRect(&rect);
CString buff = GetItemText(LpDIS->itemID, 0);
dc.CreateCompatibleDC(pDC);
bit.CreateCompatibleBitmap(pDC, rect.right, rect.bottom);
CBitmap* hOld = dc.SelectObject(&bit);
dc.FillSolidRect(rect, RGB(128,128,128));
dc.TextOut(LpDIS->rcItem.left, LpDIS->rcItem.top, buff);
pDC->BitBlt(0, 0, rect.right, rect.bottom, &dc, 0, 0, SRCCOPY);
dc.SelectObject(hOld);
ReleaseDC(&dc);
Is it impossible to have flicker free drawing during an OnDrawItem operation...??
Keith Rules CMemDC class also doesn't work...???
Am I missing something...???
Thanx in advance.
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I'm not sure if this is related to flicker problem, but you shouldn't call ReleaseDC. Use DeleteDC or just let CDC d'tor do its job.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Negative...
Nothing that i've learned in the past seems to be effective at stopping flicker...whether its the built in scroll bars or my onwerdrawn code...I hate flicker so very much!!!
Thanx anyways
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
You've overriden OnDrawItem or DrawItem? I'm asking because your code draws all over client rectangle. Where's the flicker? On scrollbar or in the window which contains the scrollbar?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
DrawItem
Interesting I never realized there was a difference...
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
1) What kind of control are you trying to owner-draw?
2) Is your control hosted in dialog or form view? If this is the case, does parent have WS_CLIPCHILDREN style set?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Are you handling the WM_ERASEBGND message for both the control and its parent?
In the parent, you need to exclude the child controls rectangle before eraseing the background.
BOOL CScrollbarsView::OnEraseBkgnd(CDC* pDC)
{
if (m_ScrollWnd.m_hWnd)
{
CRect clip ;
m_ScrollWnd.GetWindowRect(&clip) ;
ScreenToClient(&clip) ;
pDC->ExcludeClipRect(clip) ;
}
return CView::OnEraseBkgnd(pDC);
}
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
I've never handled the Parent's OnEraseBkgnd and has flicker free code ???
Wouldn't CLIP_CHILDREN have the same effect...???
Thanx
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Under certain circumstances, you can make a control flicker free itsekf, only to have the parent window erase it. This can often be the case when re-sizing a parent window, which moves around the child windows, erases them in its OnEraseBkgnd, causing lots of flicker. By excluding any child windows from the erase area of the parent, you can make controls flicker much much less.
An example is in my article:
http://www.codeproject.com/useritems/Scrollbar.asp
This has a dynamically created control which was originally being erased by the parent window every time the form view re-sized. By handling the OnEraseBkgnd correctly, this was drastically reduced.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
your control may flicker if it has class styles CS_HREDRAW or CS_VREDRAW... also, for most windows controls, only handling WM_DRAWITEM or OnDrawItem or whatever will not prevent flicker-free drawing because the "LISTBOX" window class for example, has a background brush which is used to erase the client area in certain situations, before WM_PAINT and WM_DRAWITEM are ever called
my suggestion would be to create a new window class and pass every message except for WM_PAINT to the standard listbox window procedure... then, on WM_PAINT, you could do all of the drawing manually
- Roman -
|
|
|
|
|
Interesting I never even thought of those bits being set...
I'll have to experiment with those...
Thanx!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I am using API called Read file to read the file.I am using Get file size to find file size.
When i print the value in messagebox ,there are lot of junk characters at last.
How to eradicate this Or any other API to do this.
This is my code
hFile = CreateFile("\\pre.txt",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
DWORD BufferSize;
char szMsg[128];
if(hFile)
{
BufferSize=GetFileSize(hFile,NULL);
}
char *sFileContent;
DWORD BytesRead;
sFileContent=(char *)malloc(BufferSize);
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
if(ReadFile(hFile,sFileContent,BufferSize,&BytesRead,NULL))
{
MessageBox(NULL,sFileContent,"value",MB_OK);
}
|
|
|
|
|
After your call to ReadFile has succeeded, you must zero-terminate the string. To be able to do this you must first allocate one byte more than the filesize, and then do
sFileContent[BufferSize] = '\0';
|
|
|
|
|
I would add also
sFileContent=(char *)malloc(BufferSize+1);
|
|
|
|
|
Branislav wrote:
I would add also
sFileContent=(char *)malloc(BufferSize+1);
That's what the part reading "To be able to do this you must first allocate one byte more than the filesize" was intended for.
Though one would never have to work this hard using C++:
std::ifstream foo("filename");
std::string bar;
foo >> bar;
if (!foo.fail()) {
MessageBox(NULL,bar.c_str(),"value",MB_OK);
}
|
|
|
|
|
Hi friends,
I built an MFC project in win98 machine, vc6.0. I could run my program. Now I want to run this program in another machine without loading VC++ in that. What I did I copied the necessary dlls into that system manually and tried to run my exe. I am getting this error: "The xxx.exe file is linked to missing export:MSVCRTD.DLL:chkesp" and "A device attached to the system is not functioning". What does it mean? can anybody help me? Thanks;
satya
|
|
|
|
|
You are trying to run a debug build. You are legally not allowed to redistribute msvcrtd.dll, and therefore can't really distribute a debug build unless you link statically to the CRT (libcd.lib).
|
|
|
|
|
hi,
Basically, this error means that something looking for
of MSVCRTD.DLL (the MicroSoft Visual C RunTime Dynamic
Link Library) is finding a different (probably older) version/ or it is absent. The version it is finding does not have the all the exports (places that things calling the DLL can enter by) that the version it wants has.
Regards,
Sharad Ganesh
|
|
|
|
|
Hi everyone. I recently wrote a program which saves data into a CSV (comma separated value) file. I searched and was unable to find the exact specifications for the format. Since each data string is surrounded in quotes in the file itself, how do I handle quotes in the data string itself? Do I leave them, and only change the commas between quotes, which signify a break between strings? And if I change them, what do I change them to? One CSV file I downloaded had the quotes in the strings changed to %22's. Anybody know more or where I can find more info, so my CSV is compatible with other programs which may read it?
|
|
|
|
|
www.wotsit.org[^]
HTH
Cheers
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Turns out one doubles up quotes within the data string. Thanks for the link!
|
|
|
|
|
1) is it good practice, or even possible, to have one class factory produce instances of many different COM classes?
i'm trying to make a scripting engine using IActiveScript and such, but i have multiple COM classes implementing IActiveScript, IActiveScriptSite, etc... but I don't want to have a class factory for each one
any thoughts?
2) example: a IActiveScriptError pointer gets passed to the OnScriptError function of an IActiveScriptSite... should the function call the script error pointer's Release method or is that not necessary?
- Roman -
|
|
|
|
|
Q2. [in] parameter must be never released in the called function.
With best wishes,
Vita
|
|
|
|