Introduction to Windows Client Development (IV)

Source: Internet
Author: User

        in the previous article, I briefly gave you a brief introductionGDIthe basic knowledge, includingDC,HDC,GDIobjects and so on, in general, are partial theoretical knowledge, belonging to the concept of the category.

Today in this article, I will formally start a bit of practical things, I'll teach you some Basic functions of GDI coding, basic skills, of course, how to avoid the basic pit, haha, right, basic pits rather than advanced.

         So how do I say, first I want to tell you how to createDC, how to useDC, how to setDCthe attributes (that is,GDIobject), how toDCTo draw simple text, draw a graphic, draw a picture is also a bitmap. I'll talk to you about it.GDI +, talk aboutCImageThis drawing is super convenient class (I have used this class extensively in my past projects), and I want to talk about the implementation of the Fillet window, including the method of masking color and the way of cascading windows. Of course, so much of the content in such an article is definitely not complete, so I will be in the following article one by one, interested friends can wait for me an article Wan Wan road.

         &NBSP, first to talk DC

         &NBSP, get DC There are several ways, in general there are several types of

CreateDC , consult MSDN the parameters are as follows:

HDC CreateDC (LPCTSTR lpszdriver, LPCTSTR lpszdevice, LPCTSTR lpszoutput,constdevmode* lpinitdata)

                  lpszdriver DC "DISPLAY"

                  When the first argument is "DISPLAY" lpszdevice createdc

                  createdc (TEXT ("DISPLAY"), Null,null,null)

      Span style= "margin:0px; padding:0px; Font-family: Song body; Color:rgb (42,42,42) "> This function hdc type return value, which represents the display device, with this hdc So we can draw on the screen.

      Span style= "margin:0px; padding:0px; Font-family: Song body; Color:rgb (42,42,42) "> Here's another way to get DC getdc

GetDC is window-based and it has only one HWND type parameter, which represents the window you want to draw, because it's easier to use, I don't say much here .

     speaking of which, do you think these two functions are quite simple, but in the use ofCreateDCand theGetDCcreated byDClater,GDIobjects and resources need to be released after use, there is a common pit, I have seen many of the authors on the online technology blog have made this mistake.

There are two functions of releasing a DC

DeleteDC , ReleaseDC

So what difference does it have?

Check out MSDN Remark on both.

     An application must not delete a DC whose handle is obtained bycalling theGetDC function. Instead, it mustcall the ReleaseDCfunction to free the DC.

An applicationcannot Use theReleaseDCFunctionto Release a DC that is created by calling theCreateDCfunction; instead, it must usethe DeleteDC function. ReleaseDC Mustbe called from the same thread that called GetDC.

              in other words: createdc and deletedc paired with getdc and releasedc paired, they can not be replaced, using the wrong way of releasing, this is a beginner, and even a lot of experienced veterans will make mistakes. And in the end, it needs to be noted that relasedc must be in the getdc is called in the same thread.

See here, you may feel that the real details are still a lot of, but these are exactly the logo of a Windows development veteran and rookie, so for us these Windows developers, We need to be aware of the fact that there are a lot of places, and we have to be meticulous about the parameters, meanings and pits of each API , which is probably a pleasure.

Introduction to Windows Client Development (IV)

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.