성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
[정성태] "props[i].GetValue(props[i])" 코드에서 ...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Win32 API의 UnionRect를 닷넷 BCL의 Rectangle.Union으로 바꿀 때 주의 사항</h1> <p> Win32 API의 UnionRect와 닷넷 BCL의 Rectangle.Union은 같은 역할을 합니다. 그런데, 한가지 차이점이 있습니다. 결론부터 말하면 BCL의 Union은 대상이 되는 Rectangle의 Width, Height가 0이어도 좌표에 따른 Union을 해버리는 반면 Win32 API의 UnionRect는 무시해 버립니다.<br /> <br /> 코드로 말해 볼까요? ^^<br /> <br /> 닷넷의 경우, Width 또는 Height가 0이어도,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > { Rectangle rect1 = new Rectangle(0, 0, 0, 0); Rectangle rect2 = new Rectangle(1920, 0, 1920, 1080); Console.WriteLine(Rectangle.Union(rect1, rect2)); // 출력 결과: {<span style='color: blue; font-weight: bold'>X=0</span>,Y=0,Width=3840,Height=1080} } </pre> <br /> 위와 같이 rect1의 Width (또는 Height)가 0이지만 rect1의 Left 좌표를 받아들여 Union 시킨 결과에 반영합니다.<br /> <br /> 반면 Win32 API의 UnionRect는,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > { RECT rect1 = { 0, 0, 0, 0 }; RECT rect2 = { 1920, 0, 1920 * 2, 1080 }; UnionRect(&rect1, &rect1, &rect2); printf("X = %d, Y = %d, Width = %d, Height = %d\n", rect1.left, rect1.top, rect1.right - rect1.left, rect1.bottom - rect1.top); // 출력 결과: <span style='color: blue; font-weight: bold'>X = 1920</span>, Y = 0, Width = 1920, Height = 1080 } </pre> <br /> 위와 같이 Width = 0 (또는 Height = 0)인 rect1 사각형을 무시해 버립니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 따라서, C++로 만들어진 소스 코드를 C#으로 포팅할 때 UnionRect에 대해서는 다음과 같은 조치를 취해야 합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > public static Rectangle UnionRect(Rectangle rect1, Rectangle rect2) { if (rect1.Width == 0 || rect1.Height == 0) { if (rect2.Width == 0 || rect2.Height == 0) { return Rectangle.Empty; } return rect2; } if (rect2.Width == 0 || rect2.Height == 0) { return rect1; } return Rectangle.Union(rect1, rect2); } </pre> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1335
(왼쪽의 숫자를 입력해야 합니다.)