Windows Programming Lecture 15

Slides:



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

Computer Graphics1 Windows NT Graphics Interface.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
1 Windows Goodies CIS 577 Bruce R. Maxim UM-Dearborn.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
Intro to Windows Programming Basic Ideas. Program Entry Point Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
Building a Win32API Application Raw access to the API.
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
Keyboard In computing, a keyboard is an input device, partially modeled after the typewriter keyboard, which uses an arrangement of buttons or keys, to.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
Douglas Boling President Boling Consulting Inc. SESSION CODE: WEM304.
Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls.
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.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
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.
Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)
Presentation Outline Introduction Painting and Repainting GDI.
Bitmap (Chapter 15).
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 Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
About Windows Jihoon.Yim About Windows 2 Desktop Window Application Windows Client & Nonclient Area Control and Dialog Boxes Desk Window.
Chapter 7 Controls. 2 Introduction (1/4) Control –Special kind of window –Designed to convey information to the user or to acquire input –Reduce the tedium.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
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
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Learning Programming Windows API Morpheus Feb-28, 2008.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
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.
Message Handling in MFC
Presentation Outline Introduction Painting and Repainting GDI.
Windows Programming Lecture 11
Chapter 1: An Introduction to Visual Basic 2015
Windows Programming Lecture 10.
Visual Programming Lecture 1 & 2
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
Windows Programming Lecture 09.
Window.
Building a Win32API Application
18 & 19.
Windows Programming Model
Windows Programming using Dev C++
Queued and Nonqueued Messages
The program in traditional OS
COMMON CONTROLS A control is a child window that an application uses in conjunction with another window to enable user interaction. Controls are most often.
Windows Programming Lecture 12
Windows Programming Lecture 13
Building a Win32API Application
CS 1253 Visual Programming Unit I Windows Environment
Topics Graphical User Interfaces Using the tkinter Module
21-22.
19.
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Graphics Laboratory Korea University
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2011
GUI Socket Application
Presentation transcript:

Windows Programming Lecture 15

Z-order The Z order of a window indicates the window's position in a stack of overlapping windows. This window stack is oriented along an imaginary axis, the z-axis, extending outward from the screen. The window at the top of the Z order overlaps all other windows. The window at the bottom of the Z order is overlapped by all other windows.

