void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, LONG xStart, LONG yStart, COLORREF cTransparentColor)  
{  
BITMAP bm;  
COLORREF cColor;  
HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave;  
HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld;  
HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave;  
POINT ptSize;  
/* 초기화 작업 */
hdcTemp = CreateCompatibleDC(hdc);  
SelectObject(hdcTemp, hBitmap); // 비트맵 선택

GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);  
ptSize.x = bm.bmWidth; // 비트맵 가로 크기 
ptSize.y = bm.bmHeight; // 비트맵 세로 크기
DPtoLP(hdcTemp, &ptSize, 1); // 디바이스를 논리적 위치로 변경

// 작업용 DC 생성
hdcBack = CreateCompatibleDC(hdc);  
hdcObject = CreateCompatibleDC(hdc);  
hdcMem = CreateCompatibleDC(hdc);  
hdcSave = CreateCompatibleDC(hdc);  

// 흑백 연산 (and,or연산)에 필요한 비트맵 생성 
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);  
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);  
// 작업용 비트맵들 생성 
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);  
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y);  

// 각 비트맵 삭제 위한 old 비트맵 생성 
bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);  
bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);  
bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);  
bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);  

//그려질 DC와 생성된 임시DC의 맵핑 모드 일치화 
SetMapMode(hdcTemp, GetMapMode(hdc));  

// 원본 보전 작업
BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);  

// 투명화 시킬 색을 Tempdc의 배경색으로 설정,
// 이때 SetBkColor의 리턴 값으로 원본 색 저장
cColor = SetBkColor(hdcTemp, cTransparentColor);  

/* 주어진 비트맵의 투명색(BkColor로 지정된)은 힌색으로,
나머지는 검은색으로하여 BlackWhitedc_1에 저장 */
BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0,   
SRCCOPY);  

// 배경 색을 원본 색상 DC를 가져오기
SetBkColor(hdcTemp, cColor);  

// BlackWhitedc_1를 이용 투명 영역(검은색), 비투명 영역(힌색)으로 된 DC생성 
BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0,   NOTSRCCOPY);  

// 그려질 hdc에서 비트맵이 위치할 곳의 배경을 작업용 DC로 이동 
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY);  
//BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, 0, 0, SRCCOPY);  

// 그려질 배경과 and 연산을 통해 배경투명구현(힌색 소멸), 비투명 영역은 검은 색으로
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);  

// 주어진 비트맵과 and 연산을 통해 투명부분(검은색으로), 비투명은 그대로
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);  

// 위에서 만든 2개의 DC(Workdc, Tempdc)의 or 연산을 통해 두 DC결합 
BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);  

//  결과를 표시
 BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);  

//  원본을 임시 DC에 복구
BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);  

// 메모리에 있는 각 비트맵 삭제
DeleteObject(SelectObject(hdcBack, bmAndBack));  
DeleteObject(SelectObject(hdcObject,bmAndObject));  
DeleteObject(SelectObject(hdcMem, bmAndMem));  
DeleteObject(SelectObject(hdcSave, bmSave));  
DeleteObject(SelectObject(hdcBack, bmBackOld));  
DeleteObject(SelectObject(hdcObject,bmObjectOld));  
DeleteObject(SelectObject(hdcMem, bmMemOld));  
DeleteObject(SelectObject(hdcSave, bmSaveOld));  

// 각 DC삭제 
DeleteDC(hdcBack);  
DeleteDC(hdcObject);
DeleteDC(hdcMem);    
DeleteDC(hdcSave);  
DeleteDC(hdcTemp);  
DeleteDC(hdc); // 자신의 DC를 삭제하지 않으면 GDI 객체는 계속 늘어나게 된다..
 }  


/// 사용 예시..
DrawTransparentBitmap(::GetDC(((CStatic*)GetDlgItem(컨트롤))->GetSafeHwnd()), (BMP), 0, 0, 색상);

