Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Megaproblem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Megaproblem

 Post Reply Post Reply
Author
Message
Ky3bkuHa MaTb View Drop Down
Newbie
Newbie


Joined: 13 March 2006
Location: Russian Federation
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ky3bkuHa MaTb Quote  Post ReplyReply Direct Link To This Post Topic: Megaproblem
    Posted: 14 March 2006 at 12:08am
VC++ 6.0 SP 6

I create SDI app with your wizard and adding members to MainFrame class. When i getting this variables (public variable or get function) i always getting zero.

Example.
Add to MainFrame : public: int num;
In MainFrame constructor: num = 10;
In View class add function :
void CMyView::OnAnyMenuItem() {
     char buf[10];
     sprintf(buf, "%d", ((CMainFrame*)AfxGetApp())->num);
     AfxMessageBox(buf); // 0 , but must be 10
}

On my example its function menu Edit -> Test.

If create function in CMainFrame.
void CMainFrame::OnAnyMenuitem() {
     char buf[10];
     sprintf(buf, "%d", num);
     AfxMessageBox(buf); // 10 right
}

They works rigth. I nothing understand.

2006-03-13_235601_test23.rar


Back to Top
Sven View Drop Down
Senior Member
Senior Member


Joined: 21 August 2003
Location: Germany
Status: Offline
Points: 127
Post Options Post Options   Thanks (0) Thanks(0)   Quote Sven Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2006 at 7:02am
Quote sprintf(buf, "%d", ((CMainFrame*)AfxGetApp())->num);

AfxGetApp() returns a CWinApp object and not a CMainFrame.
Back to Top
Ky3bkuHa MaTb View Drop Down
Newbie
Newbie


Joined: 13 March 2006
Location: Russian Federation
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ky3bkuHa MaTb Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2006 at 12:39pm
I suspect.
But how call function from CMainFrame class? If  AfxGetApp() is not enable do this, what enable do this ?
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 14 March 2006 at 3:59pm
AfxGetMainWnd.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Red Devil View Drop Down
Newbie
Newbie


Joined: 15 March 2006
Location: Zimbabwe
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote Red Devil Quote  Post ReplyReply Direct Link To This Post Posted: 15 March 2006 at 12:04am
Yes, my problem is disappear, thank you very match. Really good support.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.313 seconds.