Windows Development Notepad Program (a) interface article _ Related skills

Source: Internet
Author: User
Tags win32

Objective

Learn Windows UI programming from graduation and work with some APIs, but never a complete interface program. So plan to use your free time to do a small project to sum up what you have learned. Seeing a lot of people on the web suggesting that you can do a complete project quickly, you're going to start with a copy of the Windows Notepad and really implement a basic Windows interface program. Considering that writing a complete Windows Notepad program requires a lot of work, it is intended to record each phase of the results, on the one hand can help you to summarize, review the knowledge learned, on the other hand, can also discuss with other netizens, so that we can progress together in the discussion.

This section describes

As the title of this article shows, this section mainly implements the main interface design of Notepad, including the construction of the main interface window, the addition of the menu. Although these are basic operations, you still want to keep these basic steps fully documented for subsequent validation. The development environment of this paper is as follows: The system is Win7 64bit, IED is VS2008. Okay, no more nonsense, direct START process introduction:

1. New Win32 Project

This article uses Windows API to implement a simple Notepad program, so select Windows Application when you create the project, as shown in Figure 1. At the same time, in order to facilitate, choose to start with an empty project, what additional resources will be added to the subsequent process.

Figure 1 New Win32 Empty Project

2. Building the main interface

When you open a Notepad program with Windows, you can see that the entire window is a dialog box with menus and edit controls, so this article is designed to facilitate the dialogbox of the entire program's main interface in a straightforward way. The concrete practice is shown in Figure 2 below: Resource files–> add–> Resource ...:

Figure 2 Creating a new dialog box resource

After the resource window in Figure 2 is open, select the dialog resource and add it. At this point, you get a system default dialog box, as shown in Figure 3:

Figure 3 System Default dialog box

At this point, you need to switch the view to a resource view to operate. The first name for the dialog box, a meaningful variable name makes the program more readable and easier to maintain later. The dialog resource name is therefore changed to Idd_main. The OK and Cancel buttons do not exist in Notepad, so the two buttons are selected directly in the dialog box and deleted. The effect is as shown in Figure 4:

Figure 4 The Main interface dialog box renamed, remove the extra button after the effect

3. Build Menu

When you build a menu, the first step is consistent with the build main interface. Select the menu in the resource addition in Figure 2 and select New. The new menu resource default name is IDR_MENU1. The same changes to its name operation, changed to Idr_menu. Later, the fill of the menu item is made. The main thing here is to follow the corresponding text in Windows Notepad can be, the main existence of the following two small details to note:

3.1-Letter Shortcuts

In Windows Notepad, you can invoke the appropriate menu item by using a shortcut key (for example, when you open Notepad, you can open the file option with Alt+f, as shown in Figure 5).

Figure 5 Windows menu shortcut keys

The practice here is actually very simple, is to add the letter before the corresponding letters, such as "File (F)" is filled out as "file (&f)", so you can open shortcut keys by default. The settings for the open, save, and so on shortcuts below the file option are also added & before the corresponding letters.

3.1 Constructing the drop down split line

In the file Drop-down menu in Figure 5, you can see the split line that splits the Save As and page Setup. So how to produce this with the split, in fact, it is also very simple, directly in the corresponding menu item right, select "Insert Separator", as shown in Figure 6 (because my machine VS2008 is the English version of the menu items shown in English, for Chinese vs should be able to find in the same place " Insert style line option bar):

Figure 6 Adding a menu option split line

4. Adjust the main interface

In the main program, it is only to display the effect of the current interface, so the Idd_main is displayed directly with DialogBox. The code is as follows:

/************************************************************************/
/* File  : main.cpp The main portal for the entire application
 * Author:huagang Li
 * Date  : 2014-8-29 23:22:37
 * blogs:http://www.cnblogs.com/lhglihuagang/*
 *
/************************************************************************/

#include <Windows.h>
#include "resource.h"  //Idd_main defined position

int WINAPI WinMain (__in hinstance hinstance, __in_opt hinstance hPrevInstance, __in_opt LPSTR lpcmdline, __in int nshowcmd)
{
  ::D ialogbox (hinstance, Makeintresource (idd_ MAIN), NULL, NULL;
  return exit_success;
}

Because the window procedure function in dialog is set directly to NULL because the window cannot be turned off by turning off the key after it is opened (can be closed with Resource manager), the current effect is as follows 7:

Figure 7 the wrong output?

As you can see from Figure 7 above, just a blank window, OK menu options? What about the maximum minimized button? Window size is not variable?? Here's another note: When you create a new menu resource and edit it, the resource only exists in the engineering file and is not added to any of the windows. Therefore, we need to add the menu resources to the Idd_main window. At the same time, the system defaults to the New dialog box window is not the largest minimum button, so you need to idd_main in the properties of the adjustment, the following actions:

4.1 Add menu, Maximize minimize button

Select "Idr_menu" in Idd_main's "Properties" menu and set Minimize box and Maxmize box to true. The operation is shown in Figure 8 below:

Figure 8 Add menu, max, min button

4.2 Window size can be adjusted

Idd_main's "Properties" Boader Select "Resizing", which is to set the properties of the border to be adjustable, as shown in Figure 9 below:

Figure 9 dialog box size variable

Interface effect

After adding a menu, a maximum minimum button, and modifying the border-adjusting property, the entire program runs the main screen as shown in Figure 10:

Figure 10 Program UI Effects

Conclusion

Although the true logic function has not yet been developed, it has been a while before the implementation of this interface. Even such a simple interface display program can also learn a little bit of knowledge:

1. Menu Letter Shortcuts (add & before letters)

2. Menu pull down split Line (right-click to add split line)

3. The new menu resource needs to be added to the window to display (menu selection in the Idd_main property idr_menu)

Description

This will be a series of posts, followed by the steps to complement the development of the logical features. Hope to be able to communicate with more Bo friends.

If you think this article can also, please point to praise, haha ~ ~

Statement: No explanation, then the article for the original cake. NOTE: Reprint must retain the full text, if need to modify, please contact the author.

Related Article

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.