혹시 win32 api 잘하시는분 계시나요?

익명 사용자의 이미지

안녕하세요 고수님들

제가 win32 api로 라이브러리를 하나 만들고 있습니다

근데 다른 에디터나 윈도우는 보면 전역이나 클래스 멤버로

많이 하는거 같던데 그 DC라는 놈은 유독 지역변수로 선언하고 사용하더라구요

매번 GetDC로 얻어오고 dc를 해제시키는게 너무 불편하더라구요..

이걸 전역이나 클래스 멤버로 한번만 선언해두고

프로그램 안에서 공유하면 안되는건가요?

뭔가 dc를 매번 교체를 해주어야 하는 특별한 이유가 있는건지요?

shint의 이미지

Device Context : DC 를 얻는 다양한 함수가 있습니다.

HDC 크기라면. 어디든 변수 데이터는 보관이 가능할 겁니다. (전역도 상관 없을겁니다.)

SaveDC() 는 Stack 에 DC 를 보관해서 사용할 수 있다고 합니다.

경우에 따라서는 BeginPaint() 의 PAINTSTRUCT 를 사용하면. 훨씬 빠르기도 하다고 합니다.
http://del4u.tistory.com/16

GetDC()는 검색을 한다고 하네요.
The GetDC function retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The device context is an opaque data structure, whose values are used internally by GDI.
The GetDCEx function is an extension to GetDC, which gives an application more control over how and whether clipping occurs in the client area.

GetDC 함수는 지정된 창이나 전체 화면의 클라이언트 영역에 대한 장치 컨텍스트 (DC)에 대한 핸들을 검색합니다. 후속 GDI 함수에서 반환 된 핸들을 사용하여 DC를 그릴 수 있습니다. 장치 컨텍스트는 불투명 한 데이터 구조이며, 그 값은 GDI에 의해 내부적으로 사용됩니다.
GetDCEx 함수는 응용 프로그램이 클라이언트 영역에서 클리핑이 발생하는 방법과 방법을보다 잘 제어 할 수있게 해주는 GetDC의 확장입니다.

GetDC()
https://msdn.microsoft.com/ko-kr/library/windows/desktop/dd144871(v=vs.85).aspx
ReleaseDC()
https://msdn.microsoft.com/ko-kr/library/windows/desktop/dd162920(v=vs.85).aspx

SaveDC()
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162945(v=vs.85).aspx
RestoreDC()
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162929(v=vs.85).aspx

BeginPaint()
https://msdn.microsoft.com/ko-kr/library/windows/desktop/dd183362(v=vs.85).aspx
EndPaint()
https://msdn.microsoft.com/ko-kr/library/windows/desktop/dd162598(v=vs.85).aspx

WinAPI
http://soen.kr/

구글 번역
https://translate.google.co.kr/?hl=ko&tab=wT

//
Windows Data Types 윈도우즈 데이터 형식
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx

HDC
A handle to a device context (DC).
This type is declared in WinDef.h as follows:
typedef HANDLE HDC;

HANDLE
A handle to an object.
This type is declared in WinNT.h as follows:
typedef PVOID HANDLE;

PVOID
A pointer to any type.
This type is declared in WinNT.h as follows:
typedef void *PVOID;

VOID
Any type.
This type is declared in WinNT.h as follows:
#define VOID void

HDC 변수 소스를 따라가보면. (변수위에서 마우스 우측 누르면. reference 어쩌고 있을겁니다.)

HDC 는 HANDLE 이고. HANDLE 은 PVOID 이고. PVOID 는 void* 형이라고 합니다.
void 는 VOID 로 정해져 있는데. sizeof(void) 라고 하면. 크기를 알 수 있습니다.
sizeof( void * ) 로 void * 형에 크기도 얻을 수 있습니다.

sizeof( HDC )
sizeof( HANDLE )
sizeof( PVOID )
sizeof( void * )
포인터'의 크기는 32비트 (4바이트 ??) / 64비트 (8바이트 ??) '에서 다를 수 있습니다.

만약. HDC 가 32비트 윈도우에서 4바이트' 크기라면...
int 는 4바이트
HDC 는 4바이트

int a;
HDC hdc;
a = (int) hdc; // 명시적 형변환

void *p; //p에 메모리 주소가 할당되어 있지 않지만. 생략하고. 적어봅니다.
a = (int) p;

http://codepad.org/ijfkhh24

#include <stdio.h>
 
int main()
{
int a;
void *p;
a = (int)p;
printf("%d\n",p);
printf("%d\n",a);
return 0;
}

확인해보니. HDC 는 포인터 변수'네요. ㅇ_ㅇ;;

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.