|
The summary of my problem is this: two different views in a splitter window, one doc (SDI). I want to access the document's members from both views.
I've created an application with a CSplitterWnd in my MainFrame. I've created the two views using m_wndSplitter.CreateView(....);
That displays fine. Wonderful. I've got a variable in my doc class, int lookie. It's public. My class names are as follows:
CThingApp -> the app class
CThingDoc -> the doc class
CThingControlView -> the form view containing the controls
CThingDisplayView -> the graphical view displaying the data
CMainFrame -> frame class
CThingControlView was created with the whole project. I added CThingDisplayView.
So I changed the code in CThingApp:InitInstance() to look like this:
////////////////////////////
CSingleDocTemplate* pDocControlTemplate;
pDocControlTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CThingDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CThingControlView));
AddDocTemplate(pDocControlTemplate);
////////////////////////////
This seems to work.
Here's where my confusion sets in. I *thought* I now need to add the following code immediately beneath the above code:
////////////////////////////
CSingleDocTemplate* pDocDisplayTemplate;
pDocDisplayTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CThingDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CThingDisplayView));
AddDocTemplate(pDocDisplayTemplate);
////////////////////////////
I now believe that to be a false assumption because, upon building, the application displays a funny little window with the title new and what appears to be a list of options. There are two options with exactly the same text (which appears to be shortenings of my project name). If I select either one the application then starts.
Because this was incorrect behavior, I commented out the second document template code and tried several different ways of just *accessing* the data in CThingDoc from CThingDisplayView. Nothing's working.
I'm sure there is a simple solution to this. Something that my examples neglect to tell me or that I'm just not noticing.
|
|
|
|
|
|
Stop fiddling around with the DocumentTemplate!
You'll eventually destroy your application and need to start over!
Create the splitter with its views a s described in the other post.
Then, to access the document, you need to use
CThingDoc* pDoc = dynamic_cast<CThingDoc*>(GetDocument());
if()
{
} in your CThingDisplayView and CThingControlView.
Failure is not an option - it's built right in.{
|
|
|
|
|
For splitter windows, you only need one CSingleDocTemplate object that is created like:
CSingleDocTemplate* pDocControlTemplate;
pDocControlTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CThingDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(NULL));
AddDocTemplate(pDocControlTemplate);
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi list,
I want to ask whether is it possible to have a pointer whose type can change according to the input. I want to make it clear waht I need by a little code below which is not possible to compile. I think there must be a very well known trick for this. Thanks in advance for your help.
switch( datatype )
{
case DT_INT8: char *myPntr = (char *)dataPntr
case DT_UINT8: unsigned char *myPntr = (unsigned char*)dataPntr;
case DT_INT16: short *myPntr = (short *)dataPntr;
}
dataPntr is a (void *).
how can I create such myPntr?
xonobo
|
|
|
|
|
you just write: void * myPntr;
|
|
|
|
|
just read the reply of jhwurmbach below. That's my problem. void * do not help in that. but thanks...
|
|
|
|
|
xonobo wrote: want to ask whether is it possible to have a pointer whose type can change according to the input.
A void* can point to anything, but in turn it looses the information to what it is pointing.
You need to bundle this information with it.
In VB this is done using the VARIANT struct. That is a struct holding a type marker and a piece of memory.
Via a union, all datatypes are 'layered" above each other, using the same memory.
Failure is not an option - it's built right in.
|
|
|
|
|
Thanks a lot for your reply and ask: anyone knows a solution for C/C++?
|
|
|
|
|
You don't tell enough to get a solution to your problem.
What are you trying to accomplish and why can't this be solved in another way?
Does the (Microsoft specific) _variant_t help you?
Failure is not an option - it's built right in.
|
|
|
|
|
Thamks for your help. I thought VARIANT is only available in VB that's why I asked more. Now I will check _variant_t. Thanks again.
|
|
|
|
|
xonobo wrote: I thought VARIANT is only available in VB...
It's definitely not limited to VB.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi,
I have a MFC application and wish to change the way the application behaves when a user maximises the main window frame. I understand that I need to add a virtual function to the document class that inherits from the CDocument class. However, I am not sure what the name of the function is that is used when maximising the window. If you can tell me, that would be great.
Thanks !
|
|
|
|
|
the OnSize function takes UINT which identifies the minimise or maximise request.
that how ever is in MainFrm and View not Doc
example of an action based on minimised action.
void CMainFrame::OnSize(UINT nType, int cx, int cy)<br />
{<br />
if(nType == SIZE_MINIMIZED)<br />
{<br />
ShowWindow(SW_HIDE);<br />
}<br />
else<br />
{<br />
CFrameWnd::OnSize(nType, cx, cy);<br />
}<br />
}
hope that helps.
if im wrong about the document OnSize let me know please
|
|
|
|
|
Hi ya,
Thanks for your post. I actually found this
<br />
<br />
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) <br />
{<br />
static const CPoint point0 = CPoint(0, 0);<br />
if(m_PageSize != point0)<br />
{<br />
const long my = lpMMI -> ptMaxSize.y;<br />
const long ty = lpMMI -> ptMaxTrackSize.y;<br />
lpMMI -> ptMaxSize = m_PageSize; <br />
lpMMI -> ptMaxTrackSize = m_PageSize;<br />
lpMMI -> ptMaxSize.y = my;<br />
lpMMI -> ptMaxTrackSize.y = ty;<br />
}<br />
<br />
CFrameWnd::OnGetMinMaxInfo(lpMMI);<br />
}<br />
<br />
in my code and put a break point on it when I clicked the maximise button. The code then stopped at the break point proving that this function is invoked when using max / min. I guess the structure should contain info whether the user is doing a max / min ?
Thanks
|
|
|
|
|
minkowski wrote: ...proving that this function is invoked when using max / min.
True, but that does not mean it is the only function involved in such a request. The WM_GETMINMAXINFO message is sent to a window when the size or position of the window is about to change. You can handle this message to override the window's default maximized size and position, or its default minimum or maximum tracking size.
The WM_SIZE message is sent to a window after its size has changed. Given your request of, "...change the way the application behaves when a user maximises the main window frame.", I'd opt for handling this message.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I NEVER TRIED, but you can test to handle the WM_ONSIZE Message
There you get the UINT nType, which you can test on if(nType == SIZE_MEXIMIZED)
I hope it's true what i say
Good luck
|
|
|
|
|
Hi
Yes, I am sure what you suggested will work (am implementing it now) as I found this example
<br />
<br />
void CMainFrame::OnSize(UINT nType, int cx, int cy)<br />
{<br />
CFrameWnd::OnSize(nType, cx, cy);<br />
CMenu* pmenu = GetMenu();<br />
<br />
if (nType == SIZE_MAXIMIZED)<br />
pmenu->EnableMenuItem(ID_FREEZE, MF_DISABLED|MF_GRAYED);<br />
else<br />
pmenu->EnableMenuItem(ID_FREEZE, MF_ENABLED);<br />
<br />
Draw<br />
}<br />
<br />
Thanks for your suggestion.
|
|
|
|
|
Is anybody know any free unicode xml lib/classes I can use?
|
|
|
|
|
What about using MSXML?
Steve
|
|
|
|
|
|
|
hi i m using inp32 and out32 function with inpout32 dll, when i read data status and control register of parallel port inp32 function return a value that i stored in a variable all the pin of parallel port have 5V current,now i am connect all the pins one by one to ground i find change in the value of status register but not in the control register,how can i get this.my computer is celeron,but when i did this on p4 i find the change, how can i do this on celeron ,i also enable ECP mode of parallel port but could not get requored result
hi
|
|
|
|
|
hi i think you should get you the documentation of the celeron chip to find which control registers should be set and what are the other requirements for them to be set to 0V when you shortcut them (maybe you need 2 lines somewhere) the fact that it worked on the p4 proves it is only a problem either of hardware or of how the functions are interacting with it and if you have a bit of time remaining learn punctuation.
|
|
|
|