static HBITMAP hBmp1;
static HBITMAP hBmp2;
static int cxBmp;
static int cyBmp;
case WM_CREATE:
{
//load bmp
hBmp1 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP1));
if (hBmp1 == NULL)
{
MessageBox(hWnd,L"failed to load bmp1!",NULL,MB_OK);
}
hBmp2 = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_BITMAP2));
if (hBmp2 == NULL)
{
MessageBox(hWnd,L"failed to load bmp2!",NULL,MB_OK);
}
//get bmp info
BITMAP bmpInfo;
GetObject(hBmp1,sizeof(BITMAP),&bmpInfo);
cxBmp = bmpInfo.bmWidth;
cyBmp = bmpInfo.bmHeight;
//put window int the middle screen
int cxScr = GetSystemMetrics(SM_CXSCREEN);
int cyScr = GetSystemMetrics(SM_CYSCREEN);
int cxWnd = cxBmp + 2 * GetSystemMetrics(SM_CXFRAME);
int cyWnd = cyBmp + 2 * GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CYCAPTION);
MoveWindow(hWnd,(cxScr-cxWnd)/2,(cyScr-cyWnd)/2,cxWnd,cyWnd,TRUE);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
{
//disp bmp
HDC hMemDC1 = CreateCompatibleDC(hdc);
HDC hMemDC2 = CreateCompatibleDC(hdc);
SelectObject(hMemDC1, hBmp1);
SelectObject(hMemDC2, hBmp2);
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 128;//alpha transparency value
bf.AlphaFormat = 0;
AlphaBlend(hMemDC1,0,0,cxBmp,cyBmp,hMemDC2,0,0,cxBmp,cyBmp,bf);
BitBlt(hdc, 0, 0,cxBmp, cyBmp, hMemDC1, 0, 0, SRCCOPY);
DeleteDC(hMemDC1);
DeleteDC(hMemDC2);
}
EndPaint(hWnd, &ps);
break;