API Introduction Series VI-Self implementation messagebox

Source: Internet
Author: User
Tags implement

I am in the fourth article: a fairly simple SDK program says that by calling the Messageboxapi function to pop up a dialog box, do you have any idea what the details behind our simple code are? It's a little early to let you know, but now it's time to Using some basic API function calls to implement a own dialog box is not very difficult, then this article is the purpose. In passing, we introduce some basic API applications, because of the first five articles of the foreshadowing, I believe that you have the SDK program of the approximate structure and related character processing have some understanding, so in this article of knowledge, I will not say more, lest some people think I really too wordy. Really puzzled, can refer to the previous article.

First, I'll make a general list of some of the API functions we're going to use to complete this task.

SetWindowText set the title of the window

GetClientRect Gets the size information of the client area of the window

Getwindowlongptr through window handles to the window and the associated information

CreateWindowEx Create a window

BeginPaint get the device handle of the window

EndPaint the device handle of the release window

DrawText text on a window by using a device handle

Well, with these functions, we can implement a simple dialog box that has a OK button and a hint on the top of the button, but this dialog box is a code of our own to realize yo ~ ~ or a more fulfilling sense of it ~

The general framework of the program or the framework in our previous article, register the window class, create a main window, a message loop, a window message handler function. But we need to add some code to the window message handler function to complete the functionality we need.  Where do you add it? Last program, we only deal with Wm_destroy this message. For this message I no longer explain, do not understand or forget to MSDN or to see an article, here we want to add to two messages processing code, first is wm_create, this message will be created when a window is sent to the window message handler function, If something needs to be done when a window is just created, it's best to deal with the Wm_create code as follows:

Case WM_CREATE:

{

RECT rctclient; Used to store the main window client area size information

const int buttonwidth = 80; Width of the button

const int buttonheight = 25; /Button's high

GetClientRect (hwnd, &rctclient); Get size information for main window client area

HINSTANCE hinst = (hinstance) getwindowlongptr (hwnd, gwlp_hinstance);

HWND Hbutton = CreateWindowEx (0L, _t ("button"), _t ("OK"), ws_visible | Ws_child, RCTCLIENT.RIGHT/2-BUTTONWIDTH/2, rctclient.bottom/2-buttonheight/2, Buttonwidth, ButtonHeight, hwnd, ( HMENU) 2, hinst, NULL);

SetWindowText (hwnd, _t ("Custom dialog Box"));

Break

}

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.