본문 바로가기

Windows/MFC

클래스간 참조 Tip

1. 우선은 원하는 클래스의 global한 pointer변수를 app란에 만든다.
2. 해당 pointer변수를 원하는 클래스의 Constructor에서 this를 넘긴다.
3. 아무대서나 쓴다 -_- Cool~~~~~~~~~~
ps. 단 글로벌이니 책임을 못진다 -_-ㅋ

Example

[code]
App.h

#include "CMyClass.h"
extern CMyClass* g_pMyClass;
[/code]

[code]
App.cpp

CMyClass* g_pMyClass;
[/code]

[code]
MyClass.cpp

void MyClass::MyClass(void)
{
    g_pMyClass = this;
}
[/code]

일반적인 녀석들..

상호참조라면....
이런건가요??
[code]
View 에서 Doc 주소 GetDocument();
View 에서 MainFrame 주소 AfxGetMainWnd();
MainFrame 에서 View 주소 SDI일때만 GetActiveView();
모든 클래스에서 App 주고 AfxGetApp()
[/code]

'Windows > MFC' 카테고리의 다른 글

CEdit에서 엔터(enter)치면 해당 Command 실행하기  (0) 2013.10.02
CComboBox GetLBText내용 가져오기  (0) 2013.10.02
AfxGetMainWnd GetActiveView  (0) 2013.10.02
AfxLoadString  (0) 2013.10.02
CEdit - LimitText() 글자수 제한하기  (0) 2013.10.02