Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
Advertisements

Structured Design The Structured Design Approach (also called Layered Approach) focuses on the conceptual and physical level. As discussed earlier: Conceptual.
Introduction to Macromedia Director 8.5 – Lingo
1 Windows Programming CIS 577 Bruce R. Maxim UM-Dearborn.
Intro to Computers!.
Computer Graphics1 Windows NT Graphics Interface.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
INTRODUCTION TO VC++ As the Microsoft Windows 3.X and then 5.5 operating system was becoming popular, many programmers were interested in creating graphical.
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
Teach Yourself Windows 98 Module 2: Working with Files, Folders, and the Desktop.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Visual Basic .NET BASICS
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
CSE3AGT Paul Taylor Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.
Winsock Programming Blocking and Asynchronous Sockets for Windows.
Further games and graphics concepts COSE50581 Introduction to Module and Recap Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
XP New Perspectives on Microsoft Windows 2000 Professional Windows 2000 Tutorial 1 1 Microsoft Windows 2000 Professional Tutorial 1 – Exploring the Basics.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
Lecture 7 Menu, controls, scroll bars. Menu Menu item sends WM_COMMAND message to the application window Menu is attached to window when the window is.
Presentation Outline Introduction Painting and Repainting GDI.
Registering a window class Windows allows many styles of window to be created. To tell Windows to create a window as you want it you need to define a class.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Application software- programs that let you do things What are some computer programs that you or your parents use on the computer?
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
Menus  Menus is a feature which is common to almost every windows applications. It is the one of the most common user interface elements around.  Windows.
Introduction to OpenGL
Copyright © – Curt Hill Building Windows Applications in wxDev-C++
Learning Programming Windows API Morpheus Feb-28, 2008.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
W indows Programming Lecture 08. Brief History of Win Windows is announced 1984 Work begins on Word for Windows 1.0 November 1985: Windows 1.0.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Presentation Outline Introduction Painting and Repainting GDI.
PYGAME.
Windows Programming Lecture 10.
Visual Programming Lecture 1 & 2
Windows Programming Lecture 09.
Window.
Windows Programming Model
Windows Programming using Dev C++
The program in traditional OS
Windows Programming Lecture 12
Windows Programming Lecture 13
Windows Programming Lecture 15
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Graphics Laboratory Korea University
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/19.
GUI Socket Application
Presentation transcript:

Overview of Previous Lesson(s)

Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows API  Using the Microsoft Foundation Classes.  Using Windows Forms. 3

Over View.. 4

Over View…  A Windows program is mostly event – driven.  Events in a Windows application are occurrences.  Clicking the mouse.  Pressing a key.  Message queue for an application is just a sequence of such messages waiting to be processed by the application. 5

Over View…  WndProc() is the function we can use to sending the messages to our applications.  Windows accesses the function through a pointer to a function.  DefWindowProc() is used to pass a message back to Windows.  Provides default message processing. 6

Over View…  WinMain()  Where execution of the program begins and basic program initialization is carried out.  WndProc()  Called by Windows to process messages for the application.  Contains the larger portion of code deals in responding to messages caused by user input of one kind or another. 7

Over View... 8

Contents  Specifying a Program Window  Creating a Program Window  Dealing with Windows Messages  WinMain()  Message Processing Functions  The WndProc() Function  Decoding a Windows Message  WndProc()  Program Organization 10

Specifying a Program Win  1 st we have to define the type of window we want to create.  Windows defines a special struct type WNDCLASSEX  It contains the data specified by a window. 11

