User interaction with the application

User interaction is best described in terms of various events that trigger the control (based on OS messages about user actions) and which the application responds to (processes). The most commonly used events are the following:

Click – click the left mouse button in the window area;

DoubleClick – two clicks of the left mouse button with an interval less than a certain specified value;

KeyDown – pressing a keyboard key;

KeyPress – pressing and releasing a key, as a result of which a certain character is transferred to the program;

Validating – checking the entered data;

Paint – it is necessary to redraw the client area.

Events from the mouse device, such as Click, DoubleClick, MouseDown, MouseUp, MouseEnter, MouseLeave and MouseHover, are associated with various user actions over the control area.

For the Click and DoubleClick events, a parameter of type EventArgs is passed, and for the MouseDown and MouseUp events, a parameter of type MouseEventArgs is passed, which contains the following useful information(class properties), such as the current coordinates of the cursor in the client area, a description of the button pressed, the number of button presses, the number of clicks when rotating the mouse wheel.

Keyboard events work similarly: number transmitted information depends on the type of event being processed. For example, for the KeyPress event, the event handler is passed a KeyPressEventArgs parameter that contains the KeyChar property, a char value that represents the character of the key pressed.

The Handled property is used to determine whether a given event has been handled. If the Handled property is set to true, then this event will not be sent to the OS for standard processing. The KeyDown or KeyUp events are better suited to handle when you need to get more information about the key pressed, because they receive a KeyEventArgs parameter. The KeyEventArgs parameter includes properties about which Ctrl, Alt, or Shift keys were pressed. The KeyCode property returns a Keys enumeration value that indicates the virtual code of the key pressed. Unlike KeyPressEventArgs.KeyChar, the KeyCode property passes the virtual code of any keyboard key pressed, rather than the alphanumeric character of the key.

The KeyData property returns the value of the Keys enumeration, as well as the state of additional keys. For example, whether the Shift or Ctrl key was pressed. The KeyValue property contains the integer value of the Keys enumeration. The Modifiers property contains Keys values ​​that correspond to the codes of additional keys pressed. If several keys were pressed, they are combined using the OR operation. Events associated with a key are initiated in the following order: 1) KeyDown; 2) KeyPress; 3) KeyUp.



The Validating, Validated, Enter, Leave, GotFocus, and LostFocus events deal with the control gaining input focus (when the control becomes active) or losing focus. This occurs when the user presses the Tab key to navigate to the desired control or selects this element using the mouse. The Enter, Leave, GotFocus, and LostFocus events seem to be very similar in the work they do. The GotFocus and LostFocus events are events more low level, which are associated with WM_SETFOCUS and WM_KILLFOCUS OS messages. It is usually better to use the Enter and Leave events. The Validating and Validated events occur when checking a value in the control. They receive a parameter of type CancelEventArgs. It can be used to abort the following events by setting the Cancel property to true. If the developer sets his own code for checking the entered values ​​and the verification was not successful, then you can set the Cancel property to true and the control will not lose input focus (it will not move to the next control of the form). The Validating event occurs during validation, and the Validated event occurs after validation has completed. These events occur in the following order: 1) Enter; 2) GotFocus; 3) Leave; 4) Validating; 5) Validated; 6) LostFocus.

A typical Windows application contains several forms, which are created using Form class objects. This class is also an control unit and inherits from the base Control class. Some application forms open during operation, others close. At any given moment, one or more forms can be open on the screen; the user can work with one form or switch from one to another while working.

The form opened in the Main() method when the Run() method of the Application class is called is called main form of the application. Its closure leads to the closure of all others forms and shutting down the Windows application. You can also terminate an application programmatically by calling the static Application.Exit() method. Closing other forms does not terminate the project. Usually main application form is always open, while other forms open and close (or hide).

To create a form, the best way (which is done in Visual Studio) create a new class that derives from the Form class. In the class constructor, you can set the required values ​​for the properties of this class and include them in this form all required objects. The example below creates a MyForm class. Objects of this class will correspond to a window that contains the desired controls and handles events associated with the window and controls.

using System.Windows.Forms;

