|
I know about the use of BOOL, laziness stops me from using it in this instance.
Laziness can hurt here. If your search is going to return exactly one result, your while loop will never execute if you discard the return value of FindFile and use FindNextFile instead. Anyway, CFindFile works perfectly for me - maybe your problems are caused by SetCurrentDirectory? I'd get rid of it and concat mask (*.* or whatever) with dir name.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Going to try your advice now. Funny thing is I originally was concatenating *.* to the directory name and when that wasn't working I changed to SetCurrentDirectory().
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
I've dusted off some old code, and it turns out that you can't use
find.FindFile("...")
while (find.FindNExtFile())
{
}
You'll lose last file returned. You have to play with temp BOOL variable, just like in my first reply to your post.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Tomasz
got it now, thanks for your help. Don't know if I mis-read the help or just can't find it now but it definitely told me to use FindNextFile() before I could do anything with the files.
This is wrong.
FindFile() gets the first file and I can use any member function of CFileFInd to get information on that file, FindNextFile() gets the second, third file etc.
I was screwing myself by not accessing any file information until after I had looked for the second file which didn't exist
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
This is indeed documented in very confusing way. But you have to call FindNextFile before you get the file details with GetFilePath. Otherwise, your app will assert and die.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
it definitely told me to use FindNextFile() before I could do anything with the files. This is wrong.
No, your confusion comes from the bad design of FindNextFile(). In your previous code, you had
while ( finder.FindNextFile(...) ) which seems logical. One would think that FindNextFile() returns false once you iterate through the entire list of files. However, it returns false when you hit the last file, not after you hit the last file. So your test needs to be something like:
BOOL bGo = TRUE;
while ( bGo )
{
bGo = finder.FindNextFile(...);
} So in summary, when FindNextFile() returns FALSE, there is still one more file to process.
--Mike--
http://home.inreach.com/mdunn/
Push the button, Frank.
|
|
|
|
|
I write apps in C++ (using VC++) and often I'm not sure where to palce the classes. For example, if I have a class that interact with a database (CDaoMyClass) I put a reference to this class in the CMyDocument class. Is it right?
I have some trouble in design the class hirerchy for my applycation.
Is there a book that teach how to design a GOOD application with an Object Oriented approach? I mean the Style of programming is important!!!
Thanks!
|
|
|
|
|
For example, if I have a class that interact with a database (CDaoMyClass) I put a reference to this class in the CMyDocument class. Is it right?
What do you mean by a 'reference'? Something like this?
// member of CMyDocument
CDaoMyClass &m_rDaoMyClass;
Is there a book that teach how to design a GOOD application with an Object Oriented approach?
'Design Patterns' by Gamma et al.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
The 'Orthodox' way is to store all persistent data in the applications document. There are problems with doing this:
Eg.
You have an SDI application, with a control bar, nested in control bar is a custom list ctrl. Now from the list ctrl you need to display data stored in the document, this is where MFC becomes very messy.
You do the following,
1/ Get the MainFrame (AfxGetMainWnd and cast to CMainFrame*)
2/ Get the ActiveDocment (GetActiveDocument and cast to CMyDoc)
This completely sucks, however I have lived with this for 7 years.
The other solution is a MVC (Model/View/Controller) pattern, Stingray have developed a class framework implementing MVC (unfortunately I haven't used this). MVC is a much OOD way of the DOC/View metaphor.
Regards
Norm
|
|
|
|
|
I am working with a drawing program. I want to draw rotated ellipse(I dont't want to use rotated DC),but I fond the pen caps can only be round in win98. So I write
"LineTo" myself. But I found its speed was too slow. So please help me, tell where can find fastest code.
thanks to all the programmers who have helped me.
|
|
|
|
|
You can draw rotated ellipse using approximation with Bezier segments. The code below may be just what you want (I've extracted it from some old app - found the code on the net); the degrees parameter controls the rotation
void EllipseEx(CDC &dc, int cx, int cy, int rx, int ry, int degrees)
{
const int Segments = 12;
const int PointCount = 1 + 3 * Segments;
const double Alpha = 3.14159265359 / Segments;
const double Beta = 4 * (1 - cos(Alpha)) / (3 * sin(Alpha));
double px[PointCount], py[PointCount];
double Angle, CosA, SinA;
for (int i = 0; i < Segments; i ++)
{
Angle = 2 * i * Alpha;
CosA = cos(Angle);
SinA = sin(Angle);
int k = 3 * i;
int j = (i == 0) ? 3 * Segments - 1 : k - 1;
px[k] = rx * CosA;
py[k] = ry * SinA;
SinA *= Beta * rx;
CosA *= Beta * ry;
px[j] = px[k] + SinA;
py[j] = py[k] - CosA;
px[k + 1] = px[k] - SinA;
py[k + 1] = py[k] + CosA;
}
px[PointCount - 1] = px[0];
py[PointCount - 1] = py[0];
Angle = 2 * 3.1415927 * degrees / 360;
CosA = cos(Angle);
SinA = sin(Angle);
POINT pt[PointCount];
for (i = 0; i < PointCount; i ++)
{
pt[i].x = cx + (LONG)(0.5 + px[i] * CosA - py[i] * SinA);
pt[i].y = cy + (LONG)(0.5 + px[i] * SinA + py[i] * CosA);
}
PolyBezier(dc, pt, PointCount);
}
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
thank you! Do you have the code of LineTo? Mine is much slower than the CDC::LineTo. And how to create a pen with square cap in win98?
thanks to all the programmers who have helped me.
|
|
|
|
|
Do you have the code of LineTo? Mine is much slower than the CDC::LineTo.
Why do you need your own LineTo?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi, I have programm in VB, where is transparent window. And I rewrite code to MFC. But i have problemm ((. I dont know why ?!, but i see only black color on screen .
Can you help me ?? Here is my code.
_________________________________________
void CMyDialog::DrawScreen(CDC* dc){
CDC *window=GetDesktopWindow()->GetDC();
CDC *drawing = new CDC;
CBitmap *bitmap = new CBitmap;
CBitmap* oldbit;
drawing->CreateCompatibleDC(window);
bitmapa->CreateCompatibleBitmap(window,1050,1004);
oldbit = drawing->SelectObject(bitmap);
dc->BitBlt(0, 0, 100, 100, drawing, 1000, 730, SRCCOPY);
drawing->SelectObject(oldbit);
}
________________________________________
LB
|
|
|
|
|
You're trying to blt from uninitialized bitmap selected into the 'drawing' variable. Can't you just use the 'window' DC as a source?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Can you write my the code ?
Please .
lb
|
|
|
|
|
Ohhh, I have it. But : when I use BilBlt--> programm display the picture. And this picture is dialogwindow of programm . But i need picture which is unter the window ?? How can i do it ??
|
|
|
|
|
But i need picture which is unter the window ?? How can i do it ??
What worked OK in your VB program?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
This is code from program in VB :
Function hDCToPicture(ByVal hDCSrc As Long, ByVal LeftSrc As Long, ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Picture
Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long, R As Long
Dim hPal As Long, hPalPrev As Long, RasterCapsScrn As Long, HasPaletteScrn As Long
Dim PaletteSizeScrn As Long, LogPal As LOGPALETTE
'Create a compatible device context
hDCMemory = CreateCompatibleDC(hDCSrc)
'Create a compatible bitmap
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
'Select the compatible bitmap into our compatible device context
hBmpPrev = SelectObject(hDCMemory, hBmp)
R = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, vbSrcCopy)
hBmp = SelectObject(hDCMemory, hBmpPrev)
R = DeleteDC(hDCMemory)
Set hDCToPicture = CreateBitmapPicture(hBmp, hPal)
End Function
Private Sub Form_Load()
dsk = GetDesktopWindow()
'Create a picture object from the screen
Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY)
srcdc = GetDC(dsk)
Set Me.Picture = hDCToPicture(srcdc, Left / Screen.TwipsPerPixelX, Top / Screen.TwipsPerPixelY, Width / Screen.TwipsPerPixelX, Height / Screen.TwipsPerPixelY)
End sub
Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Picture
Dim R As Long, Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID
'Fill GUID info
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
'Fill picture info
With Pic
.Size = Len(Pic) ' Length of structure
.Type = vbPicTypeBitmap ' Type of Picture (bitmap)
.hBmp = hBmp ' Handle to bitmap
.hPal = hPal ' Handle to palette (may be null)
End With
'Create the picture
R = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
'Return the new picture
Set CreateBitmapPicture = IPic
End Function
|
|
|
|
|
It seems that you're trying to copy the desktop window to a bitmap first. Next, you want to display a dialog and paint its background using saved image. There's a class encapsulating a memory DC and a bitmap on code project; search for CMemDC.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I would to monitor the memory usage as given in the taskmanager , i would be more helpful if some one provide the solution .
GG
|
|
|
|
|
|
Hi all,
I'm writing program about database,
In my program i have three dialogs, and i have to use of CDaoDatabase object in all dialogs ...
I want to use of only one object for do that,
How can i do that ???
Does i must create global variable ?
I mean, writing CDaoDatabase g_db; in first of my source code, and using of extern CDaoDatabase g_db; in other cpp files ???
Do you have any idea ?
My program is in SDI mode ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Make your CDaoDatabase an application data member and provide an accessor function in your app class...
class CYourApp : public CWinApp
{
public:
CDaoDatabase& GetDatabase() { return m_db; }
private:
CDaoDatabase m_db;
};
... and use AfxGetApp in your dialogs to get access to db:
CDaoDatabase &db = static_cast<CYourApp *>(AfxGetApp())->GetDatabase();
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi Tomasz, and thanks for reply ...
Can you explain more about your source codes ...
For example, first, you make private member variable CDaoDatabase m_db; and then you make public member function CDaoDatabase &GetDatabase(){return m_db;} !!!
WHY ???
Why you make GetDatabase() function ? why i shouldn't use of only m_db ?
And please explain to me how can i use of GetDatabase() function ...
Because i'm beginner ...
Thanks again ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|