// 미리 정의해 놓고 사용하면 좀더 편리함...
#define TRANS_BITMAP(CTRL, BMP); DrawTransparentBitmap(::GetDC(((CStatic*)GetDlgItem(CTRL))->GetSafeHwnd()), (BMP), 0, 0, BLACK);


사업자 정보 표시
가나소프트 | 김용유 | 충남 천안시 동남구 목천읍 서리2길 42-1 | 사업자 등록번호 : 312-33-14797 | TEL : 070-8659-0316 | Mail : yykim@gana-soft.com | 통신판매신고번호 : 12390123호 | 사이버몰의 이용약관 바로가기

/* =-=-=-=-=-=-=-=-=-=-=-=-=-= Window Messages =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

#define WM_NULL           0x0000
#define WM_CREATE                   0x0001
#define WM_DESTROY                  0x0002
#define WM_MOVE                     0x0003
#define WM_SIZE                     0x0005
#define WM_ACTIVATE                 0x0006

/* WM_ACTIVATE state values */
#define     WA_INACTIVE             0
#define     WA_ACTIVE               1
#define     WA_CLICKACTIVE          2

#define WM_SETFOCUS                 0x0007
#define WM_KILLFOCUS                0x0008
#define WM_ENABLE                   0x000A
#define WM_SETREDRAW                0x000B
#define WM_SETTEXT                  0x000C
#define WM_GETTEXT                  0x000D
#define WM_GETTEXTLENGTH            0x000E
#define WM_PAINT                    0x000F
#define WM_CLOSE                    0x0010
#define WM_QUERYENDSESSION         0x0011
#define WM_QUIT                     0x0012
#define WM_QUERYOPEN                0x0013
#define WM_ERASEBKGND               0x0014
#define WM_SYSCOLORCHANGE          0x0015
#define WM_ENDSESSION               0x0016
#define WM_SHOWWINDOW               0x0018
#define WM_WININICHANGE             0x001A
#if(WINVER >= 0x0400)
#define WM_SETTINGCHANGE        WM_WININICHANGE
#endif /* WINVER >= 0x0400 */

#define WM_DEVMODECHANGE          0x001B
#define WM_ACTIVATEAPP              0x001C
#define WM_FONTCHANGE               0x001D
#define WM_TIMECHANGE               0x001E
#define WM_CANCELMODE               0x001F
#define WM_SETCURSOR                0x0020
#define WM_MOUSEACTIVATE           0x0021
#define WM_CHILDACTIVATE            0x0022
#define WM_QUEUESYNC                0x0023

#define WM_GETMINMAXINFO            0x0024
// end_r_winuser

// begin_r_winuser
#define WM_PAINTICON             0x0026
#define WM_ICONERASEBKGND      0x0027
#define WM_NEXTDLGCTL               0x0028
#define WM_SPOOLERSTATUS           0x002A
#define WM_DRAWITEM                 0x002B
#define WM_MEASUREITEM              0x002C
#define WM_DELETEITEM               0x002D
#define WM_VKEYTOITEM               0x002E
#define WM_CHARTOITEM               0x002F
#define WM_SETFONT                  0x0030
#define WM_GETFONT                  0x0031
#define WM_SETHOTKEY                0x0032
#define WM_GETHOTKEY                0x0033
#define WM_QUERYDRAGICON            0x0037
#define WM_COMPAREITEM              0x0039
#if(WINVER >= 0x0500)
#define WM_GETOBJECT             0x003D
#endif /* WINVER >= 0x0500 */
#define WM_COMPACTING            0x0041
#define WM_COMMNOTIFY             0x0044  /* no longer suported */
#define WM_WINDOWPOSCHANGING   0x0046
#define WM_WINDOWPOSCHANGED    0x0047

