LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam) {
static HBITMAP hBitmap;
static int cxClient, cyClient;
static HDC hMem;
HDC hdc;
PAINTSTRUCT ps;
static POINT pt;
int x, y;
static HINSTANCE hLibrary;
BITMAP bp;
switch(message) {
case WM_CREATE:
// 这是dll文件的名字
if(NULL == (hLibrary = LoadLibrary(TEXT("dll.dll")))) {
MessageBox(hwnd, TEXT("can't load dll.dll"),
TEXT("error"), MB_ICONERROR);
return -1;
}
hdc = GetDC(hwnd);
// 这是DLL里的资源
hBitmap = LoadBitmap(hLibrary, TEXT("DLL"));
hMem = CreateCompatibleDC(hdc);
SelectObject(hMem, hBitmap);
GetObject(hBitmap, sizeof(BITMAP), &bp);
pt.x = bp.bmWidth;
pt.y = bp.bmHeight;
ReleaseDC(hwnd, hdc);
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
for(x = 0; x < cxClient; x += pt.x)
for(y = 0; y < cyClient; y += pt.y)
BitBlt(hdc, x, y, pt.x, pt.y, hMem, 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
if(hLibrary)
FreeLibrary(hLibrary);
if(hBitmap)
DeleteObject(hBitmap);
if(hMem)
DeleteDC(hMem);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
|