CreateWindow() HWND CreateWindow ( LPCTSTR lpClassName, // registered class name LPCTSTR lpWindowName, // window name DWORD dwStyle, // window style int x, // horizontal position of window int y, // vertical position of window int nWidth, // window width int nHeight, // window height HWND hWndParent, // handle to parent or owner window HMENU hMenu, // menu handle or child identifier HINSTANCE hInstance, // handle to application instance LPVOID lpParam // window-creation data );

Child Windows A child window always appears within the client area of its parent window. Child windows are most often as controls. A child window sends WM_COMMAND notification messages to its parent window. When a child window is created a unique identifier for that window is specified in hMenu parameter of CreateWindow()

Prototype of window procedure LRESULT CALLBACK WindowProc ( HWND hwnd, // handle to window UINT uMsg, // WM_COMMAND WPARAM wParam, // notification code and identifier LPARAM lParam // handle to control (HWND) );

WM_COMMAND This message is sent when the user selects a command item from a menu, when a control sends a message to its parent window, or when an accelerator keystroke is translated.

Notification Codes Common controls are child windows that send notification messages to the parent window when events, such as input from the user, occur in the control. The application relies on these notification messages to determine what action the user wants it to take. Except for trackbars, which use the WM_HSCROLL and WM_VSCROLL messages to notify their parent of changes, common controls send notification messages as WM_NOTIFY messages.

WM_COMMAND Notifications The wParam parameter of Window Procedure contains the notification code and control identifier. low word: ID of the control high word: notification code BUTTON BN_CLICKED EDIT EN_CHANGE etc

Child windows application Three push buttons ”RECTANGLE” ”CIRCLE” ”MESSAGE” One edit child window or edit control in its client area One floating popup window with caption with 1 push button ”QUIT APPLICATION”

Child windows application

Objectives of Child windows application Parent-child communication Message Routing Usage of GDI function calls

Window management functions-I The GetParent function retrieves a handle to the specified window's parent or owner. HWND GetParent ( HWND hWnd // handle to child window );

Window management functions-II HWND GetDlgItem ( HWND hDlg, // handle to dialog box int nIDDlgItem // control identifier ); HWND FindWindow LPCTSTR lpClassName, // class name LPCTSTR lpWindowName // window name

Application analysis Window classes in the child windows application: mainWindowClass popupWindowClass System Window Classes

MianWindowClass Important Parameters wc.lpfnWndProc = mainWindowProc; wc.hInstance = hAppInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_UPARROW); wc.hbrBackground= (HBRUSH)GetStockObject (GRAY_BRUSH); wc.lpszClassName= "MainWindowClass";

PopupWindowClass wc.lpfnWndProc = popupWindowProc; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.hCursor = LoadCursor(NULL, IDC_HELP); wc.lpszClassName = "PopupWindowClass";

Creating windows hWndMain = CreateWindow("MainWindowClass", "Virtual University", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 400, 300, NULL, NULL, hInstance, NULL); hWndPopup = CreateWindow("PopupWindowClass", "Popup Window", WS_POPUP | WS_CAPTION | WS_VISIBLE, 250, 250, 300, 250, hWndMain, NULL, hInstance, NULL);

Creating child windows CreateWindow("BUTTON", "Rectangle", WS_CHILD | WS_VISIBLE, 10, 10, 100, 50, hWndMain, 5, hInstance, NULL); CreateWindow("EDIT", "Message", WS_CHILD | WS_VISIBLE | ES_LOWERCASE, 10, 190, 200, 25, hWndMain, 8,

Main window’s WndProc case WM_COMMAND: wControlID = LOWORD(wParam); wNotificationCode = HIWORD(wParam); if(wNotificationCode == BN_CLICKED) { switch(wControlID) case 5: SendMessage(hWndPopup, ?, wparam, ???); break; ... ... ...

User defined messages WINUSER.H contains Window messages #define WM_LBUTTONDOWN 0x0201 (513) #define WM_DESTROY 0x0002 (2) #define WM_QUIT 0x0012 (18) #define WM_USER 0x0400 (1024) #define WM_DRAW_FIGURE WM_USER+786

User defined messages case WM_COMMAND: ... ... ... switch(wControlID) { case 5: SendMessage(hWndPopup, WM_DRAW_FIGURE, RECTANGLE, 0); break; case 6: SendMessage(hWndPopup, WM_DRAW_FIGURE, CIRCLE, 0); break; case 7: SendMessage(hWndPopup, WM_DRAW_FIGURE, TEXT_MESSAGE, 0); break; }

Using Enumerations Objects of type enum are int types, and their size is system-dependent. By default, objects of enum types are treated as 16-bit objects of type unsigned short when transmitted over a network. The keyword enum to identifies an enumerated type. enum FigureType { RECTANGLE, CIRCLE, TEXT_MESSAGE };

Drawing in Popup window-I case WM_DRAW_FIGURE: hDC = GetDC(hWndPopup); switch(wParam) { case RECTANGLE: SelectObject(hDC,GetStockObject( LTGRAY_BRUSH)); Rectangle(hDC, 50, 10, 230, 150); break; }

Drawing in Popup window-II case CIRCLE: hBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(170, 150, 180)); SelectObject(hDC, hBrush); Ellipse(hDC, 70, 10, 210, 150); DeleteObject(hBrush); break;

Drawing in Popup window-III {... ... ... case TEXT_MESSAGE: TextOut(hDC, 50, 100, "Virtual University", 18); SelectObject(hDC, GetStockObject( ANSI_VAR_FONT)); SetBkColor(hDC, RGB(10, 255, 20)); TextOut(hDC, 50, 115, "knowledge Beyond Boundaries", 27); break; } ReleaseDC(hWndPopup, hDC); break;

Application Output

Informing back to main window case WM_DRAW_FIGURE: hDC = GetDC(hWndPopup); hwndEdit = GetDlgItem(GetParent(hWnd), 8); switch(wParam) { case RECTANGLE: SelectObject(hDC,GetStockObject(LTGRAY_BRUSH)); Rectangle(hDC, 50, 10, 230, 150); SendMessage(hwndEdit, WM_SETTEXT, 0, "Rectangle DrAwN!"); break; }

Quit application via a control in the popup window WM_CREATE: CreateWindow("BUTTON", "Quit Application", WS_CHILD | WS_VISIBLE, 75, 155, 150, 40, hWnd, 1234, hAppInstance, NULL); break;

Quit app. via a ctrl in the popup window case WM_COMMAND: wControlID = LOWORD(wParam); wNotificationCode = HIWORD(wParam); if(wNotificationCode == BN_CLICKED) { switch(wControlID) { case 1234: DestroyWindow(GetParent(hWnd)); break; } }

Erase it clean, then draw! case TEXT_MESSAGE: SendMessage(hWndPopup, WM_ERASEBKGND, (WPARAM)hDC, 0); TextOut(hDC, 50, 100, "Virtual University", 18); SelectObject(hDC, GetStockObject(ANSI_VAR_FONT)); SetBkColor(hDC, RGB(10, 255, 20)); TextOut(...) ......... other code .........