namespace WindowsApp (

static void Main(string args)(

MyForm frm = new MyForm("First window");

Application.Run(frm);

class MyForm:Form(

Button btn1 = new Button();

public MyForm(string s)(

btn1.Top = 10; btn1.Left = 20;

btn1.Text = "Click";

Controls.Add(btn1);

btn1.Click +=new EventHandler(btn1_Click);

As already mentioned, to transfer messages from the application queue to the main form, the Application.Run() method is used, which is passed a reference to the created form object. This method organizes a cycle of sending messages to application forms. It stops working only when a WM_QUIT message arrives in the queue, which arrives when closing the main form window (clicking the button) or selecting a menu command to end work with the application (for example: Quit or Exit).

To display controls on a form, you need to create objects corresponding to them, set the desired values ​​for their properties, and add them to the form's Controls collection. For example:

Button btn1 = new Button();

btn1.Top = 10; btn1.Left = 20; // setting location

btn1.Text = "Click"; // set the text title

Controls.Add(btn1); // adding elements to the collection

For events of interest to users that are triggered by the form and the controls it contains, you need to create event handlers and assign their values ​​to the corresponding events of these objects.

For example, to handle the click event of the button described earlier, an event handler is described that is assigned to a class event variable:

// description of the event handler

public void btn1_Click(object o, EventArgs ea)(

MessageBox.Show("Hello World!");

btn1.Click += new EventHandler(btn1_Click);

The result of this program is shown in Fig. 8.4.

Rice. 8.4. The result of the WindowsApp program.

The main elements of graphic Windows interface are:

  • · Desktop
  • · Icons (Pictograms)
  • · Shortcuts
  • · Taskbar
  • · Context menu
  • · Windows

The desktop is the main area of ​​the screen that appears after you turn on the computer and enter the operating room. Windows system.

Like the surface of a regular table, it serves as a work surface. Running programs and open folders appear on the desktop. You can place various objects, such as files and folders, on your desktop and arrange them in a convenient order. When developing the Windows interface, two main tasks were solved: firstly, to make the work of an inexperienced user as easy as possible, and secondly, to provide experienced users with a set of tools that would allow them to optimally configure the system to work as a separate workstation or to work in local network. All this is true for Windows, adjusted for the fact that the scope of this operating system now includes the Internet.

What appears on the screen after loading the Windows operating system is nothing more than a kind of desk (virtual, of course), on which you can maintain order, but you don’t have to do it - just like in real life. Therefore, such a virtual desk is called a desktop (from the English desktop).

Unlike a regular desk, you can't store objects on your desktop that can do things on their own (like a running clock). To eliminate this drawback, just switch to using the Active Desktop. It provides the user with a number of additional features.

In Windows, icons and shortcuts are located on the desktop. With their help, you can instantly access relevant applications or documents. The desktop is always in front of the user's eyes (unless, of course, it is covered by some application window), so the icons and shortcuts located on it are always available.

After installing Windows, several icons are displayed on the desktop (for example, “My Computer”, “Network Neighborhood” and “Trash”). Using the first two, you can access local, as well as dedicated for sharing on the network to storage devices and printers. By dragging files and folders onto the Trash icon, you can quickly delete them. In addition, the Recycle Bin allows you to recover deleted documents.

Any icon (or shortcut) located on the desktop can be removed from it. The only exceptions to this rule are icons created by the operating system, such as “My Computer”, “Network Neighborhood”, “Trash”. You can place any number of icons and shortcuts on your desktop. Placing an icon or shortcut on the desktop is quite simple if you use the Drag method and Drop. For example, to create an application shortcut or a document icon on the desktop, you need to find the required one using the Explorer program (launched by selecting the command of the same name in the Programs submenu of the start menu). executable file or document and drag the corresponding icon to the desktop (to do this, move the mouse pointer to the icon, press the left button and, without releasing it, move the pointer to the desktop, then release the left mouse button). After this, an icon or shortcut will appear on the desktop (depending on which file you dragged - executable or some other).

By default, the taskbar appears at the bottom of the desktop. By clicking on the Start button on the taskbar, you can open the start menu. The taskbar and start menu allow you to quickly perform actions that you would normally have to take in Windows. They are designed specifically for beginners to help them launch applications and switch between them. However, thanks to its simplicity and power, the taskbar has become popular among advanced users.

Pictograms (Icons) are small pictures that represent programs, files, folders, and other objects. An expressive picture instead of an inscription is understandable to anyone, regardless of their nationality and level of literacy.

An icon or pictogram is a user interface element that is a small picture or image that serves to indicate the hardware and software resources of a computer.

Icons are used to designate various interface objects: desktop, disk devices, printers, programs, documents, etc. Icons corresponding to the most important interface objects or the most frequently used applications and documents are located directly on the desktop surface. The My Computer and Recycle Bin icons are always on the desktop surface. If the computer is connected to a local network, then there is always a “Network Neighborhood” icon on the desktop, which allows you to call up the window for accessing local network resources. And if there is an exit to global network Internet on the table there is always an “Internet” icon for the program to access it. All other icons are placed on the table surface or removed from it according to special instructions from the user.

The taskbar is a long horizontal bar at the bottom of the screen (Figure 2.2). Unlike the desktop, which can be blocked by windows lying on it, the taskbar is almost always visible (in some cases it can be hidden).

The taskbar consists of four main parts.

  • · Start button, which opens the Start menu.
  • · Panel quick launch, allowing you to launch the program with one click of the mouse button.
  • · Middle part which displays open source software and documents
  • · Notification area containing clock and icons (small pictures)

The Start menu (Figure 2.3) is the main means of accessing programs, folders and computer settings. It's called a "menu" because it provides a list of choices, just like a menu in a restaurant. And as the word “Start” implies, this menu is the place where starting or opening items begins.

Use the Start menu to perform the following basic tasks.

  • · Launching programs
  • Opening frequently used folders
  • · Search for files, folders and programs
  • · Configuring computer settings
  • · Getting help using the Windows operating system
  • · Shutting down the computer
  • Log off your Windows session or select account another user

A context menu is a menu that is displayed in a separate window and shows actions that can be performed with selected files, folders or individual elements.

It is called (Figure 2.4), as a rule, by pressing the right mouse button, and its content may change depending on the place where the click was made.

Example, right click on any folder or file:


As you can see, using this menu you can perform simple actions: send, cut, copy, view properties, etc.

The context menu can be supplemented when installing certain programs. For example, after installing the “Avast” antivirus, I now have the “Scan” item, by clicking on which I can check separate folder for viruses.

Now try pressing the right button in any free space, any window:


As you can see, the menu is different from the previous one. Here we have nothing to copy or rename, because we did not select a specific object. But now we can create it, customize its appearance, sort it, etc. Please note that items with an arrow on the right call up an additional menu.

The main thing is not to be afraid to experiment, if you can always restore something previous settings in the same way.

Don't forget that the context menu can be called up almost anywhere, both in the system and in any individual program.

Working with Windows

Opened programs, files or folders appear on the screen in fields or frames - windows (it is from them that the Windows operating system gets its name). Since windows are everywhere in Windows, it's important to learn how to move them, resize them, or simply remove them.

A window is an area of ​​the screen delimited by a rectangular frame. It displays the contents of a folder, a running program or document.

Main window elements (Figure 2.6).


  • · work area: the inner part of the window in which you work with disks, files and documents;
  • · window title: a line below the top border of the window containing the name of the window;
  • · window state control menu: the button in the title bar on the left opens a menu that allows you to expand, collapse or close the window;
  • · window state control buttons: buttons in the title bar on the right allow you to expand, collapse or close the window;
  • · window menu: located under the title and is a list of thematically grouped commands;
  • · toolbar: located below the menu bar and is a set of buttons that provide quick access to the most important and frequently used window menu items;
  • · borders: a frame that encloses a window on four sides. The window can be resized by grabbing and moving the border with the mouse;
  • · scroll bars: appear if the window contents are larger than the window's working area; they allow you to move the window contents vertically or horizontally.

There are three options for displaying a window on the screen:

  • · a standard size window takes up part of the screen area. If desired, you can move it or any of its borders to another location on the screen
  • · a window maximized to full screen has maximum size
  • · a minimized window is displayed as a button on the taskbar.

The program continues to run in the minimized window. To open a minimized window or minimize an already open one, click the window button on the taskbar.

Windows can be classified by type:

  • · folder window
  • document window
  • · program window

Dialog boxes.

Dialog panels can include several tabs, which can be switched between by clicking on their names. The dialog panel contains various control elements:

  • · tabs - “pages” of a dialog box
  • · command button - ensures the execution of a particular action, and the inscription on the button explains its purpose;
  • · text field - you can enter a sequence of characters into it;
  • · drop-down list - is a set of values ​​and looks like a text field equipped with a button with a downward arrow;
  • · counter - is a pair of arrows that allow you to increase or decrease the value in the field associated with them;
  • · checkbox - provides assignment of a specific value to any parameter. Flags can be placed either in groups or individually. The checkbox has the shape of a square; when the checkbox is checked, there is a “tick” in it;
  • · switch - serves to select one of the mutually exclusive options; the selection options are presented in the form of small white circles. The selected option is indicated by a circle with a dot inside;
  • · slider - allows you to smoothly change the value of any parameter.

Lesson #12.
Topic: "Windows Graphical Interface".
Lesson objectives:

- help students understand the concept of a graphical interface, control methods in Windows, and give the basic concepts necessary to work on a computer.
- upbringing information culture students, attentiveness, accuracy, discipline, perseverance.
- development of cognitive interests, skills in working with a mouse and keyboard, self-control, and note-taking skills.

Equipment:
board, computer, computer presentation.

Lesson plan:
I. Org. moment. (1 min)
II. Testing and updating knowledge. (2 min)
III. Theoretical part. (12 min)
IV. Practical part. (16 min)
V. D/z (2 min)
VI. Questions from students. (5 min)
VII. Lesson summary. (2 min)

Lesson progress:
I. Org. moment.

Greeting, checking those present. Explanation of the lesson.

II. Updating knowledge.
Currently, all operating systems for personal computers provide user interaction using GUI.

This allows even a novice computer user to work confidently in the operating system environment (perform file operations, run programs, and so on).

In this lesson we will look at how to manage this most important and complex program, i.e. Windows OS.

III. Theoretical part.

A graphical interface allows a person to interact with a computer in the form of a dialogue using windows, menus and controls (dialogue panels, buttons, and so on).
The interface is an intermediary, a translator, whose task is to transform all the internal “control levers” of Windows into a graphical form that people can understand. One can endlessly argue about the numerous shortcomings and shortcomings in certain elements of the Windows interface. You can, shaking dusty historical reference books, prove that Microsoft simply copied all the best things contained in it from its competitors - Unix, MacOS, Linux, OS/2... But why? In any case, what we see during a session with Windows looks not only logical and convenient, but in some cases it is also simply beautiful!

The Windows interface is simple and accessible, and almost everyone can solve almost all of its riddles.

To work with the graphical interface, a mouse or other coordinate input device is used, and the user must be able to:
left click - pressing and releasing the main (usually left) mouse button once;
right click - single press and release of an additional (usually right) mouse button;
double click - two clicks of the main mouse button with a minimum time interval between them;
dragging (dragging) - pressing the left or right mouse button and moving an object with the button pressed.

Windows GUI Elements :
Desk.
The name “Desktop” was chosen well. On it, like on a regular desktop, there are various programs and tools presented in the form of icons or icons.
Icons.
Icons in Windows represent programs and documents. Launch is done by double-clicking on the icon. The program can be located directly on the Desktop, or it can be hidden deep on the disk, but even in this case it is presented on the Desktop in its own way - a shortcut.
Labels.
A program shortcut is not the program itself, but only its image, an indication of the place on the disk where it is located. Double-clicking the shortcut also launches the program. Labels differ from icons by having a small arrow at the bottom left.
Taskbar.
Located at the bottom of the screen. It contains: the Start button, buttons for open windows, indicators and a clock.
Window.
A window is one of the main elements of the Windows interface.

Desk. How to find the Desktop? - many novice users ask. No way. In the sense that it is simply impossible not to find a desktop. For everything you see on your screen after Windows startup- that’s what he is.

The name “Desktop” was chosen extremely well. On their regular desktop, people keep all the tools, documents, and so on they need. On virtual work Windows desktop The most necessary programs and tools are also collected, presented in the form of icons.

There are only a few small icons on our desktop so far. Some of them look like rectangular yellow folders, some are indicated by other pictures. Some have an arrow icon in the lower left corner, others don’t... It’s easy to get confused.

In addition to icons, the Desktop can contain windows, a context menu, and much more.

Badges . Both programs and documents are indicated by similar icons. By clicking on any of them, you can launch the program you need and immediately open a document in it. It's simple - sit back and click on the icons!

The icon corresponds to one file - a document or program. A program often consists of several hundred files, but Microsoft believes (with good reason) that the user does not need to see all of them. One thing is enough - the file that launches the program. And this is often reasonable.

Document icons replace file extensions. So in the icon caption you will only see the file name.
Each program installed on Windows has its own, original icon. And this icon, as a rule, is present to one degree or another in the icon of a document created using this program. This way, by looking at the icon, you will always know which file type it corresponds to.

An icon can represent not only a file, but also a folder. Or a catalog, or a directory - whatever you are used to. By clicking on it with the left mouse button, you can open the folder in the form of a window. In this case, all files living in this folder will be represented by a kind of “portrait gallery” - a row of icons with captions.
By clicking on the program icon, you give a command to execute it - as computer scientists say, “run”.

You can rename any icons, move from folder to folder, delete or copy using the mouse. However, remember that any operations on icons are operations on the original program files or document. By deleting an icon from the Desktop or from any folder, you thereby physically delete the file from the disk - and this is worth doing only if you are absolutely sure that the need for this action.

Shortcuts . There are, however, other types of icons, any operations with which will not affect the original files in any way - shortcuts. These icons differ from regular ones by having a small black arrow in the lower left corner.

Translating the English term shortcut into the word “shortcut” is not entirely successful. It would be more accurate to say “pointer”, since this very shortcut on the Desktop, pointing to a file located in another location, serves as its shadow, reflection.

The fact is that, despite all the colorfulness and novelty of the Windows graphical interface, underneath it hides the usual, familiar to us all, “directory tree” structure. Each program is in its own directory. And our Desktop is, in fact, a real catalog.

What happens if we want to mark some program on our Desktop, for example, Microsoft Word? The program is launched by the winword.exe file, which is located along with other Word files in the C:\Program Files\Microsoft Office\Office\ folder. And you cannot move the file to any other folder, including the Desktop - the program will not work... But you can create a pointer on the Desktop - a shortcut! This icon will differ from the icon of the program itself only with an arrow in the corner, but it will provide the user with truly unlimited possibilities! The icon can be safely renamed or deleted without fear for the fate of the program or document itself - with any changes they will remain in good health.
Shortcuts do not require the presence of the program itself in the folder where we will place this shortcut. Inside the shortcut is not the program itself, but only a link containing the exact address of the program.

For quick access to disks, the printer, and frequently used documents, it is advisable to create shortcuts on the desktop. A shortcut differs from an icon in that it represents an object that is actually located not on the Desktop, but in some other folder. The arrow means that we do not have the object itself, but a link to it. Shortcuts are created by dragging object icons onto the desktop.

Taskbar. At the bottom of the screen is the Taskbar, which contains the Start button, buttons for running tasks and open folders, indicators and a clock. The Start button allows you to call the Main Menu, which provides access to almost all system resources and contains commands for launching applications, setting up the system, searching for files and documents, accessing help system etc.

Windows is a multitasking operating system, meaning multiple applications can run in parallel. Each running application is indicated by a button on the taskbar, and the transition from working in one application to working in another can be done by clicking on the button. A running (active) application is displayed on the taskbar as a pressed button.

You can display different panels on the taskbar. On the far right side of the taskbar is the language bar, which allows you to select your input language. For example, the Ru indicator indicates that the Russian keyboard layout is currently being used.
The notification area (tray) is used to display icons for some programs related to the operation of the computer. To avoid cluttering the taskbar, an arrow button may be visible instead of icons for rarely used items presented in the notification area. To display all icons, click this button.
The digital clock on the taskbar shows the current time. To see the current date, month and year, just move your mouse pointer over the clock.

Windows . The most important element of the Windows graphical interface is windows, indeed “windows” means “windows”. There are two main types of windows - application windows and document windows.
A window is a framed portion of the screen that displays an application, document, or message.
Application windows. The application window runs any running application or displays the contents of a folder. Opening or closing an application window is the same as launching or ending a program. Application windows can be moved to any place on the desktop, maximized to fill the entire screen, or minimized to buttons on the taskbar.

The main elements of the application window are :
workspace: the inner part of the window, contains subfolders or document windows;
border: a frame that encloses a window on four sides. The window size can be changed by moving the border with the mouse;
title: the line immediately below the top border of the window containing the title of the window;
system menu icon: the button on the left in the title bar opens a menu for moving and resizing the window;
menu bar: located directly below the header, contains menu items, provides access to commands;
toolbar: located below the menu bar, it is a set of buttons that provides quick access to some commands;
the Collapse, Maximize/Restore, and Close buttons are located in the upper right part of the window.
scroll bars. If the text or picture does not completely fit in the program window, then to view it, scroll bars appear at the bottom or on the right, which can be moved, revealing areas that do not fit on the screen.

Document windows. Document windows are designed for working with documents and “live” inside application windows. You can expand, collapse, move, or resize these windows, but they always remain within their application window. The document window has the same control buttons as the application window.

A document window contains a title area (containing the name of the document) and often scroll bars (appearing when the document does not fit entirely in the window) and rulers.

A window is active (current) if the user is currently working with it. Otherwise the window will be passive (in a passive state). If the window is in a passive state (the title area is not highlighted), then by clicking on any part of it with the mouse, you can switch it to the active state.

A menu is one of the main elements of a graphical interface and is a list of commands (usually grouped thematically) from which you need to make a choice (by placing the mouse pointer on the menu item and clicking). Selecting a menu item causes a specific command to be executed. If a menu command is followed by an ellipsis, selecting it will cause a dialog box to appear that allows the user to obtain or enter additional information.

Questions:
What is a graphical user interface?
How is control done in Windows?
What actions can you perform with the mouse?
List the elements of the Windows GUI.
What is a desktop?
What is the difference between icons and labels?
How to access all programs installed on your computer and all Windows settings?
Where is the digital clock?
How to switch input language using mouse?
How to find out the current date?
List the main elements of a window.

III. Practical part.

Today in the practical part we will continue working with the Notepad program and learn how to copy and move text. For these purposes we will use the clipboard. The clipboard is an area of ​​RAM designed to temporarily store data when transferred from one place to another. This memory is allocated to us by the operating system.

To place some data on the clipboard, you must first select it. You can select text in Notepad in different ways, For example:
while holding down the button, move through the text using the arrow buttons;
select text while holding down the left (main) mouse button;
to select multiple parts of text, select them with the mouse while holding down the button on the keyboard;
To select all the text, use the Edit command→ Select all;
To select all text, you can use the special key combination +[A]…

To remove a selection, simply click the left mouse button anywhere in the text or press any cursor key without pressing .

But what to do after the text is selected? Let's go to Notepad's help system and find information about copying text. Students work with help...
To cut, copy, paste or delete text:
To cut a piece of text to move to another location, select the text you want, and then choose Cut from the Edit menu.
To copy a piece of text to paste it elsewhere, select the text you want, and then choose Copy from the Edit menu.
To paste copied or cut text, place the cursor where you want to paste it, and then choose Paste from the Edit menu.
To delete text, select it and select Delete from the Edit menu.

And now the task: a certain student Ivan Ivanov memorized a poem by A.S. for a literature lesson. Pushkin’s “Winter Morning”, but during the lesson I got confused and mixed up all the lines. Help Ivanov remember the poem.
File with the verse (with mixed up lines) – C:\Our lesson\Lesson 12 Practice.txt. Save the result of your work in your folder under the name “Winter Morning”.
Students complete the task.

IV. D/z
Know the elements of the Windows graphical interface, be able to work with windows. Students who have computers at home should continue to master the “ten-finger touch typing method.”

Additional task: learn how you can create an additional panel with shortcuts to the programs you frequently use.

V. Questions from students.
Answers to student questions.

VI. Lesson summary.
Summing up the lesson. Grading.
In this lesson we looked at the elements of the Windows graphical interface. We also learned how to move some text using the Windows clipboard.

Structure Windows applications

The program consists of several clearly marked blocks (sections):

  • preprocessor operator groups;
  • section of prototypes of applied functions used in the program;
  • main function WinMain();
  • window function of the main window.

Let's consider these blocks sequentially.

The program begins with two #include preprocessor directives, with the help of which header files are included in the program. As already noted, the WINDOWS.H header file (as well as a whole group of additional header files included “from inside” the WINDOWS.H file) ensures that the compiler understands the meaning of types Windows data, constants and macros and connecting this file to the source text of the program is mandatory. Some of the definitions used in programs (for example, the GetStockBrush() macro and others similar to it, or the HANDLE_MSG macro, which will be discussed below) are contained in the WINDOWSX.H file, which also must be included in almost all Windows applications.

Following the preprocessor operators in our example is the prototype section, where the prototype of the only application function in this program, WndProc(), is defined. In fact, the program must contain prototypes of all functions used, both applied and system. We have quite a lot of calls to Windows system functions: RegisterClass(), CreateWindowQ, GetMessage(), etc. However, the prototypes of all these functions are already defined in the header files of the programming system. Thus, the prototype of the WinMain() function is described in the WINBASE.H file:

Int WINAPI WinMain(
HINSTANCE hlnstance,//Handle to the current application instance
HINSTANCE hPrevInstance,//Descriptor of the previous application instance
LPSTR lpszCmdLine,//Pointer to parameters command line
int nCmdShow//Constant characterizing the initial view of the window
) ;

It's easy to see that the WinMain() function header in our program exactly matches the prototype above (except that we've omitted unused parameters). It cannot be otherwise. It is enough to change even a little the characteristics of our WinMain() function, and the program will either not go through the compilation stage, or will not be loaded for execution, or will be loaded but will not work.

The prototypes of the remaining Windows functions used in the program are defined in the file WINUSER.H. This way you don't have to worry about prototyping Windows functions. The situation is different with the window function WndProc(). This is an application function, its name can be anything, and the programming system does not know this name. Moreover, 120 Win32. Programming Basics When an application has multiple windows (and this is almost always the case), the program describes several window functions, one for each window class. For all window functions used in the program, their prototypes must be specified.

On the other hand, the format of a window function, that is, the number and types of input parameters of the function, as well as the type of value it returns, are determined by the Windows system and cannot be arbitrarily changed. Indeed, the window function is called from Windows when a message arrives at the application. When it is called, Windows passes it a very specific list of parameters, and the function must be able to accept these parameters and work with them. Therefore, in the interactive reference book of the programming system, a template is given for a window function, which in appearance is very similar to the prototype, but is not a prototype of a specific function, but a template for the application programmer:

LRESULT CALLBACK WindowProc(
HWND hwnd,//Window handle
UINT uMsg, 11 Message code
WPARAM wParam, //First parameter of the message
LPARAM lParam //Second message parameter
) ;

Again you can see that our window function, having a different name, exactly matches the above template: it takes 4 parameters specified types and returns (on Windows) a result of type LRESULT. In addition, it is declared with the CALLBACK specifier. What does this descriptor mean?

In the WINDEF.H file, the symbolic notation CALLBACK is declared to be equivalent to keyword the C++ stdcall language, which defines the rules for the interaction of functions with calling procedures. In Win32, almost all functions use the so-called standard calling convention. This convention specifies that when a function is called, its parameters are pushed onto the stack in such an order that the last parameter is at the bottom of the stack and the first at the top. The function itself, of course, knows about this arrangement of its parameters and selects them from the stack in the correct order. For 16-bit Windows functions, the Pascal language convention is that the order in which parameters are pushed onto the stack is reversed.

Interface element- a graphical user interface primitive that has a standard appearance and performing standard actions.

Other names: control (control), control And widget(English) widget).

Windows GUI

Currently, all operating systems for personal computers provide user interaction using a graphical interface.

This allows even a novice computer user to work confidently in the operating system environment (perform file operations, run programs, and so on).

Graphical interface allows human interaction with a computer in the form of a dialogue using windows, menus and controls (dialog panels, buttons, etc.).

Working with the mouse. To work with the graphical interface, a mouse or other coordinate input device is used, and the user must be able to:

    left click - single click and release of the main (usually left) mouse button;

    right click- single click and release of the additional (usually right) mouse button;

    double click- two clicks of the main mouse button with a minimum time interval between them;

    drag and drop- pressing the left or right mouse button and moving the object with the button pressed.

Desk. The main part of the screen is occupied Desk, on which they are located icons And shortcuts(icons with small arrows in the lower left corner). Icons and shortcuts provide quick, double-click access to drives, folders, documents, apps, and devices.

Icons appear on Desktop after installing Windows. There are usually icons on the left side of the screen My Computer, Network Places, Recycle Bin And My documents.

For quick access to disks, the printer, and frequently used documents, it is advisable to create shortcuts on the desktop. A shortcut differs from an icon in that it represents an object that is not actually located on Desktop, but in some other folder. The arrow means that we do not have the object itself, but a link to it. Shortcuts are created by dragging object icons onto Desk.

Introducing the Windows GUI

1. Create on Desktop shortcuts to all disks, printer and scanner.

Create shortcuts to frequently used applications and documents.

Windows application structure

Windows application structure

The model for generating and passing messages will help you understand the structure adopted for all Windows applications. The last two blocks in the considered diagram (Fig. 3.1) determine the structural features of any Windows application. The simplest of them should consist of at least two functions:

    the winMain function, with which program execution begins and which “winds up” the message waiting loop (message pump);

    a window procedure that the system calls, sending it appropriate messages.

Each application in a message-based system must be able to receive and process messages from its queue. The basis of such an application in Windows is the winMain function, which contains a standard sequence of actions. However, most messages are processed by the window, an object of the Windows operating system.

Note

From the user's point of view, a window is a rectangular area of ​​the screen corresponding to some application or part of it. You know that an application can manage several windows, among which there is usually one main frame window (Frame Window). From the operating system's point of view, the window is in most cases the final destination to which messages are sent. From a programmer's point of view, a window is an object whose attributes (type, size, position on the screen, cursor type, menu, icon, title) must first be generated and then registered by the system. Window manipulation is carried out through a special window function, which has a well-defined, established structure.

The winMain function is executed first in any application. Its name is reserved by the operating system. In this sense it is analogous main functions, from which the execution of a C program for the DOS platform begins. The name of the window procedure is arbitrary and chosen by the developer. Windows registers this name and associates it with the application. The main purpose of the winMain function is to register a window class, create a window, and start a message loop.

Taskbar. At the bottom of the screen is Taskbar, on which the button is located Start, buttons for running tasks and open folders, indicators and a clock.

Button Start allows you to call Main menu, which provides access to almost all system resources and contains commands for launching applications, setting up the system, searching for files and documents, accessing the help system, etc.

Windows is multitasking operating system, that is, several applications can be executed in parallel. Each running application is indicated by a button on Taskbars, while switching from working in one application to working in another can be done by clicking on a button. A running (active) application is displayed on the taskbar as a pressed button.

On the far right Taskbars are Watch. To the left of the clock are system status indicators. For example, the indicator Ru indicates that the Russian keyboard layout is currently in use.

3. Left-click to open the indicator and switch to the English layout, and right-click to open the dialog panel Properties and select the required combination of keystrokes on the keyboard to switch layouts.

Windows. The most important element of the Windows graphical interface is windows; indeed, “windows” means “windows” in translation. There are two main types of windows - application windows And document windows.

Application windows. The application window runs any running application or displays the contents of a folder. Opening or closing an application window is the same as launching or ending a program. Application windows can be moved to any location Desktop, expand to full screen or minimize to buttons on the taskbar.

The main elements of the application window are:

    work area: the inner part of the window, contains subfolders or document windows;

    borders: frame bordering the window on four sides. The window size can be changed by moving the border with the mouse;

    title: a line directly below the top border of the window containing the window title;

    system menu icon: the button on the left in the title bar opens a menu for moving and resizing the window;

    line horizontal menu: located directly below the header, contains menu items, provides access to commands;

    toolbar: located below the menu bar, it is a set of buttons that provides quick access to some commands;

    buttons Collapse, Maximize/Restore, Close located in the upper right part of the window.

Document windows. Document windows are designed for working with documents and “live” inside application windows. You can expand, collapse, move, or resize these windows, but they always remain within their application window. The document window has the same control buttons as the application window.

A document window always contains a title bar (containing the name of the document) and often scroll bars (appearing when the document does not fit completely in the window) and rulers. The open document window may be in active or in a passive state. If the window is in a passive state (the title area is not highlighted), then by clicking on any part of it with the mouse, you can switch it to the active state.

4. After launching the Word application, its window will appear on Desktop. If you open two documents in Word, the windows of the two documents will appear in the application window. One window can be maximized and active, the other can be minimized and passive.

Menu. A menu is one of the main elements of a graphical interface and is a list of commands (usually grouped thematically) from which you need to make a choice (by placing the mouse pointer on the menu item and clicking). Selecting a menu item causes a specific command to be executed. If a menu command is followed by an ellipsis, selecting it will cause a dialog box to appear that allows the user to obtain or enter additional information.

Dialog panels. Dialog panels can include a variety of elements. Let's look at the capabilities of dialog panels using the example of refining file search parameters.

Tabs. Dialog panels can include multiple "pages" called tabs.

5. After entering the [Find-Files and Folders...] command, a dialog box will appear Find: All files. This panel contains three tabs: Name and Location, Date, More. Select a tab by left clicking.

Command buttons. Pressing a button (click) performs one or another action, and the inscription on the button explains its purpose. So, click on the button that says Find allows you to begin the search process.

Text fields. The text field is sometimes called edit field and allows you to enter some text information.

6. For example, if the user wants to find files containing the word "computer science", then it must be entered in the text field Search text: tabs Name and location dialog panel Find: All files.

To do this, left-click in the field and enter text.

Lists. The list is a set of values ​​offered for selection. Dropdown list looks like a text field with a button with a downward arrow. The list is expanded by left clicking on the button.

7. Dropdown list Where to look: dialog panel Find: All files allows you to specify a drive or folder (for example, a folder My documents) in which the search will be carried out.

Switches. The switches are used to select one of mutually exclusive options; the options are presented in the form of small white circles. The selected option is indicated by a circle with a dot inside. Select an option by left clicking.

8. So, on the tab Date dialog panel Find: All files There are two switches: the main one (for two options) and the additional one (for three options). While searching for files, set the main switch to Find all files, and the additional one is in position between, you can limit the search area to the period of file changes (in this case, from 09/14/99 to 12/13/99).

Flags. A checkbox allows you to assign a specific value to a parameter. Flags can be placed either in groups or individually. The checkbox is shaped like a square; When a checkbox is checked, there is a "tick" in it. Checkboxes can be selected by left clicking.

9. On the tab Name and location dialog panel Find: All files by checking the box Including subfolders, you can provide the required depth of file search.

Counters. The counter is a pair of arrows that allow you to increase or decrease the value in the associated field. So, when searching for a file on the tab Date dialog panel Find: All files the values ​​of the fields that specify the file modification period can be changed using counters. To increase the corresponding value, click on the arrow pointing to the right, and to decrease it, click on the arrow pointing to the left.

Sliders. The slider allows you to smoothly change the value of any parameter. For example, using the sliders you can change the volume level of audio playback and recording, the balance of the left and right channels, etc.

10. After double clicking on the volume indicator, which is located on Taskbars, a dialog box will appear Volume control with volume and channel balance sliders.

Context menus. The object-oriented approach used in the Windows operating system allows drives, folders, and files to be treated as objects. All these objects have certain properties, and certain operations can be performed on them.

For example, documents (a document is any file processed using applications) have a certain volume and can be copied, moved and renamed; windows have a size that can be changed and so on.

Although each of these objects has its own specific properties and certain operations are possible on it, the technology for working with objects and the interface are universal. This allows the user to achieve consistency when working with different objects.

You can get acquainted with the properties of an object, as well as perform permitted operations on it using context menu. To call the context menu, you need to right-click on the object icon.

11. In order to familiarize yourself with the properties of the disk, you need to select the item in the context menu Properties - a dialog panel will appear Properties: Disc 3.5 (A). The panel contains four tabs: General, Service, Equipment, Access. On the tab General contains information about the type of file system, total, free and occupied information capacity of the disk, etc.

Built-in object Windows models, object models Windows Script Host (WSH), Scripting Runtime, ADO, SQLDMO, CDO, WMI, ADSI, Windows Explorer, Internet Explorer Collections of objects that are designed to perform tasks related to one area are called object models. For example, the Excel object model provides objects that represent the Excel application, workbook, individual sheets on that workbook, sets of cells, charts, etc. The last part of this book examines in detail the object models of Microsoft Office applications: Word, Excel, Access, PowerPoint, Project, Outlook. However, when programming in VBA and creating your own applications, you are limited to object models only Office applications not at all necessary. There are many other object models built into the Windows operating system that can greatly enhance the capabilities of your applications. Below is a list of additional object models that are built into Windows or other Microsoft products (this will be discussed separately) that I use very actively. Help for most of these object models can be found on MSDN. To use the capabilities of these object models in your program, you need to add a reference to it in your project. This is done very simply: in the Visual Basic editor window, select Tools -> References and select the desired library.

Object model Microsoft Word

The general structure of Word objects looks as shown in Fig. 10.1.

Rice. 10.1 This is what the main Word objects look like

But you shouldn’t be scared at all - you will never need most of these hundreds of objects. In practice, to solve most software problems, it is enough to know only five objects (with accompanying collections):

    object Application;

    object Document(with collection Documents);

    object Selection;

    object Range;

    object Bookmark(with collection Bookmarks).

    Since the most common programming task in Word is creating a document (based on a template) and recording the necessary information in the right place in the document, the emphasis will be on using appropriate objects to solve this task.


Close