|
It's been awhile since I did this, but this can be accomplished using an MDI interface. The first step is to match all your documents, child frame, and view classes together. This is done in your apps InitInstance function
CMultiDocTemplate* pDocTemplate = new CMultiDocTemplate(
IDR_MY_TYPE_ONE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CMyView1));
AddDocTemplate(pDocTemplate);
pDocTemplate = new CMultiDocTemplate (
IDR_MY_TYPE_TWO,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CMyView2));
AddDocTemplate(pDocTemplate);
CMainFrame* pMainFrame = new CMainFrame;
The IDR_MY_TYPE_ONE and IDR_MY_TYPE_TWO are the resource defines for the string table strings that that name your templates.
IDR_MY_TYPE_ONE "\nTypeOne\n"
IDR_MY_TYPE_TWO "\nTypeTwo\n" The string after the first newline (\n) is used to name the document template.
You then have to override CMainFrame::OnFileNew() so that it uses the proper template
void CMainFrame::OnFileNew()
{
CDocTemplate *pTemplate = GetTemplate(_T("TypeTwo"));
if (pTemplate)
pTemplate->OpenDocumentFile(NULL);
} In CMainFrame::OnFileOpen you would pass the file name to OpenDocumentFile().
To open a new view of an already open document, you have to add the menu message handlers to your document class
void CMyDoc::OnNewViewTypeOne()
{
CDocTemplate *pDocTemplate = GetTemplate(_T("TypeOne"));
if (pDocTemplate)
{
CFrameWnd *pFrame = pDocTemplate->CreateNewFrame(this, NULL);
if (pFrame)
pFrame->InitialUpdateFrame(this, TRUE);
}
}
Here is the code for GetTemplate
CDocTemplate *GetTemplate (CString str)
{
CString strDoc;
CDocTemplate *pTemplate = NULL;
bool templatefound = false;
POSITION pos = AfxGetApp()->m_pDocManager->GetFirstDocTemplatePosition();
while (pos)
{
pTemplate = (CDocTemplate *)AfxGetApp()->m_pDocManager->GetNextDocTemplate(pos);
pTemplate->GetDocString(strDoc, CDocTemplate::docName);
if (strDoc == str)
{
templatefound = true;
break;
}
}
if (!templatefound)
{
TRACE (_T("GetTemplate() failed, Template not found"));
return NULL;
}
return pTemplate;
} There may be bits I am missing, but this should get you started.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks for the help.
When implementing this code, my application runs, but upon startup, it pops-up an MFC dialog titled "New" which contains my two views and expects me to pick either one. If I hit cancel, no document is loaded; else, the app behaves correctly. How do I default a view (instead of asking the user to choose), and how do I show both views simultaneously?
thanks!
JennyP
|
|
|
|
|
In your app's InitInstance function, there is a call to ProcessShellCommand. Remove that line. You then have to process the command line yourself. Look up CommandLineInfo in MSDN for all the possible options.
For example, if your user opens your app by double clicking on one of your associated files in explorer
if (cmdInfo.m_nShellCommand == CommandLineInfo::FileOpen)
{
CDocTemplate *pTemplate = GetTemplate(_T("TypeOne"));
if (pTemplate)
pTemplate->OpenDocumentFile(cmdInfo.m_strFileName);
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hello,
Thanks for the help. Just to make sure your solution matches my needs: I would like to have several views operate/interact with the same open document data set simultaneously. Is this the case here? I'm a little suspicious because perhaps MFC is asking about which document (data set) to open upon startup?
Also, is there an easier way to simply display the same document data in separate child windows rather than creating templates? I'm not complaining about the implementation, but in the back of my head, I'm thinking that manually starting and maintaining a child view would be pretty straight-forward. I would just have the added task of manually messaging this new window to update itself at the right times.
thanks,
JennyP
|
|
|
|
|
bitpusher wrote:
I would like to have several views operate/interact with the same open document data set simultaneously. Is this the case here?
Yes.
bitpusher wrote:
I'm a little suspicious because perhaps MFC is asking about which document (data set) to open upon startup?
No, MFC is asking which view to use to display the data. If you had multiple CDocument classes then the question would be which document, but AFAIK you have only one CDocument class.
bitpusher wrote:
is there an easier way to simply display the same document data in separate child windows rather than creating templates?
No, the templates are the core of the MFC Doc/View model
bitpusher wrote:
I would just have the added task of manually messaging this new window to update itself at the right times.
It's not all that difficult. As long as you remember that the document is the central part of your app. All your views do is display your data and pass any user input onto your document. Do not do any actual data manipulation in your CView classes, do it all in your CDocument classes. Whenever you do data manipulation, simply call UpdateAllViews and the MFC framework will update all the active views that are displaying data from the current document.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
bitpusher wrote:
my application runs, but upon startup, it pops-up an MFC dialog titled "New" which contains my two views and expects me to pick either one.
This will happen if you have more than one document template defined when the commandline parameters are processed. You can either: Define all the templates except one after the parameters are processed, or modify the parameter processing to prevent this behaviour. The defailt parameter processing calls OnFileNew() which shows the New dialog box if there are multiple document templates.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
I have included an MSFlexgrid control into my MFC application and I don't know if it is necessary to add the ocx file, as well as another files into the project to distribute the program (and what files?). And is it needed to make a registering routine for this Activex control in Windows register?
Thanks
|
|
|
|
|
I have visual c++ .net 2003 and am trying to add an MSchart to a form. I've selected it from the coms list and added it to the tool box. I then go to ad it to the form and get an AxImp.exe error message telling me it can't find AxInterop.OWC10.dll even though it's in the debug directory of the project. I have the same problem if I try using any other AxtiveX component, just a different dll in the error message.
|
|
|
|
|
Hi,
I'd like to know if there is a sort of sdk to develop an application that uses MP3, I'd like to access the MP3 Tags for example.
Thanks
|
|
|
|
|
|
|
Hi,
I have a dialog based project in vc++ 6.0, I need to add Menu bar to the dialog box. So I have inserted a Menu(IDR_MENU1) and created it the way I want.But I do not know how to add it to the dialog box. Please do help me.
Thanks
|
|
|
|
|
CDialog::SetMenu() should do the trick.
Nick
|
|
|
|
|
I am using Microsoft Visual C++ 6.0. I ahve tried #include <stdlib> and #include <stdlib.h> and both are not accepted. Is their a header file associated with this function?
int pos = input.find(',');
while (pos != -1)
{
input.replace(pos, 1, "");
pos = input.find(',');
}
number = atoi(input.c_str());
cout << number << endl;
Thank You
|
|
|
|
|
Try using #include<algorithm>
|
|
|
|
|
I have used #include <stdlib.h and="" #include="" <stdlib=""> and it does not work with the following function.
int pos = input.find(',');
while (pos != -1)
{
input.replace(pos, 1, "");
pos = input.find(',');
}
number = atoi(input.c_str());
cout << number << endl;
Thanks
|
|
|
|
|
#include <string>
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi!
In my app I've declared 2 dialogs via 2 classes. In dialog 1 I use a variable, that works well (of course..). Now I have to use the same var in dialog 2 (class 2) -> that won't work:
error C2597: illegal reference to data member
'CPIADlg::m_workdays' in a static member function
Has anybody the solution? Thanks, Thomas
PS: declaring as static ->
PIADlg.obj : error LNK2001: unresolved external symbol "public: static int CPIADlg::m_workdays" (?m_workdays@CPIADlg@@2HA)
Settings.obj : error LNK2001: unresolved external symbol "public: static int CPIADlg::m_workdays" (?m_workdays@CPIADlg@@2HA)
hmmm???
|
|
|
|
|
Hi everybody.
I need to open some files from my app. So I used do parse the register in order to obtain the default program and run it. For example, to open a pdf file I parsed the HKEY_CLASSES_ROOT for the ".pdf" key and got AcroExch.Document as value. Then I parsed again HKEY_CLASSES_ROOT for the "AcroExch.Document\shell\comman\open\" key and got the whole path of Acrobat Reader. Finally I opened the file using spawnl command.
With Acrobat it's almost all OK, but I neede to open html files too. And Internet Explorer doesn't work as Acrobat does, besides I got the right value of Ecplorer's path.
Any suggestion?
Is there any other way to open a file using its default program?
Thanks,
|
|
|
|
|
Use ShellExecute() or ShellExecuteEx().
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hey can anyone help me out with video compression? i have tried to look into virtual dub's code but i didnt get anything.
Saba
|
|
|
|
|
Hi ....
In my application I build functions that convert Arabic text to UCS2 coding this function will take it parameter from DB nvarchar field as follow:
*****************************************
CString CTryNewDlg::ToUCS2(CString txt)
{
USES_CONVERSION;
int xlen = txt.GetLength();
wchar_t *wsz = T2W(txt);
CString c,cc,x;
cc="";
int j=0,i=0;
for (i=j; i
|
|
|
|
|
Hi again ....
i found VB function to do what i want as follow:
************************************************
Public Function UCS2Str(strtext As String) As String
Dim s As String, h As String, i As Integer
i = 1
s = ""
While i < Len(strtext)
h = Mid(strtext, i, 4)
i = i + 4
h = CLng("&H" & h)
h = ChrW(h)
s = s & h
Wend
Hex2Str = s
End Function
************************************************
for CLng i used atol
but for CHrW i do not know what i should use i tried different convertion but i am only gettin strang char
(ex 0634 i should get ش )
plz any hint ...
|
|
|
|
|
Maybe someone can help me on this: I'm creating a MFC custom control which is a combination of a CEdit and a CSpinButtonCtrl . The control is created solely by code, i.e. no resource editor.
The problem is that the edit control paints itself incorrectly. Let me explain:
1.) Directly after showing the dialog with the custom controls it looks this way (the control in question is the control labeled "Breite der Bilder"):
<a href="http://www.magerquark.de/data/misc/mfc-cedit-01.png">Screenshot 1</a> [<a target=_blank title='New Window' href="http://www.magerquark.de/data/misc/mfc-cedit-01.png">^</a>] As you can see, the border around the CEdit is missing and the text ("640") is hanging on the upper left border.
2.) If I move the mouse over the control it looks this way:
<a href="http://www.magerquark.de/data/misc/mfc-cedit-02.png">Screenshot 2</a> [<a href="http://www.magerquark.de/data/misc/mfc-cedit-02.png" target="_blank" title="New Window">^</a>] I.e. now it paints the border but the text is still in the upper left corner, now partially hidden by the border.
3.) The control resizes when the user sizes the dialog. Now when the size was change, suddenly it looks correct, as in this screenshot:
<a href="http://www.magerquark.de/data/misc/mfc-cedit-03.png">Screenshot 3</a> [<a href="http://www.magerquark.de/data/misc/mfc-cedit-03.png" target="_blank" title="New Window">^</a>] As you can see, now the "640" has 'snapped down' to the correct position (in contrast to the control labeled "Breite der Vorschaubilder", which doesn't scale). Also, the CEdit border now is always visible.
So something must happen upon scaling. I already examined the styles of the CEdit before and after scaling with Spy++ and also compared with CEdit controls created with the resource editor. The styles are always the same, so these are not the cause of the display-error.
Question: Can someone enlighten me about why this display-error occures an how I can get rid of it?
Thank you
Uwe
--
Affordable Windows-based CMS: www.zeta-producer.com
|
|
|
|
|
I do not know why the error occurs, but I have seen some controls appear one way and then readjust as if they have received a second invalidate rectangle command (or a resize command).
It occurs to me that when Chris Maunder designed the MFC grid control 2.25, he may have ran into that problem. So it might be worth looking at.
Good Luck!
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|