MFC
[MFC] IP Address Control
개발하는꼬물이
2019. 7. 11. 14:56
IP 주소를 입력하고, 받아올 수 있는 컨트롤인 IP Address Control 의 사용법에 대해 알아보겠당
1. 먼저 다이얼로그에 컨트롤을 생성하고, 컨트롤의 ID를 원하는 ID로 바꿔준다.
2. 컨트롤을 마우스 오른쪽 버튼으로 눌러 변수 추가 메뉴를 선택, CIPAddressCtrl 형 변수를 추가한다.
3. 코드
// Edit Control -> IP Address Control CString strInput; CString strIP1, strIP2, strIP3, strIP4; GetDlgItemText(IDC_INPUT_EDIT, strInput); // IP주소를 "." 을 기준으로 각각 나눠서 저장 AfxExtractSubString(strIP1, strInput, 0, '.'); AfxExtractSubString(strIP2, strInput, 1, '.'); AfxExtractSubString(strIP3, strInput, 2, '.'); AfxExtractSubString(strIP4, strInput, 3, '.'); // CString to int int nIp1 = _ttoi(strIP1); int nIp2 = _ttoi(strIP2); int nIp3 = _ttoi(strIP3); int nIp4 = _ttoi(strIP4); // IP Address Control에 값 Set m_IPControl.SetAddress(nIp1, nIp2, nIp3, nIp4);
// IP Address Contro -> Edit Control BYTE ipFirst, ipSecond, ipThird, ipForth; CString strIPAddr; // BYTE 변수에 IP Address Control 값 Save m_IPControl.GetAddress(ipFirst, ipSecond, ipThird, ipForth); strIPAddr.Format(_T("%d.%d.%d.%d"), ipFirst, ipSecond, ipThird, ipForth); SetDlgItemText(IDC_OUTPUT_EDIT, strIPAddr);
4. 참고프로젝트와 실행 화면