|
My pointer to nothing doesn't work...
|
|
|
|
|
I tried what you suggested, but I get the error message that CWinSTMView::CWinSTMView() is inaccessible.
|
|
|
|
|
When do you get this error? Is the constructor of this view public?
|
|
|
|
|
No, the constructor is not public. It is protected and I was unsure if just changing it to public was the best way to solve the problem. So, I thought I would ask if it was good programming practice in my efforts to understand MFC programming.
|
|
|
|
|
If it's protected, it's probably not meant to be accessed that way... see my other post. Usually multi-view documents in MFC have to be initialized through MFC methods/macros.
|
|
|
|
|
By the way, if the view already exists, trying to do what Jonathan suggests isn't the proper thing to do... if it exists, then you need to either use the framework to pass the message to the view or get a hold of the pointer to the view itself and do a SendMessage() to it.
|
|
|
|
|
AndrewG1231 wrote:
What does that mean? We cannot see your PC screen so have no idea i) what is supposed to happen, or ii) what actually happens.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I'm sorry about being vague...I am really trying my best with all my posts to be as descriptive as possible, but based on the responses I must continue to improve in this aspect. The comment was meant to direct the attention away from the first call to OnPlaceData() to the lines of code that was causing problems. All I wanted to happen is for the Autoplane() member that is defined in the view part of the MDI (I think there are three parts in MDI, the view, the doc, and the app) to be successfully called from a button I placed on a different dialog box. To do this I tried to create an pointer of the view class type and call the member. It compiles fine, but in runtime the program crashes.
|
|
|
|
|
AndrewG1231 wrote: It compiles fine, but in runtime the program crashes.
Because you create the variable but never initialise it:
CWinSTMView *pView; pView->OnImageAutoPlane();
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
These two statements don't do what you expect
CWinSTMView *pView;
pView->OnImageAutoPlane();
All it does is declare that pView is a pointer to "something" but you don't actually initialize it to point to anything. Then you try to use it.
I assume that the CWinSTMView object was instantiated somewhere else and you are trying to access it. You need to find that object and initialize pView to point to it. How you find that object is your problem as the amount of code posted is not enough for me to guess at it.
|
|
|
|
|
Thanks, I will look for where it is instantiated
|
|
|
|
|
Have you tried something like:
AfxGetApp()->GetMainWnd()->GetActiveView()->OnImageAutoPlane();
AfxGetMainWnd()->GetActiveView()->OnImageAutoPlane();
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I have not, but when I use your suggestion:
class "Cwnd" has no member "GetActiveView"
|
|
|
|
|
Which is why I added the "casting not provided" comment. As I don't know the name of your frame/doc/view classes, you'll need to cast some of those function calls to your specific situation.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I was able to solve the problem after I did some research on the MSDN site about the suggestions of sending messages and GetActiveView(). :
OnPlaceData();
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
CWinSTMView *pView = (CWinSTMView *) pChild->GetActiveView();
pView->OnImageAutoPlane(); Now my pointer points to something and I was able to access that member (and others that I wanted to use as well). Thanks for the help!
|
|
|
|
|
Before you get too far into finding view pointers and accessing them directly....
This is not a good practice in MDI Programming. The framework supports multiple view types for every document. So the Active View, in theory could return a different class type than you expect. Obviously if you don't have other view types explicitly written then this won't happen... There are also cases where you'll see no Active View, even though from the user's perspective it looks like there is one.
The better solution is to get a pointer to your CDocument instantiation and call a notification method there, instead of your view. I good way to do this is to pass the doc pointer to the dialog when you create the dialog. I like to pass the doc * in the constructor.
Then in the doc, have the notification method, call UpdateAllViews() with a hint as to what data has been changed, and let the view respond to this message.
|
|
|
|
|
Thanks, the code works to modify data in the same window when I have only one active child window...but I have been running into problem when the data is saved to a new document and displayed in a second child window. I was working with the view pointers to try and cycle through child windows, but your method seems interesting. The member I am calling, Autoplane(), creates another document already as shown here:
void CWinSTMView::OnImageAutoPlane()
{
CWinSTMDoc *pDoc = CreateNewDoc(GetDocument()); Can I use this doc pointer as you described?
|
|
|
|
|
Is it your goal to have two view windows?
The MDI Framework doesn't lend itself well, to creating new documents from user code.
It's easier to add and create additional views.
The way the framework is intended to be used:
1. The document holds your data and resources.
2. The views are intended to be presentation classes that provide a view of the data to the users.
This is why we have a one to many relationship between documents and views.
|
|
|
|
|
|
how to use system API for given time
some times a when i call system api, my computer hangs and i need to reboot
can i use for given time
|
|
|
|
|
The API function [SetTimer ] executes a function every x milliseconds or any given time.
MFC version [here].
Console example:
The following console program works like this: It sets a timer using SetTimer
then loops in a message loop. The message loop receives and processes WM_TIMER messages
and the timer callback also is called for each time interval.
Simply put the stuff you want done in the TimerProc() function.
#define STRICT 1
#include <windows.h>
#include <iostream.h>
VOID CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
{
cout << "Doing stuff Time: " << dwTime << '\n';
cout << "--------------------------------------------------\n" ;
cout.flush();
}
int main(int argc, char *argv[], char *envp[])
{
int Counter=0;
int usage_Time_millisec=500;
MSG Msg;
UINT TimerId = SetTimer(NULL, 0, usage_Time_millisec, &TimerProc);
cout << "TimerId: " << TimerId << '\n';
if (!TimerId) return 16;
while (GetMessage(&Msg, NULL, 0, 0))
{
++Counter;
if (Msg.message == WM_TIMER)
cout << "Doing stuff Counter: " << Counter << "; timer message\n";
else
cout << "Doing stuff Counter: " << Counter << "; message: " << Msg.message << '\n';
DispatchMessage(&Msg);
}
KillTimer(NULL, TimerId);
return 0;
}
|
|
|
|
|
MKC002 wrote: how to use system API for given time
What exactly do you mean by this; which API and what time?
MKC002 wrote: some times a when i call system api, my computer hangs and i need to reboot
Perhaps if you show an extract of the code that does this we may be able to help.
MKC002 wrote: can i use for given time
Use what and for what time - time of day, time interval, ...?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
our server maintains large amount of data. Everyday new files/folders created on it. A serevice set some special properties for files/folders. One service checkes if some property does not exist in file/folder then move the file to another location for further processing.
Here one service call GetFileAttributes and GetVolumeInformation for disk where file will be move. From this function we get volume label and other information to store in database. Sometimes system hangs and i need to reboot. I noticed system hangs due to GetVolumeInformation.
So, can i set time limit for this function. If after given time i dont get volume label then move the file to another disk.
|
|
|
|
|
It's more important to discover why the system hangs on this function; perhaps it is trying to access a network disk and you are having network problems, or the drive is failing. You could also move this code into a background thread and then kill it after a fixed time interval from your main thread.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for your reply. To play with thread is little difficult.
Please give any link to kill thread which is safe and does not result in any type of crash.
|
|
|
|