1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static int cxClient, cyClient, cxImg, cyImg;
HDC hdc;
PAINTSTRUCT ps;
static Gdiplus::Graphics* graphic1=nullptr;
static Gdiplus::Image* image1=nullptr;
switch (iMsg)
{
case WM_CREATE:
{
image1 = Gdiplus::Image::FromFile(L"Night BW test.jpg");
if(image1==nullptr) MessageBoxW(0, L"File Load Failed", L"File Status", 0);
graphic1 = Gdiplus::Graphics::FromImage(image1);
if(image1==nullptr) MessageBoxW(0, L"Image Load Failed", L"Graphic Object", 0);
cxImg = image1->GetWidth();
cyImg = image1->GetHeight();
}
case WM_SIZE:
{
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
}
case WM_PAINT:
{
int cxSize, cySize, xImgOrg, yImgOrg, eImgSts, scaleflag=1;
float fScale;
hdc = BeginPaint(hwnd, &ps);
if (scaleflag) {
if (cxImg/cyImg > cxClient/cyClient) fScale = float(cxClient)/float(cxImg);
else fScale = float(cyClient)/float(cyImg);
cxSize = int(cxImg*fScale+0.5);
cySize = int(cyImg*fScale+0.5);
}
else { cxSize = cxImg; cySize = cyImg; }
xImgOrg = (cxClient-cxSize)/2;
yImgOrg = (cyClient-cySize)/2;
eImgSts = graphic1->DrawImage(image1, xImgOrg, yImgOrg, cxSize, cySize);
if(eImgSts) MessageBoxW(0, L"Draw Image Failed", L"DrawImage", 0);
EndPaint(hwnd, &ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
| |