AfxGetMainWnd()->SetWindowText( "HELLO" );

//원래 등록되어 있던 뷰에서 복사해서 붙여넣기 하면 되고, 위치를 꼭 같은 위치에 붙여넣도록 주의.

 

/******************************************************************************************/

//1. 해더파일에서

///////////////////////////////

//추가

#include "TestDoc.h"

///////////////////////////////

 

class CNewView : public CView
{
 // Attributes
 public:

//////////////////////////////////

//추가
  CTestDoc* GetDocument();

/////////////////////////////////

 

.....

 

protected:
 //{{AFX_MSG(CNewView)
 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

 

/////////////////////////////////////

//추가

#ifndef _DEBUG 

inline CTestDoc* CNewView::GetDocument()  //클래스명 주의
   { return (CTestDoc*)m_pDocument; }
#endif

/////////////////////////////////////

/******************************************************************************************/

 

 

/******************************************************************************************/

//2. 소스파일에서

void CNewView::Dump(CDumpContext& dc) const
{
 CView::Dump(dc);
}

 

//////////////////////////////////////////

//추가

CTestDoc* CNewView::GetDocument() //클래스명 주의
{
 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
 return (CTestDoc*)m_pDocument;
}

//////////////////////////////////////////


#endif //_DEBUG

/******************************************************************************************/

 

 

/******************************************************************************************/

//3. OnDraw에서

void CNewView::OnDraw(CDC* pDC)
{

////////////////////////////////////////

//수정
 CTestDoc* pDoc = GetDocument();

////////////////////////////////////////


 // TODO: add draw code here

}

/******************************************************************************************/


/******************************************************************/

/* Regular DLL using shared MFC DLL 첫번째 방법

/******************************************************************/

1. 프로젝트를 생성한다.

[MFC AppWizard(dll)] -> [Regular DLL using shared MFC DLL] -> [Finish]

 

2. 새로 생성된 프로젝트의 소스에서 맨 밑에 추가

.....

 

CMFC0808App::CMFC0808App()
{
 // TODO: add construction code here,
 // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMFC0808App object

 

//추가

extern "C" __declspec(dllexport)
 double Square( double d)
 {
     return d * d;
 }

 

3. 컴파일 하면 dll파일 생성된다.

 

4. 다이얼로그 베이스의 새로운 프로젝트를 생성.

dll파일을 새로 만들 프로젝트에 복사해서 붙여 넣는다.

 

5. 에디트 박스 두개와 버튼을 만든다.

 - IDC_EDIT1 : 입력 받는 에디트 박스( 컨트롤 변수 생성 : m_dInput, double형 )

 - IDC_EDIT2 : 결과 출력할 에디트 박스( 컨트롤 변수 생성 : m_dOutput, double형 )

 - IDC_BUTTON1 : 버트 눌렀을때 Square함수 호출

 

6. OnInitDialog에서

if( (m_hDll = LoadLibrary("MFC0808.dll")) == NULL )
{
    AfxMessageBox( "dll파일이 존재하지 않습니다. " );
}

 

7. OnDestroy에서

FreeLibrary( m_hDll ); 

 

8. 해더 파일에서

HINSTANCE m_hDll; //추가

 

9. OnButton1에서 (IDC_BUTTON1)

double (*pSquare)(double);

 

if( !(pSquare = (double(*)(double))GetProcAddress(m_hDll, "Square")) )
{
    AfxMessageBox( "Square함수가 존재하지 않습니다." );
}

 

UpdateData( TRUE );

 

m_dOutput = (*pSquare)(m_dInput);

 

UpdateData(FALSE);

 

 

 

/******************************************************************/

/* Regular DLL using shared MFC DLL 두번째 방법

/******************************************************************/

1. 새로운 프로젝트를 생성한다.

[MFC AppWizard(dll)] -> [Regular DLL using shared MFC DLL] -> [Finish]

 

2. 새로 생성한 프로젝트에서 해더파일 추가

Square.h

 

3. Squart.h에서

#include <windows.h>

 

extern "C" __declspec(dllimport)
double Square( double d);

 

4. 소스에서

#include "Square.h"

 

.....

 

CMFC0808App::CMFC0808App()
{
 // TODO: add construction code here,
 // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMFC0808App object

CMFC0808App theApp;

 

//추가

extern "C" __declspec(dllexport)
double Square( double d)
{
    return d * d;
}

 

5. 컴파일 하면 dll파일과 lib파일 생성

 

6. 다이얼로그 베이스의 새로운 프로젝트를 생성.

dll파일, lib파일, Square.h파일을 복사해서 붙여 넣는다.

 

7. 에디트 박스 두개와 버튼을 만든다.

 - IDC_EDIT1 : 입력 받는 에디트 박스( 컨트롤 변수 생성 : m_dInput, double형 )

 - IDC_EDIT2 : 결과 출력할 에디트 박스( 컨트롤 변수 생성 : m_dOutput, double형 )

 - IDC_BUTTON1 : 버트 눌렀을때 Square함수 호출

 

8. 소스에 해더파일과 lib파일 링크 추가

#include "Square.h"

 

9. OnButton1에서 (IDC_BUTTON1)

UpdateData( TRUE );

 

m_dOutput = Square(m_dInput);

 

UpdateData(FALSE);


/******************************************************************/

/* MFC Extension DLL(using shard MFC DLL)

/******************************************************************/

1. 새로운 프로젝트를 생성한다.

[MFC AppWizard(dll)] -> [MFC Extension DLL(using shard MFC DLL)] -> [Finish]

 

2. 새로운 클래스를 추가한다.

Class Type : Generic Class

Class Name : CTest

 

3. CTest클래스의 해더에서

// Test.h: interface for the CTest class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TEST_H__84322227_2364_48FD_B142_DE36100C3F0C__INCLUDED_)
#define AFX_TEST_H__84322227_2364_48FD_B142_DE36100C3F0C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

 

class AFX_EXT_CLASS CTest   //AFX_EXT_CLASS 추가
{
    int num;

 

public:
    CTest();
    virtual ~CTest();

 

    void SetNum( int num );
    int GetNum() const;
    int Square( int num ); 
};

 

#endif // !defined(AFX_TEST_H__84322227_2364_48FD_B142_DE36100C3F0C__INCLUDED_)

 

4. CTest클래스의 소스에서

// Test.cpp: implementation of the CTest class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Test.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

 

CTest::CTest()
{
    num = 0;
}

 

CTest::~CTest()
{

}

 

void CTest::SetNum( int num )
{
    this->num = num;
}

 

int CTest::GetNum() const
{
    return num;
}

 

int CTest::Square( int num )
{
    return this->num * num;
}

 

5. 컴파일 하면 dll파일과 lib파일이 생성된다.

 

6. 콘솔 모드로 프로젝트를 새로 생성한다.

 

7. dll.파일과 lib파일 Test.h파일을 새로 만든 콘솔 프로젝트에 복사해서 붙여넣는다.

lib파일 링크 추가

 

8. 콘솔 모드 프로젝트에 Test.h파일 include

AFX_EXT_CLASS // <--이부분 삭제

 

9. 콘솔 모드 프로젝트에 cpp파일 추가

#include <iostream>
#include "Test.h"

 

using namespace std;

 

void main()
{
    CTest test;

    test.SetNum( 10 );

 

    cout << test.GetNum() << endl;

    cout << test.Square( 100 ) << endl;
}


 SCHOOL* GetValue()
 {
  //return값이 여러개 필요하므로 포인터로 넘긴다
  //포인터로 넘기는 방법
  return strSCHOOL;
 }

 ITEM* GetITEM()
 {
  return strITEM;
 }


import java.io.*;
import javax.media.jai.*;

public class converter
{
 public static void g2p(String filename)
    {
  try
        {
            //파일을 읽어온다..
            RenderedOp src = JAI.create("fileload", filename+".bmp");
            
            //변환될 파일을 저장할 스트림..
            FileOutputStream fos = new FileOutputStream(filename+".jpeg");
            
            //변환합니다. 다른형식으로 변환시 JPEG만 바꿔주시면 됩니다..
            JAI.create("encode", src, fos, "JPEG", null);
            fos.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }
 
    public static void main(String[] args) throws IOException
    {
     InputStreamReader isr = new InputStreamReader(System.in);
     BufferedReader in = new BufferedReader(isr);

     String input;
     System.out.print("Filename: ");
     input = in.readLine(); //키보드로부터 입력 받음
     System.out.println(input);

     g2p(input);
     System.out.println("Complete");
    }
}

1. 리스트컨트롤의 멤버변수 선언


OnInitDialog()에서 아래의 방식으로 리스트컨트롤의 컬럼을 초기화함

 // TODO: Add extra initialization here
 m_schoolList.InsertColumn(0, "No.", LVCFMT_CENTER, 40);
 m_schoolList.InsertColumn(1, "성별", LVCFMT_CENTER, 50);
 m_schoolList.InsertColumn(2, "구분", LVCFMT_CENTER, 50);
 m_schoolList.InsertColumn(3, "학교이름", LVCFMT_CENTER, 200);
 
 m_schoolList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
 m_schoolList.ModifyStyle(LVS_TYPEMASK, LVS_REPORT); 

 CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd(); //AfxGetMainWnd() -> MainWnd의 주소값을 가져옴
 CIvyClubDoc *pDoc = (CIvyClubDoc *)pFrame->GetActiveDocument(); //GetActiveDocument() AfxGetMainWnd로 가져온 MainFrame에서 활성화된 Document의 주소를 가져오는 함수. 이 주소를 가져다가 pDoc에 넣어주면 결국 활성화된 Doc의 주소를 가져올 수 있고 이것을 이용하여 호출

 SCHOOL* pSchool = pDoc->GetValue(); //pDoc의 getvalue를 호출하면 SCHOOL 구조체의 포인터 주소를 넘겨준다

 int counter = pDoc->GetCounter();
 
 for(int i=0;i<counter;i++)
 {
  CString SEX, LEV, SN, NO;
  NO.Format("%d", i);
  SEX.Format("%d", pSchool[i].sex);
  LEV.Format("%d", pSchool[i].level);

  if(strcmp(SEX, "1")==0)
   SEX = "남";
  else if(strcmp(SEX, "2")==0)
   SEX = "여";
  if(strcmp(LEV, "1")==0)
   LEV = "쵸딩";
  else if(strcmp(LEV, "2")==0)
   LEV = "즁딩";
  else if(strcmp(LEV, "3")==0)
   LEV = "고삘";

  //각 컬럼에 ITEM삽입
  m_schoolList.InsertItem(i, "0", 0); //컬럼줄
  m_schoolList.SetItemText(i, 0, NO);
  m_schoolList.SetItemText(i, 1, SEX);
  m_schoolList.SetItemText(i, 2, LEV);
  m_schoolList.SetItemText(i, 3, pSchool[i].school_name);
  //InsertItem(row no, 문자열, 컬럼번호)
  //SetItemText(row no, 컬럼번호, 문자열)
 }
 return TRUE;  // return TRUE unless you set the focus to a control
               // EXCEPTION: OCX Property Pages should return FALSE

1. 리소스탭에서 다이얼로그 선택하고 Insert Dialog 선택
2. 다이얼로그 생성되면 ID 변경
3. 생성한 다이얼로그에 대한 클래스 생성 이때 맨 앞에 C를 붙여준다(자동으로 C는 제껴놓고 파일이름 생성된다)
이렇게 하면 cpp와 h파일이 생성된다
3. Menu에서 ID, 캡션 추가하여 메뉴생성
4. 생성된 메뉴에서 클래스마법사 실행하고 Object ID -> 생성한 다이얼로그 선택 -> Messages: COMMAND 선택 -> Add Function -> MainFrame.cpp에 On 펑션 생성됨 -> h파일 include -> 다이얼로그 띄우는 방법 참고


void CMainFrame::OnMenuSchoolAdd()
{
 // TODO: Add your command handler code here
 CSchoolAdd CSA;
 CSA.DoModal();
}

void CMainFrame::OnMenuSchoolList()
{
 // TODO: Add your command handler code here
 SchoolList SL;
 SL.DoModal();
}

void CMainFrame::OnTrash()
{
 // TODO: Add your command handler code here
 CTrash TR;
 TR.DoModal();
}

모달창 - Multi dialog 상태에서 현재 뜬 창을 제외하고 다른 창으로 이동이 불가능한것
모달리스창 - Multi dialog 상태에서 현재 뜬 창과 다른 창들을 번갈아 가며 사용할 수 있는것


common.h에 선언했던 내용

define과 enum도 그대로 복사했음

#ifndef _GLOBAL_DEFINE_
#define _GLOBAL_DEFINE_

#define SCHOOL_MAX_NUM 100
#define SCHOOL_NAME_LENGTH 10
#define A_KIND 4

enum {MAN = 0, WOMAN};
enum {ES = 0, MS, HS};
enum {_NONE = -1, _ERROR = 0, _SUCCESS};

typedef struct tagSchool
{
 int index;
 int sex;
 int level;
 CString school_name;
}SCHOOL;

typedef struct tagITEM
{
 int index;
 int s85[A_KIND];
 int s90[A_KIND];
 int s95[A_KIND];
 int s100[A_KIND];
}ITEM;

typedef struct tagHuman
{
 //int num;
 CString name;
 CString school_name;
 CString address;
 CString callme;
 int Js, Jn;
 int Vs, Vn;
 int Ss, Sn;
 int Bs, Bn;
}HUMAN;

#endif

+ Recent posts