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

+ Recent posts