Win32 loads images to the program

Source: Internet
Author: User

//. 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 );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.