#define WM_POWER                 0x0048
/*
* wParam for WM_POWER window message and DRV_POWER driver notification
*/
#define PWR_OK                   1
#define PWR_FAIL                 (-1)
#define PWR_SUSPENDREQUEST      1
#define PWR_SUSPENDRESUME       2
#define PWR_CRITICALRESUME       3

#define WM_COPYDATA              0x004A
#define WM_CANCELJOURNAL         0x004B
// end_r_winuser

// begin_r_winuser
#if(WINVER >= 0x0400)
#define WM_NOTIFY                0x004E
#define WM_INPUTLANGCHANGEREQUEST  0x0050
#define WM_INPUTLANGCHANGE      0x0051
#define WM_TCARD                    0x0052
#define WM_HELP                     0x0053
#define WM_USERCHANGED            0x0054
#define WM_NOTIFYFORMAT           0x0055

#define NFR_ANSI                    1
#define NFR_UNICODE                 2
#define NF_QUERY                    3
#define NF_REQUERY                  4

#define WM_CONTEXTMENU              0x007B
#define WM_STYLECHANGING            0x007C
#define WM_STYLECHANGED             0x007D
#define WM_DISPLAYCHANGE            0x007E
#define WM_GETICON                  0x007F
#define WM_SETICON                  0x0080
#endif /* WINVER >= 0x0400 */

#define WM_NCCREATE                 0x0081
#define WM_NCDESTROY               0x0082
#define WM_NCCALCSIZE              0x0083
#define WM_NCHITTEST                0x0084
#define WM_NCPAINT                  0x0085
#define WM_NCACTIVATE              0x0086
#define WM_GETDLGCODE             0x0087
#define WM_SYNCPAINT                0x0088
#define WM_NCMOUSEMOVE          0x00A0
#define WM_NCLBUTTONDOWN       0x00A1
#define WM_NCLBUTTONUP           0x00A2
#define WM_NCLBUTTONDBLCLK          0x00A3
#define WM_NCRBUTTONDOWN            0x00A4
#define WM_NCRBUTTONUP              0x00A5
#define WM_NCRBUTTONDBLCLK    0x00A6
#define WM_NCMBUTTONDOWN      0x00A7
#define WM_NCMBUTTONUP          0x00A8
#define WM_NCMBUTTONDBLCLK    0x00A9

#define WM_KEYFIRST                0x0100
#define WM_KEYDOWN                  0x0100
#define WM_KEYUP                    0x0101
#define WM_CHAR                     0x0102
#define WM_DEADCHAR                 0x0103
#define WM_SYSKEYDOWN              0x0104
#define WM_SYSKEYUP                 0x0105
#define WM_SYSCHAR                  0x0106
#define WM_SYSDEADCHAR             0x0107
#define WM_KEYLAST                  0x0108

#if(WINVER >= 0x0400)
#define WM_IME_STARTCOMPOSITION  0x010D
#define WM_IME_ENDCOMPOSITION      0x010E
#define WM_IME_COMPOSITION          0x010F
#define WM_IME_KEYLAST              0x010F
#endif /* WINVER >= 0x0400 */

#define WM_INITDIALOG               0x0110
#define WM_COMMAND                  0x0111
#define WM_SYSCOMMAND              0x0112
#define WM_TIMER                    0x0113
#define WM_HSCROLL                  0x0114
#define WM_VSCROLL                  0x0115
#define WM_INITMENU                 0x0116
#define WM_INITMENUPOPUP            0x0117
#define WM_MENUSELECT               0x011F
#define WM_MENUCHAR                 0x0120
#define WM_ENTERIDLE                0x0121
#if(WINVER >= 0x0500)
#define WM_MENURBUTTONUP          0x0122
#define WM_MENUDRAG                 0x0123
#define WM_MENUGETOBJECT          0x0124
#define WM_UNINITMENUPOPUP        0x0125
#define WM_MENUCOMMAND            0x0126
#endif /* WINVER >= 0x0500 */

