Introduction to windows programming

Introduction to 64 Bit Windows Assembly Programming. Seyfarth,Ray

This book introduces programmers to 64 bit Intel assembly language using the Microsoft Windows operating system. The book also discusses how to use the free integrated development environment, ebe, designed by the author specifically to meet the needs of assembly language programmers. Ebe is a C++ program which uses the Qt library to implement a GUI environment consisting of a source window, a data window, a register window, a floating point register window, a backtrace window, a console window, a terminal window, a project window and a pair of teaching tools called the «Toy Box» and the «Bit Bucket». The source window includes a full-featured text editor with convenient controls for assembling, linking and debugging a program. The project facility allows a program to be built from C source code files and assembly source files. Assembly is performed automatically using the yasm assembler and linking is performed with ld or gcc.

Если вам понравилась эта книга поделитесь ею с друзьями, тем самым вы помогаете нам развиваться и добавлять всё больше интересных и нужным вам книг!

Cхожие Книги

Программирование на языке Ассемблера М.Ю. Смоленцев

    Программирование на языке ассемблера IBM PC. В. Н. Пильщиков

    Программирование на Ассемблере для PIC. Носов

    Introduction to windows programming

    WinMain is called by the system when our program is first run. It’s the starting point of our application. The first parameter is the handle to the instance of our application. The second parameter will always be NULL for our purposes. The third parameter is a string pointer to the command line. The last parameter specifies a show state (there are several values that start with «SW_» that you can look up in the help files). We will look at the other initialization code in a moment, but take a look at the while block. GetMessage gets a message from our thread’s message queue and puts it into our MSG variable. The only time GetMessage returns 0 is when it receives a WM_QUIT message. You can use GetLastError to get error information if GetMessage returns an error (-1). Otherwise its return will be non-zero. The GetMessage parameters provided say that we want to retrieve any type of message available. The message is received into the msg variable which is then used by TranslateMessage to translate special keyboard messages into messages that are sent to the thread’s message queue (you don’t really need to worry about what this means right now). DispatchMessage then sends the message to the proper window procedure. Our window procedure is a special function that will process all of our messages. Note: there is a function called PeekMessage you can look up on your own time. Its quite useful because it returns (boolean) immediately instead of waiting around for a message like GetMessage does. It has its advantages, but I won’t discuss them here. Now lets see how we go about actually creating our window.

    First we need to register the window class. This would happen somewhere in the «other initialization code» section I left out of the WinMain above. Our window class can be registered via code such as:

    The WNDCLASS structure contains window class attributes for the window we plan on creating. For a complete description and listing of all the available constants, read the help files that came with your compiler. (Word to the wise: Throughout your days of Windows coding, you will most likely be dealing with MANY constants, api calls, and things of this nature. Be sure to familiarize yourself with the help files. They’re extremely useful when you’re learning the way things work and as a general reference.) I’ll briefly try to explain what each member means:

    style Specifies the class style. CS_HREDRAW and CS_VREDRAW mean that our window will redraw whenever our window is moved or resized horizontally or vertically.
    lpfnWndProc Specifies our window’s ‘window procedure’, which handles the messages that are sent to it. We’ll see more on that later.
    cbClsExtra Amount of extra space (in bytes) to allocate for the class structure.
    cbWndExtra Amount of extra space (in bytes) to allocate for the window structure.
    hInstance Instance handle.
    hIcon Handle to an icon (use a resource handle)
    hCursor Handle to a cursor (use a resource handle)
    hbrBackground Handle to a brush to use as the class background. There are several «COLOR_» HBRUSH values you can look up in the help files.
    lpszMenuName Pointer to a string that holds the menu name (from a resource). We aren’t using a menu for this example program.
    lpszClassName Pointer to a string that specifies our class name. WINDOWNAME is #defined elsewhere in the program as «Simple Sample Application».

    After setting up our WNDCLASS structure, we register our class by using RegisterClass which registers our window class so we can use CreateWindow to actually create our window such as the following code does.

    The parameters should be fairly self explanatory (again, all the values for things such as ‘window style’ can be located in the help files), but I’ll quickly explain them. The first parameter is the class name that we registered earlier. The second parameter is the window name — which will show up in our window caption. The next parameter is the window style, which in our case is WS_OVERLAPPEDWINDOW. There are many combinations of styles you can use, but you’ll have to look up all the values in the help file because there are too many for me to list here. The next two parameters specify the starting position of the window (horizontally and vertically). CW_USEDEFAULT just means to use the default position. The next two parameters specify the window’s width and height respectively. The next parameter is the handle to a parent window. If our window was a child or owned window, we’d set this parameter to the parent window handle. Next up is a menu handle, but we’re not using a menu so it’s NULL. The next-to-last parameter is our instance handle and the last parameter is a pointer to other data to be sent to the window. After creating the window, you should usually check if the returned handle is valid then call ShowWindow and UpdateWindow which will set our window’s show state and then tell it to repaint itself.

    Now we would have a functioning window on our screen as shown below:

    But don’t think we’re done just yet. We still need to write the window procedure which is how we make our seemingly useless and pointless window respond to some events.

    Processing Messages

    As I mentioned before, we need to look at how the window procedure for our function works. Here is an example:

    The code above is a little strange and doesn’t do very much, but hopefully it will illustrate my point. The convention is to use a large switch/case setup to handle messages that we want to process explicitly — then return DefWindowProc to take care of any messages that we don’t. The «WM_» values above are ‘window messages’ that are simply constants that refer to events. For example as I mentioned earlier, a «WM_QUIT» message would return 0 to GetMessage (thus ending our message loop and exiting). If we wanted to process the WM_QUIT message ourselves, we’d add to the switch above, «case WM_QUIT:» and the corresponding code. In the example program I only added two messages to process, the «WM_MOVE» message which occurs after the window has been moved, and the «WM_DESTROY» which occurs when a window is being destroyed. You can add as many other window messages as you’d like such as «WM_CHAR» and «WM_SIZE» that all occur based on different events. Hopefully you should be seeing how things are coming together now. Events (like moving our window with the mouse) occur which are then translated (in the message loop) into messages. The messages are sent to our window and we do specific things based on what message it is. Any messages we don’t neccesarily want to do anything with, the DefWindowProc handles. Wonderful, yes?

    C# Programming: From Problem Analysis to Program Design 2nd

    Barbara Doyle

    Chapter 8

    Introduction to Windows Programming

    Educators

    Problem 1

    One of the differences between a console application and a Windows application is:
    a. Classes can only be used with console applications.
    b. One font size is used with console applications.
    c. Variables must be declared with console applications.
    d. Windows applications require that program statements be placed in a class.
    e. Execution always begins in the Main( ) method for console applications.

    Problem 2

    Which namespace includes most of the Control classes for developing Windows applications?
    a. System;
    b. System. Windows. Controls
    c. System. Windows. Components. Forms
    d. System. Windows. Forms
    e. System. Windows. Drawing;

    Problem 3

    Which of the following inherits members from the control class?
    a. Label
    b. Form
    c. TextBox
    d. a and $c$
    e. all of the above

    Problem 4

    The______________ is the front end of a program that represents the presentation
    layer or the visual image of the program.
    a. interface
    b. control
    c. Visual Studio
    d. IDE
    e. framework

    Problem 5

    A(n) _____________ is a notification from the operating system that an action has
    occurred, such as the user clicking the mouse or pressing a key.
    a. method call
    b. statement
    c. event
    d. GUI
    e. handler

    Problem 6

    Which of the Control objects is viewed as a container that can hold other objects when you design a Windows application?
    a. Control
    b. Button
    c. Window
    d. Frame
    e. Form

    Problem 7

    Which property is used to set the caption for the Windows title bar?
    a. Caption
    b. Text
    c. Title
    d. TitleBar
    e. WindowTitle

    Problem 8

    The class heading public class AForm : Form indicates that:
    a. Form is a derived class of the AForm class.
    b. AForm is the base class for the Form class.
    c. The class being defined is identified as Form.
    d. AForm inherits the members of the Form class.
    e. none of the above

    Problem 9

    If the name of the class is graphicalForm, the following:
    public graphicalForm( )
    is an example of $a(n):$
    a. accessor method
    b. property
    c. constructor
    d. mutator method
    e. data member

    Problem 10

    You would use an IDE such as Visual Studio to construct Windows applications because it has the following capability:
    a. drag-and-drop construction
    b. Intellisense features
    c. access to the Properties window listing properties and events
    d. access to the Toolbox for dropping controls
    e. all of the above

    Problem 11

    Click is an example of $a(n):$
    a. event
    b. property
    c. method
    d. control
    e. handler

    Problem 12

    Visual Studio has a number of windows that can be viewed during design. The window used to hold controls that are dragged and dropped during construction is called the:
    a. Property
    b. Code Editor
    c. Form Designer
    d. Solution Explorer
    e. Class View

    Problem 13

    If the System.Windows.Forms namespace is imported, the following statement:
    this.textbox1ƒ=ƒnewƒSystem.Windows.Forms.TextBoxƒ(ƒ);
    can be written as:
    a. this.textbox1 = new TextBox ( );
    b. textbox1 = new TextBox ( );
    c. textbox1 = new System.Windows.Forms.TextBox ( );
    d. all of the above
    e. none of the above

    Problem 14

    The statement that actually constructs or instantiates a Button object is:
    a. this.button1 = new System.Windows.Forms.Button( );
    b. private System.Windows.Forms.Button button1;
    c. this.Controls.AddRange(this.button1);
    d. button1.Name = “A button”;
    e. button1.Click += new System.EventHandler
    ƒƒƒ(this.button1_Click);

    Problem 15

    The statement that registers a Button object click event with the operating system is:
    a. this.button1ClickEvent = new System.Windows.Forms.Button( );
    b. private System.Windows.Forms.Button button1ClickEvent;
    c. this.Controls.AddRange(this.button1ClickEvent);
    d. button1.Click = “Register Me”;
    e. button1.Click += newƒSystem.EventHandler
    ƒƒƒ(this.button1_Click);

    Problem 16

    The property of the TextBox control that is used to set all characters to uppercase as
    they are typed is:
    a. CharacterCasing
    b. Text
    c. ToUpper
    d. UpperCase
    e. ConvertToUpper

    Problem 17

    Which of the following might be the heading for an event-handler method?
    a. private void btn1_Click(object sender, System.EventArgs e)
    b. Application.Run(new TempAgencyForm());
    c. btnCalculate.Click += new
    System.EventHandler(this.btnCalculate_Click);
    d. this.btnCalculate = new System.Windows.Forms.Button();
    e. none of the above

    Problem 18

    Which of the following design considerations leads to more user-friendly presentation
    layers for GUIs?
    a. Avoid clutter.
    b. Be consistent with font, color, and placement.
    c. Design for the target audience.
    d. Use contrast to call attention to something.
    e. all of the above

    Problem 19

    The #region. #endregion is an example of a C#_______________ .
    a. Windows class declaration statement
    b. required statement for creating Windows applications
    c. reference to a namespace called region
    d. preprocessor directive
    e. collapsible segment of code that must be used for Windows applications

    Problem 20

    During design, how can you separate the business logic from the presentation layer?
    a. Create two forms, one for input and the other for output.
    b. Create two objects using an object-oriented approach.
    c. Create at least two methods.
    d. Create separate classes for each.
    e. all of the above

    Problem 21

    Describe at least three ways Windows applications differ from console applications.

    Problem 22

    Identify which property could be set so that a Form object would perform the fol-
    lowing function:
    a. Change the background color for the form.
    b. Set the default font to Courier for all controls that are added.
    c. Change the size of the window to 400 by 400.
    d. Associate a name of designForm with the Form object.
    e. Position the window near the center of the screen.

    Problem 23

    Describe what might be done to respond to a button click event.

    Problem 24

    List at least five issues to consider when you plan the design of graphical user interfaces.

    Problem 25

    Describe the process that must occur to get a TextBox object added to a Form object. In your description, consider not only how the process is performed with Visual Studio, but also what steps would be necessary to do it manually.

    Читайте также:  Как узнать windows live id что это
    Оцените статью