//. RC
PIC bitmap "pic.bmp"
//. Cpp # include <windows. h>
Lresult callback wndproc (hwnd, uint, wparam, lparam );
Hbitmap HBM;
Bitmap bm;
Int i1_wwidth;
Int iwindowheight;
HDC;
HDC hdcmem;
Paintstruct pS;
Int winapi winmain (hinstance,
Hinstance hprevinst,
Lpstr lpszcmdline,
Int ncmdshow)
{
Hwnd;
MSG;
// Use hbitmap to point to images in the Resource
HBM = loadbitmap (hinstance, "pic ");
// Read the image to the bitmap struct.
GetObject (HBM, sizeof (Bitmap), & BM );
// Obtain the window size based on the image size
Iw.wwidth = BM. bmwidth;
Iwindowheight = BM. bmheight;
Wndclass;
Char lpszclassname [] = "window ";
Char lpsztitle [] = "window sample program ";
Wndclass. Style = 0;
Wndclass. lpfnwndproc = wndproc;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hinstance = hinstance;
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. lpszmenuname = NULL;
Wndclass. lpszclassname = lpszclassname;
If (! Registerclass (& wndclass ))
{
Messagebeep (0 );
Return false;
}
Hwnd = createwindow (lpszclassname,
Lpsztitle,
Ws_caption | ws_sysmenu,
Cw_usedefault, cw_usedefault,
Iwindowwidth, iwindowheight,
Null,
Null,
Hinstance,
Null );
Showwindow (hwnd, ncmdshow );
Updatewindow (hwnd );
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return (INT) msg. wparam;
}
Lresult callback wndproc (hwnd, uint message, wparam, lparam
Iparam)
{
Switch (Message)
{
Case wm_create:
// Obtain the device description table
HDC = getdc (hwnd );
// Create the same device description table as HDC in the memory
Hdcmem = createcompatibledc (HDC );
// Release the device description table
Releasedc (hwnd, HDC );
Break;
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
// Select the image to draw
SelectObject (hdcmem, HBM );
// Display the image from hdcmem to HDC
Bitblt (HDC, BM. bmwidth, BM. bmheight, hdcmem, srccopy );
Endpaint (hwnd, & PS );
Break;
Case wm_destroy:
Postquitmessage (0 );
Default:
Return defwindowproc (hwnd, message, wparam, iparam );
}
Return (0 );
}