#define WM_CTLCOLORMSGBOX        0x0132
#define WM_CTLCOLOREDIT             0x0133
#define WM_CTLCOLORLISTBOX        0x0134
#define WM_CTLCOLORBTN              0x0135
#define WM_CTLCOLORDLG              0x0136
#define WM_CTLCOLORSCROLLBAR    0x0137
#define WM_CTLCOLORSTATIC          0x0138

#define WM_MOUSEFIRST               0x0200
#define WM_MOUSEMOVE                0x0200
#define WM_LBUTTONDOWN              0x0201
#define WM_LBUTTONUP                0x0202
#define WM_LBUTTONDBLCLK            0x0203
#define WM_RBUTTONDOWN              0x0204
#define WM_RBUTTONUP                0x0205
#define WM_RBUTTONDBLCLK            0x0206
#define WM_MBUTTONDOWN              0x0207
#define WM_MBUTTONUP                0x0208
#define WM_MBUTTONDBLCLK            0x0209

#if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
#define WM_MOUSEWHEEL              0x020A
#define WM_MOUSELAST                0x020A
#else
#define WM_MOUSELAST                0x0209
#endif /* if (_WIN32_WINNT < 0x0400) */

#if(_WIN32_WINNT >= 0x0400)
#define WHEEL_DELTA              120     /* Value for rolling one detent */
#endif /* _WIN32_WINNT >= 0x0400 */
#if(_WIN32_WINNT >= 0x0400)
#define WHEEL_PAGESCROLL            (UINT_MAX) /* Scroll one page */
#endif /* _WIN32_WINNT >= 0x0400 */

#define WM_PARENTNOTIFY          0x0210
#define WM_ENTERMENULOOP         0x0211
#define WM_EXITMENULOOP          0x0212

#if(WINVER >= 0x0400)
#define WM_NEXTMENU              0x0213
// end_r_winuser


사업자 정보 표시
가나소프트 | 김용유 | 충남 천안시 동남구 목천읍 서리2길 42-1 | 사업자 등록번호 : 312-33-14797 | TEL : 070-8659-0316 | Mail : yykim@gana-soft.com | 통신판매신고번호 : 12390123호 | 사이버몰의 이용약관 바로가기

1) WideString 
캐스팅 시키는 함수. 아래 방법으로 하시면, A에 wchat_t 형식으로 Hello가 들어갑니다. 

A = WideString("Hello"); 

2) StringToOleStr 
원라는 AnsiString용 함수입니다. char 배열도 사용할 수 있습니다. 

A = StringToOleStr("Hello"); 

3) MultiByteToWideChar 
이 방법을 쓰시면 UTF8 형식으로도 변경할 수 있습니다. UniCode를 사용하는 경우, 이 API를 꼭 이용하셔야 합니다. UTF8을 원하시면 CP_ACP 부분을 CP_UTF8 로 바꾸어 주시면 됩니다. 이 방법은 조금 복잡합니다. 먼저 문자열 길이가 얼마나 나오는지 얻어낸 다음, 그 길이만큼 변수를 잡고, 변환을 다시 시켜야 합니다. 

String            stString = "HELLO"; 
int               itWideSize = MultiByteToWideChar(CP_UTF8, 0, stString.c_str(), stString.Length() + 1, NULL, 0); 
wchar_t           *wcTarget = new wchar_t[itWideSize]; 

MultiByteToWideChar(CP_ACP, 0, stString.c_str(), stString.Length() + 1, wcTarget, itWideSize); 
=========================================================================================================

볼랜드포럼 유영인님 글에서 발췌


사업자 정보 표시
가나소프트 | 김용유 | 충남 천안시 동남구 목천읍 서리2길 42-1 | 사업자 등록번호 : 312-33-14797 | TEL : 070-8659-0316 | Mail : yykim@gana-soft.com | 통신판매신고번호 : 12390123호 | 사이버몰의 이용약관 바로가기

+ Recent posts