WNDCLASSEX struct WNDCLASSEX {UINT cbSize; // Size of this object in bytes UINT style; // Window style WNDPROC lpfnWndProc; // Pointer to message processing function int cbClsExtra; // Extra bytes after the window class int cbWndExtra; // Extra bytes after the window instance HINSTANCE hInstance; // The application instance handle HICON hIcon; // The application icon HCURSOR hCursor; // The window cursor HBRUSH hbrBackground; // The brush defining the background color LPCTSTR lpszMenuName; // A pointer to the name of the menu LPCTSTR lpszClassName; // A pointer to the class name HICON hIconSm; // A small icon associated with the window }; 12

WNDCLASSEX.. WNDCLASSEX WindowClass; // Create a window class object  Now we simply need to fill the values for the members of WindowClass  Setting the value for the cbSize member of the struct is easy when you use the sizeof operator: WindowClass.cbSize = sizeof(WNDCLASSEX);  The style member of the struct determines various aspects of the window’s behavior. WindowClass.style = CS_HREDRAW | CS_VREDRAW; 13

WNDCLASSEX.. WNDPROC lpfnWndProc; // Pointer to message processing function  It stores a pointer to the function in our program that handles messages for the created window.  cbClsExtra and cbWndExtra allows to ask that extra space be provided internally to Windows for our own use.  Normally it is not required so they must set to zero. 14

WNDCLASSEX... HINSTANCE hInstance; // The application instance handle  It holds the handle for the current application instance, so we should set this to the hInstance value that was passed to WinMain() by Windows. 15

WNDCLASSEX... HICON hIcon; // The application icon HCURSOR hCursor; // The window cursor HBRUSH hbrBackground;  These members are handles that defines  Icon that represents the application when minimized.  Cursor the window uses  Background color of the client area of the window.  These are set using Windows API functions. WindowClass.hIcon = LoadIcon(0, IDI_APPLICATION); WindowClass.hCursor = LoadCursor(0, IDC_ARROW); 16

WNDCLASSEX...  The lpszMenuName member is set to the name of a resource defining the window menu, or to zero if there is no menu for the window.  The lpszClassName member of the struct stores the name that is supplied to identify this particular class of window.  We need to keep track of this name because we will need it again when window will created.  The last member is hIconSm  It identifies a small icon associated with the window class. 17

Creating a Program Win  2 nd step is to tell Windows about our defined structure.  This is done using the Windows API function RegisterClassEx() RegisterClassEx(&WindowClass);  The address of the struct is passed to the function and Windows extracts all the values of the structure members. 18

Creating a Program Win  This process is called registering the window class.  Each instance of the application must make sure that it registers the window classes that it needs.  CreateWindow() function is now used for creating a window whom characteristics are already known. 19

Creating a Program Win.. HWND hWnd; // Window handle... hWnd = CreateWindow( szAppName, // the window class name "A Basic Window the Hard Way", // The window title WS_OVERLAPPEDWINDOW, // Window style as overlapped CW_USEDEFAULT, // Default screen position of upper left CW_USEDEFAULT, // corner of our window as x,y... CW_USEDEFAULT, // Default window size, width... CW_USEDEFAULT, //... height 0, // No parent window 0, // No menu hInstance, // Program Instance handle 0 // No window creation data ); 20

Creating a Program Win.. HWND hWnd; // Window handle  The variable hWnd of type HWND is a 32 - bit integer handle to a window.  Window now exists but is not yet displayed.  So now we need to call another Win API function to get it displayed. 21

Creating a Program Win... ShowWindow(hWnd, nCmdShow); // Display the window  hWnd identifies the window and is the handle returned by the function CreateWindow()  nCmdShow indicates how the window is to appear onscreen. 22

Dealing with Windows Messages  The last task that WinMain() needs to do is dealing with the messages that Windows may have queued for our application.  2 kinds of Win messages  Queued Messages  Windows places in a queue.  WinMain() function extract these messages from the queue for processing.  The code in WinMain() that does this is called the message loop. 23

Dealing with Windows Messages  Non - Queued Messages  There are non - queued messages that result in the WndProc() function being called directly by Windows.  A lot of the non - queued messages arise as a consequence of processing queued messages. 24

The Message Loop  Retrieving messages from the message queue is done using the message pump or message loop MSG msg; // Windows message structure while(GetMessage( & msg, 0, 0, 0) == TRUE) // Get any messages { TranslateMessage( & msg); // Translate the message DispatchMessage( & msg); // Dispatch the message } 25

The Message Loop..  GetMessage()  Retrieves a message from the queue.  TranslateMessage()  Performs any conversion necessary on the message retrieved.  DispatchMessage()  Causes Windows to call the WndProc() function in application to deal with the message. 26

WinMain()  Lets check the code in IDE … 27

Message Processing  WinMain() contained nothing that was application - specific beyond the general appearance of the application window.  All of the code that makes the application behave in the way that we want is included in the message processing part of the program.  WndProc()  Windows calls this function each time a message for your main application window is dispatched. 28

WndProc()  The prototype of our WndProc() function is: LRESULT CALLBACK WindowProc ( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);  LRESULT is a type defined by Windows and is equivalent to type long.  As the function is called by Windows through a pointer, so we need to qualify the function as CALLBACK 29

WndProc() 30

Decoding Win Message  Message that window is sending to the WndProc() needs to be decoded.  A switch statement is used for decoding in the WndProc() function.  Switch statement is something like this.. 31

Decoding Win Message switch(message) { case WM_PAINT: // Code to deal with drawing the client area break; case WM_LBUTTONDOWN: // Code to deal with the left mouse button being pressed break; case WM_LBUTTONUP: // Code to deal with the left mouse button being released break; case WM_DESTROY: // Code to deal with a window being destroyed break; default: // Code to handle any other messages } 32

WndProc()  We will see it in IDE.. 33

A Simple window Program  Already dicuss WinMain() and WndProc() to handle messages.  So we have enough to create an app Windows program just using the Windows API. #include // Insert code for WndProc() // Insert code for WinMain() 34

Program Organization 35 Program

Thank You 36