Code for adding images and music to Win32 APIs

Source: Internet
Author: User
Tags bmp image

Add music:
Static Library: # pragma comment (Lib, "winmm. lib") // windows multimedia library
Playsound ("1.wav", null, snd_filename | snd_async );

Retrieve window handle
Hinstance = (lpcreatestruct) lparam)-> hinstance;

Add image:
However, it must be a bitmap, that is, BMP format.
Static hbitmap hbitmap1, holdbitmap; // apply for an image handle
Static bitmap BMP Info; // used to obtain BMP image information, such as length and width.
Static int cxbitmap, cybitmap; // used to indicate the length and width of the added image.
Static HDC hdcbackbuffer; // request Resource Space, which can also be called a buffer zone
(Hbitmap) LoadImage (hinstance, "White. BMP", image_bitmap, 0, 0, lr_loadfromfile | lr_createdibsection );//
Add the white. BMP image and the handle is hbitmap1. This handle represents this image when used elsewhere.
Hdcbackbuffer =
Createcompatibledc (null)
; // Request Buffer
GetObject (hbitmap1, sizeof (Bitmap), & BMP info)
; // Obtain the information of the added image. The information is stored in the BMP info pointer.
Cxbitmap = BMP info. bmwidth; // get the width and height of the image through BMP info
Cybitmap = BMP info. bmheight;
Holdbitmap = (hbitmap) SelectObject (hdcbackbuffer, hbitmap1); // place the image in the applied buffer zone. You can directly draw the image in the buffer zone.

(HDC, X1, Y1, A1, B1, hdcbackbuffer, 0, 0, cxbitmap, cybitmap, srccopy); // Where X1 and Y1 are
Position of the image in the window. A1 and B1 indicate the width and height of the image. hdcbackbuffer is the image buffer handle, that is, the image. The following four parameters are the position, width, and height of the original image.
Degrees, srccopy directly copies the source rectangular area to the target rectangular area

Common Information
Case wm_size: // if you use cxclient and cyclient to convert the value to a parameter in the drawing, the image will not disappear when the value is minimized.
Cxclient = loword (lparam );
Cyclient = hiword (lparam );
Return 0;
Case wm_command: // receive menu Information
Switch (loword (wparam ))

Case wm_keydown: // receives keyboard key information
Switch (wparam)
Case ....

Mouse value storage location
Mousex = loword (lparam); // access the horizontal and vertical coordinates of the mouse
Mousey = hiword (lparam );

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: 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.