Usage and precautions of SelectObject in C ++ GDI

Source: Internet
Author: User
Describes cpen * SelectObject (cpen * ppen); cbrush * SelectObject (cbrush * pbrush); Virtual cfont * SelectObject (cfont * pfont); cbitmap * SelectObject (cbitmap * pbitmap ); int SelectObject (crgn * prgn); cgdiobject * SelectObject (cgdiobject * pobject); function: This function selects an object to the specified device context, this new object replaces the previous objects of the same type. Function prototype: hgdiobj SelectObject (HDC, hgdiobj); parameter: HDC: handle of the device context. Hgdiobj: the handle of the selected object. The specified object must be created by the following function. Bitmap: createbitmap, createbitmapindirect, createcompatible bitmap, createdibitmap, and createdibsection (Bitmap can be selected only in the memory device context environment, and only one device context environment can be selected at a time ). Paint Brush: createbrushindirect, createdibpatternbrush, createdibpatternbrushpt, createhatchbrush, createpatternbrush, and createsolidbrush. Font: createfont, createfontindirect. Pen: createpen, createpenindirect. Region: combinergn, createellipticrgn, createellipticrgnindirect, createpolygonrgn, createrectrgn, and createrectrgnindirect. Return Value: If the selected object is not a region and the function is successfully executed, the return value is the handle of the replaced object. If the selected object is a region and the function is successfully executed, the following value is returned; simpleregion: A region consists of a single rectangle. complexregion: a region consists of multiple rectangles. Nullregion: The region is empty. If an error occurs and the selected object is not a region, the return value is null. Otherwise, gdi_error is returned. Note: This function returns a previously specified type of selection object. After an application draws a new object, it should replace the New object with the original default object. The application cannot select a bitmap to the context of multiple devices at the same time. ICM: If the selected object is a paint brush or pen, color management is performed. Quick query: Windows NT: 3.1 and later; windows: 95 and later; Windows CE: 1.0 and later; header file: wingdi. h; library file: gdi32.lib. Edit this section Example HDC = getdc (hwnd); HDC memdc = createcompatibledc (HDC); rect RC; bitmap BMP; hbitmap holdbmp, hbmp = loadbitmap (hinstdvbres, makeintresource (idb_clock )); // load the bitmap from the resource. holdbmp = (hbitmap) SelectObject (memdc, hbmp); // select the bitmap of hbmp to be compatible with DC memdc, after that, the compatible DC will have a drawing area of the same size as/hbmp. Note that the output of the GDI file returned by the bitmap is invalid. getObject (hbmp, sizeof (Bitmap), & BMP); // The bitmap size information is obtained here. In fact, it is also compatible with the setrect (& rc, BMP) Output Range of DC plotting. bmwidth, BMP. bmheight); drawtext (memdc, "center line text"-1, & rc, dt_vcenter | dt_singleline | dt_center ); // output the string in the compatible DC center. // This is equivalent to adding a text annotation to the hbmp bitmap. We can save the bitmap with the added text annotation. A simple image processing is basically OK. selectObject (memdc, holdbmp); // restores DC-compatible data. deletedc (memdc );

 

reference: new Windows API reference

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.