336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

How to prevent MFC dialog closing on Enter and Escape keys?


There is an alternative to the previous answer, which is useful if you wish to still have an OK / Close button. If you override the PreTranslateMessage function, you can catch the use of VK_ESCAPE / VK_RETURN like so:



BOOL CMainDialog::PreTranslateMessage(MSG* pMsg)

{


if (pMsg->message == WM_KEYDOWN)

{

if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)

{

return TRUE;                // Do not process further

}

}


return CDialogEx::PreTranslateMessage(pMsg);

}




이렇게 수정하여야 한다.




PreTranslateMessage 함수를 생성하는 방법은


1. Enter, ESC 키를 차단할 DialogClass 를 우클릭


2. [클래스 마법사] 를 켠다.


3. [가상 함수]


4. 가상 함수 탭에서 PreTranslateMessage 를 선택


5. [함수 추가]


6. 추가된 함수에


if (pMsg->message == WM_KEYDOWN)

{

if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)

{

return TRUE;                // Do not process further

}

}


추가 작성




336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

ATL 프로젝트로 만든 DLL 을 MFC 프로젝트에서 사용하기



ATL 프로젝트로 만든 DLL 이름을 ComServer.DLL 이라고 가정하겠습니다.


ComServer 대신에 자신이 만든 DLL 을 쓰면 됩니다.



사용하고자하는 ComServer.dll 파일을 프로젝트 디렉토리에 복사한다.


stdafx.h 파일에 


#import "ComServer.dll" no_namespace named_guids


넣고


빌드를 하게 되면


빌드 폴더에 ComServer.tlh , ComServer.tli 가 생성된것을 확인 할 수 있습니다.



ComServer.tlh 파일을 열어 둡니다.




그다음 Dlg 의 OnInitDialog() 같은 곳에 아래의 코드를 삽입한다.


ComTest 는 객체 이름입니다.


try{


UpdateData();


HRESULT rc;


IComTestPtr pComTest; //IComTest *pComTest 도 가능 !!! (IComTest 의 스마트포인터)


rc = CoCreateInstance(CLSID_ComTest, NULL, CLSCTX_INPROC_SERVER, DIID_IComTest, (void**)&pComTest);


if (FAILED(rc)){


MessageBox("Failure in call to CoCreateInstance");


return;


}


pComTest->(사용하고 싶은 속성이나 메서드);


}


catch (_com_error &e){


CString strBuffer;


strBuffer.Format("Code = %08lXnCode meaning = %snSource = %snDescription = %sn",

e.Error(), e.ErrorMessage(), e.Source(), e.Description());

AfxMessageBox(strBuffer);

}






'Programming > COM,ATL' 카테고리의 다른 글

MFC 프로젝트에서 ATL 연동하기  (2) 2016.03.29
ATL/COM 강좌  (0) 2016.03.25
ATL 프로젝트에서 hWnd사용하기 #2  (0) 2016.03.25
ATL 프로젝트에서 hWnd사용하기  (0) 2016.03.25
ocx, dll 라이브러리 등록  (0) 2016.03.15