[MFC] Printer DC 에는 DrawIconEx API 가 먹지 않는다.

2008. 5. 2. 17:53Coders

간결한 프로그램을 만드는데, OnDraw 에서 이것저것 다 그려 넣는 코딩을 하고 있었다.
그냥 컨트롤을 올려 놓으면 간단한 일이지만, 계획이 프린터 출력까지 하려고 하다 보니, View 의 OnPrint 에서는 OnDraw 가 호출된다는 점에 착안하여, 간단하게 사이즈만 조정하면 인쇄까지 한 코딩으로 끝나겠다 싶은 생각에 OnDraw 에 그린 것이다.
워낙 자잘한 거 하는 건 왠지 산수 계산하는 것 같아 좀 재미를 들였기 때문에,
Draw3DRect, FillSolidRect, DrawText 등의 CDC 의 함수들을 사용해 잘 그리고 잘 쓰고 있었는데,
자 종이가 아까워 인쇄 미리보기만 보다가,
실제 출력을 하니, 이 뭥미... 아이콘이 인쇄되지 않는 현상을 발견한 것이다.
여기저기 알아 보아도 한글 사이트에서는 동문서답이나 하고 있어서,
찾다찾다 보니 이런 게 있었다.

http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=1319526
주욱- 내려가 보면 이런 질문글이 있다.
The icon in the view can't be printed in SDI,the text is able to print ?how can I do?
I draw some icons into view ,the icon is from a file.I also draw some text in the view . the view inherit from CSrollView.
but the icon can't be output at the end.
thank you .
댓글1
Is it a displaying problem or printing problem? I don't know the solution if it is a printing problem.
void OnDraw(CDC* pDC)
{
    HICON hi;
    hi = (HICON)LoadImage(NULL,"d:\\asd.ico",IMAGE_ICON,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE);
    pDC->DrawIcon(10,10,hi);
}


this is this.
질문자 재질문
I tried,your solution is not able to resolve my question.
this is my code:
.....
hIcon=(HICON)LoadImage (NULL,iconPath,IMAGE_ICON,48,48,LR_LOADFROMFILE|LR_DEFAULTSIZE);

DrawIconEx(pDC->GetSafeHdc(), x-24, y+50, hIcon, 48, 48, 0, NULL, DI_NORMAL);
how should I do ?
could you help me
아까 그 놈 다시 댓글
Your code works just fine. Just make sure that x-24, and y+50 will be inside the client area.
Also make sure that LoadImage(...) does not return NULL.


this is this.
재질문
The x-24 and y+50 is in inside the client area.
The loadImage(...) returns a hIcon,I use this hIocn draw icon on the view ,and the icon can display while printing preview,but the icon is not able to print ,why? how can resolve this question?
I also draw text,but the text could be print
아까 그놈이라고 쓴 건, 댓글 단 친구가 참 태도가 불량해서이다.
질문자는 해결 방안을 애타게 찾고 있는데, 그리고 프린터로 출력이 안된다고 했음에도 불구하고 계속 "this is this" 하고 약간 깐죽거리는 듯한 댓글을 단다. 난 되는데 넌 왜 계속 안 된다고 하냐? 하는 식이지.
이런 녀석들은 개발자 커뮤니티에서 퇴출시켜야 한다.
(결국엔 다시 댓글 달기를 하지 않았다.)
데브피아에도 그런 질문이 올라와 있는데, 거긴 댓글 단 분이 없더라.

아무튼, 영문 사이트는 좀 거시기 해서 한글 사이트 위주로 찾아보는데,
어디에서도 속 시원히 알려주는 곳이 없었다.
핵심은,
화면에서도, 인쇄 미리보기(Print Preview)에서도 보이는 아이콘이 실제 출력할 때에만 나오지 않는다!!! 라는 것이다.

뭔가 코딩이 잘못되었다는 생각을 하다가 한번만 더 찾아보자 해서 찾아보니,
구글 뉴스그룹에 그냥 나온다.
http://groups.google.co.kr/group/microsoft.public.dotnet.general/browse_thread/thread/a1906a8c177ea7a5
어허허 이럴 수가...

M$의 답변이다.
Hello,

Internally, DrawIcon() calls the DrawIconEx() API. This API is not designed
to work on printer DCs.

This is by design, so please convert the icon to image first, and then
output the image to the printer.

Your solution is great :)

--
Parker Zhang
Microsoft Developer Support

즉, Printer 의 DC는 DrawIconEx() API 가 작동하도록 설계되지 않았다는 말.
뭐 어찌어찌 죄송합니다. 수정하도록 하죠! 하는 게 아니라,
그냥 그림으로 바꿔 출력하세요. 라네...

미친 M$...
우리나라 업체였으면, 죄송죄송죄송... 할 것이고,
사용자는 "아이씨 이뭐병~" 했을 텐데, 이상하게 갑을이 바뀐 것 같다.

결론 : icon 을 그냥 bmp 로 출력했다. 씨파...