|
Hi,
I like to know if this is the right way to count the number of open documents in MDI :
int i=1;
CWinApp* pApp = AfxGetApp();
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
while (posTemplate)
{
posTemplate = pApp->GetFirstDocTemplatePosition();
i++;
}
thanks
Ehsan Behboudi
|
|
|
|
|
This will count the document templates, not the document themselves, and only if you replace GetFirstDocTemplatePosition with GetNextDocTemplate inside the while(...) loop.
With a doctemplate, you can count the documents using CDocTemplate::GetFirstDocPosition/GetNextDoc. You'll have two nested loops - outer loop for iterating over templates and inner loop for documents.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
thanks for your help,
I have a small question. How can I cast the pDoc pointer so I could have access to the data of the corresponding document.
int i=0;
int nDocCount = 0;
CWinApp* pApp = AfxGetApp();
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
while (posTemplate)
{
CDocTemplate *pDocTemplate=pApp->GetNextDocTemplate(posTemplate);
if(NULL!=pDocTemplate)
{
POSITION posDoc = pDocTemplate->GetFirstDocPosition();
while(posDoc)
{
CDocument *pDoc = pDocTemplate->GetNextDoc(posDoc);
////////////////////////////////////////////////////
//I need another pointer to the data of the corresponding doc, or i have to cast pDoc. How can I do that.
///////////////////////////////
if(NULL!=pDoc)
nDocCount++;
}
}
i++;
}
TRACE("%d",nDocCount);
Thanks
Ehsan Behboudi
|
|
|
|
|
How can I cast the pDoc pointer so I could have access to the data of the corresponding document
Try this...
CDocument *pDoc = pDocTemplate->GetNextDoc(posDoc);
CMyDocument *pMyDoc = (CMyDoc *)pDoc;
... or this:
CDocument *pDoc = pDocTemplate->GetNextDoc(posDoc);
CMyDocument *pMyDoc = static_cast<CMyDocument *>(pDoc);
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I've created a splitted window. And I want my left part of the window to be not less than 150 pixels by X axis. How can I do this?
With the best regards, Vitaly.
|
|
|
|
|
Use CSplitterWnd::SetColumnInfo/SetRowInfo. They have a parameter that controls the minimum pane size.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
No, it isn't work the way I need. If I reduce the column width less than cxMin value - it's width will be set to 0. But I need it to be set to the cxMin. At this moment I'm trying to make a child class for CSplitterWnd and correct the width in RecalcLayout().
With the best regards, Vitaly.
|
|
|
|
|
yeah! it works
With the best regards, Vitaly.
|
|
|
|
|
I see - user can drag the splitter to hide a column. RecalcLayout looks very ugly - maybe it's better to hack into OnMouseMove?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Do you find this ugly?
void CVertSplitter::RecalcLayout() {
CSplitterWnd::RecalcLayout();
int cur, min;
GetColumnInfo(0, cur, min);
if (cur < min) {
SetColumnInfo(0, min, min);
CSplitterWnd::RecalcLayout();
}
}
With the best regards, Vitaly.
|
|
|
|
|
Mea culpa. I didn't realize that RecalcLayout is virtual and you'll have to take the source of CSplitterWnd and make substantial changes.
Cheers,
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I need to run an application from screen saver. When screen saver exists I use this code to launch application.
STARTUPINFO si;
PROCESS_INFORMATION ProcessInformation;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpTitle = NULL;
si.lpDesktop = _T("WinSta0\\Default");
si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
si.dwFlags = 0;;
si.wShowWindow = SW_SHOW;
si.lpReserved2 = NULL;
si.cbReserved2 = 0;
if (::CreateProcess(lpApplicationName, lpszCmdLine, NULL, NULL, FALSE,
0, NULL, NULL, &si, &ProcessInformation))
{
::CloseHandle(ProcessInformation.hProcess);
::CloseHandle(ProcessInformation.hThread);
}
But problem is, this code launch application successfully on Win NT, but I can'tsee launched application on desktop of Win 2k. Another important thing is that when I shutdown my Win 2k system then while shuting down I can see that launched application. I don't know on which desktop this Win 2k launch application.
Please help me in his problem, as I m not getting any idea, as the code is working fine on NT, but is creating problem on Win 2k.
Please help me.
Waiting for reply!
Thanx.
I m really about this Win2k behaviour.
|
|
|
|
|
Just curious: did you try with
si.lpDesktop = NULL; ?
Paolo.
|
|
|
|
|
I'm trying to create a thin frame window, which can still be resized. Problem is that whenever removing the WS_THICKFRAME style from the window I loose the ability to resize the window. How can maintain the resizing capability?
|
|
|
|
|
|
I asked this question yesterday but got no response so will try again. I have used this function successfully in the past, so don't know why I can't get it to work now.
I have the follow file on disk D:\Import\ReadMe.txt, when I search for it, it doesn't get found.
According to help I need to call FindNextFile() after I call FindFile() before I can access any of the other member functions
::SetCurrentDirectory("D:\\Import");
CFileFind Find;
Find.FindFile("ReadMe.txt");
while (Find.FindNextFile())
{
if (!Find.IsDots() &&
!Find.IsDirectory())
{
CString strMsg = Find.GetFilePath();
strMsg += " found.";
AfxMessageBox(strMsg, MB_OK | MB_APPLMODAL | MB_ICONSTOP);
}
}
Find.Close();
Any ideas what I have stuffed up and more importantly any answers to my problem?
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
You should use BOOL value returned from FindFile:
BOOL bWorking = finder.FindFile("D:\\dir\\ReadMe.txt");
while (bWorking)
{
bWorking = finder.FindNextFile();
if (!finder.IsDots() && !finder.IsDirectory())
{
CString strMsg = finder.GetFilePath();
strMsg += " found.";
AfxMessageBox(strMsg, MB_OK | MB_APPLMODAL | MB_ICONSTOP);
}
}
finder.Close();
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Tomasz
thanks for your response. I know about the use of BOOL, laziness stops me from using it in this instance. If I search for *.* instead of ReadMe.txt FindNextFile() will find
. Current Directory
.. Parent Directory
but will fail to find any other files I have in the directory, if I search for a specific file by name it also fails to find it.
I am running this under Windows 2000 Professional SP2 and the actual directory name is D:\DevelopC++\Supplier\Debug\Import. Not sure if the problem is actually being caused by the fact the directory is under the Debug directory used by Visual Studio to create the executable in.
Still completely stumped, as I have been for the last 2 days.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
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!
|
|
|
|