Classification window: Based on basic capplication-bit encoding (6 B)

Source: Internet
Author: User

Classification window: Based on basic capplication-bit encoding (6 B)

I have recently studied the location of ghost (BMP, which can be understood as a ghost film in Windows). When it comes to being a ghost, all the ghost movies on the ghost are ghost! As a result, I am eager to study and complete a small example. I am going to discuss it for beginners.

This time, I added a configuration file (bitmap1.bmp) to the project. The main program is still an old window with full screen dishes. Click "submit case"> "Submit" to show the slice (stretch, if necessary) in the window. See the following example. So simple.

Program running effect:

 

Click here to download the project file. (Note: Due to the earthquake in the bottom of the sea, I will put it back after restoration)

 

Note: In this example, the bitwise file is imported into the project as the resource, so the exported file is an EXE file, the attachment has been merged into the EXE file.

Create a new project named "production film B". The project will be capplication. h. capplication. CPP has all been written, and a new main is created. h, Main. CPP and so on. If you are not familiar with the architecture, you may wish to compile this series from the beginning.

First, we need to add a video source to the project, click "insert"-> "resource"-> "click" insert resource ", click" import "on the right of the" insert resource "dialog box, and select" all files ", then select the BMP file you just inserted. For example, here I will write a picture of the uploaded file, because I found that they all liked the zookeeper as an example, ^_^. The metadata ID of the Shard is called "idb_bitmap1.

Note: If the bit colors you insert are over 256 colors, for example, 24 colors, then VC will not be able to adjust or adjust the values.

Now let's look at the generation:

First look at the main. cpp File

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////////////

/// // Main. CPP //////////////////////////////////////

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////////////

# Include <windows. h>

# Include "capplication. H"
# Include "Main. H"
# Include "extra. H"
# Include "resource. H"

Capplication app;

// Process processed in the Main Window
Lresult callback winproc (hwnd,
Uint umsg,
Wparam,
Lparam)
{
Static hinstance;

Hwnd hwnddesktop;
Static HDC hdcmem;
HDC, hdcdesktop;
Static hbitmap;
Bitmap bitmap;
Static uint cxscreen, cyscreen, cxclient, cyclient;

Paintstruct pS;

// Message Processing
Switch (umsg)
{
// Producer Creation
Case wm_create:
Hinstance = (lpcreatestruct) lparam)-> hinstance;

Hwnddesktop = getmediatopwindow ();
Hdcdesktop = getdc (hwnddesktop );
 
Hdcmem = createcompatibledc (hdcdesktop );
 
Cxscreen = getdevicecaps (hdcdesktop, horzres );
Cyscreen = getdevicecaps (hdcdesktop, vertres );

Hbitmap = createcompatiblebitmap (hdcdesktop,
Cxscreen, cyscreen );

// Inject hbitmap into hdcmem
SelectObject (hdcmem, hbitmap );

// Showwindow (hwnd, sw_hide );

Bitblt (hdcmem, 0, 0,
Cxscreen, cyscreen,
Hdcdesktop, 0, 0, srccopy );

Showwindow (hwnd, sw_show );

Deletedc (hdcdesktop );

Return 0; // combine a condition

// Modify the size
Case wm_size:
Cxclient = loword (lparam );
Cyclient = hiword (lparam );
Return 0; // modify the size to merge
 
// Zookeeper
Case wm_paint:
HDC = beginpaint (hwnd, & PS );
If (hbitmap)
{
//
GetObject (hbitmap, sizeof (Bitmap), & Bitmap );
Hdcmem = createcompatibledc (HDC );
SelectObject (hdcmem, hbitmap );

//
Setstretchbltmode (HDC, coloroncolor );
Stretchblt (HDC, 0, 0, cxclient, cyclient, hdcmem, 0, 0, cxscreen, cyscreen, srccopy );

Deletedc (hdcmem );
}
Endpaint (hwnd, & PS );
Return 0;


// Use the dish list
Case wm_command:
Switch (loword (wparam ))
{
// Cancel case-> quit
Case idm_file_exit:
Sendmessage (hwnd, wm_close, 0, 0 );
Return 0;

// Submit the case-> submit the case
Case idm_file_load:
If (hbitmap)
{
Deleteobject (hbitmap );
Hbitmap = NULL;
}
Hbitmap = (hbitmap) LoadImage (hinstance,
Makeintresource (idb_bitmap1 ),
Image_bitmap,
Cxclient, cyclient,
Lr_createdibsection );

// Weight conversion
Invalidaterect (hwnd, null, true );
Break;

// Help-> about
Case idm_help_about:
Dialogbox (hinstance,
Makeintresource (idd_about ),
Hwnd,
(Dlgproc) dialogaboutproc );

Return 0;

}

Return 0; // combine the dishes
} // Message Handling

// MMO Message Handling
Return app. msgproc (hwnd, umsg, wparam, lparam );

} // Process merging in the Main Window

 

// Main program Portal
Int winapi winmain (hinstance,
Hinstance hprevinstance,
Lpstr lpcmdline,
Int ncmdshow)
{
// The ingress entry criteria
App. set_hicon (hinstance, idi_icon1 );
// Fill in the optical mark
App. set_hcursor (hinstance, idc_cursor1 );
// Add a ticket
App. set_hmenu (hinstance, idr_menu1 );
 
// Set the window size
App. isfullscreen (true );
// App. setscreenw (400 );
// App. setscreenh (300 );

// Background color of the customer Region
// App. setclientbkcolor (black_brush );

// Producer creation window
App. createwin (winproc,
Hinstance,
"Slice B ",
Ws_overlappedwindow );

// Operate the message-based mechanism of the recognized Operator
Return app. rundefault ();
}

//////////////////////////////////////// /// // EOF ////////////////////////// /////////////////////////

All new things are stored in this file. Let's analyze them again:

First, create a bitmap object bitmap, and then create a bitmap handle hbitmap, this handle is used as the "handle" to be opened by the LoadImage function.

Bitmap bitmap;
Static hbitmap;

 

Use if to clean up the scene first in the processing of the "food orders" option, and then

Hbitmap = (hbitmap) LoadImage (hinstance,
Makeintresource (idb_bitmap1 ),
Image_bitmap,
Cxclient, cyclient,
Lr_createdibsection );

Makeintresource (idb_bitmap1) specifies that the opened data source is "idb_bitmap1", which is the bitmap that we entered only after obtaining the handler "invalidaterect (hwnd, null, true); "returns the weight system.

In the "case wm_paint:" example, use the processing handle of the courier. hbitmap to stretch the parts (if necessary) into the passenger area. .

 

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.