2016년 2월 14일 일요일

[C++]MFC, Release method including static library

When you release your project without static library, the released exe. file would not work on other PC. That is because libraries related to your project are not included in your released file. Here I will introduce the release method including static library to prevent the happening described above.

1) In your project properties, set configuration from debug to release.
2) Click the General tab of configuration properties, 
3) Change 'Use MFC in a shared DLL' to 'Use MFC in a static library'
4) Nextly, move the Code generation tab of C/C++
5) Change '/MD' to '/MT' in the runtime library.

details are shown in below figure.





2016년 2월 12일 금요일

[C++]MFC, obtain the pointer of MainFrame, Doc, View classes

MFC, obtain the pointer of MainFrame, Doc, View classes 


// Notice: Before doing below, you have to include the header of the pointer to be obtained.



※ CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();

1. MainFrame Pointer
CMainFrame *frame = (CMainFrame*)AfxGetMainWnd();

2. Doc class Pointer
CxxxDoc *pDoc = (CxxxDoc*)(frame->GetActivedocument());

3. View class Pointer
CxxxView* pView = (CxxxView*)((CMainFrame*)(AfxGetApp()->m_pMainWnd))->GetActiveView();

--------------------------------------------------------------------------
[SDI Type]

1. MainFrame pointer
- CMainFrame *pFrame = (CmainFrame *) AfxGetMainWnd();

2. App class pointer
- CTestApp *pApp = (CtestApp *) AfxGetApp();

3. Document class pointer
- CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
  CTestDoc *pDoc = (CTestDoc *)pFrame->GetActiveDocument();
- CTestDoc *pDoc = ((CMainFrame *)AfxGetMainWnd())->GetActiveDocument();

4. View class pointer
- CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
  CTestView *pView = (CTestView *)pFrame->GetActiveView();
- CTestView *pView = ((CMainFrame *)AfxGetMainWnd())->GetActiveView();
 --------------------------------------------------------------------------------
[MDI type]

1. ChildFrame pointer
- CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
  CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
- CChildFrame *pChild = ((CMainFrame *)AfxGetMainWnd())->GetActiveFrame();

2. Document pointer
- CMainFrame *pFrame = (CMainFrame)AfxGetMainWnd();
  CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
  CMdiTestDoc *pDoc = (CMdiTestDoc *)pChild->GetActiveDocument();
- CMdiTestDoc *pDoc = (((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveDocument();

3. View pointer

- CCainFrame *pFrame = (CMainFrame)AfxGetMainWnd();
  CChildFrame *pChild = (CChildFrame *)pFrame->GetActiveFrame();
  CMdiTestView *pView = (CMdiTestDoc *)pChild->GetActiveView();
- CMdiTestView *pView = (((CMainFrame *)AfxGetMainWnd())->GetActiveFrame())->GetActiveView();


** This post is written by courtesy of http://egloos.zum.com/printf/v/1940633

2016년 2월 1일 월요일

[C++] MFC, Add dialog to a SDI based project

Summary to add dialog (formview) to a project based on SDI.

1. Firstly, Create a new project which is based on SDI.

2. Add a new dialog to resource.

3. Add class to the added dialog (should be based on CDialog class) (ex. CMyDlg)

4. Add a member function "BOOL Create(Cwnd* pParentWnd); " in CMyDlg class.

5. type below codes for the member function in .cpp file of the above class,

BOOL CMyDlg::Create(CWnd* pParentWnd)
{
           return CDialog::Create(IDD, pParentWnd);
}

6. include "CMyDlg" in main frame class (Or View class)

7. declare the added class' instance (e.g., CMyDlg *dlg;)

8. Lastly, in .cpp file of Main frame class (or view class), type below codes in OnCreate (if there is no OnCreate, add message function) ,
     dlg = new CMyDlg;
       dlg->Create(this);
       dlg->ShowWindow(SW_SHOW);
       dlg->MoveWindow(0,0,1024,64); 



Additionally, if menu buttons (or event handler) are used for create the dialog, 
refer to below functions:

bool CMFC_TESTView::CreateChildDlg(void)
{
        if(dlg != NULL) return 0;
               dlg = new CMyDlg;
       
               if(dlg->GetSafeHwnd() ==0)
               {
                       if(!dlg->Create(this)) return 0;
                       else {dlg->ShowWindow(SW_SHOW);
        //dlg->MoveWindow(0,0,1024,64);
                              }
               }

  
        return TRUE;
}


bool CMFC_TESTView::DestroyChildDlg(void)
{
               if(dlg != NULL)
                       if(!dlg->DestroyWindow()) return FALSE;
       
        dlg =NULL;
        return TRUE;
}