Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.

Slides:



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

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Computer Graphics1 Windows NT Graphics Interface.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Region of Interest Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
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)
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Building a Win32API Application Raw access to the API.
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
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.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
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.
Lecture Two Event Handling Keyboard and Mouse Input.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
Server Core is the preferred deployment configuration.
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.
Assign one variable to each group of radio buttons To do this, assign one integer variable to the first radio button in each group. All the subsequent.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
Lec 16 Adding Mouse and KeyEvent handlers to an Applet Class.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Bitmap (Chapter 15).
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
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.
Chapter2: Drawing a Window
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
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.
Introduction to OpenGL
Please open JCreator and follow these steps: 1)Configure  Options 2)JDK Tools 3)Choose Run Applet from drop-down 4)Click Default, then Edit 5)Click the.
Learning Programming Windows API Morpheus Feb-28, 2008.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
Drawing in Windows. To help with drawing on the Windows operating system, Microsoft created the Graphical Device Interface, abbreviated as GDI. – It is.
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Programming windows with MFC Chapter 2 - Drawing in a Window
Presentation Outline Introduction Painting and Repainting GDI.
Windows Programming Lecture 09.
Building a Win32API Application
Windows Programming Model
Queued and Nonqueued Messages
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
The program in traditional OS
Windows Controls & Concepts
Graphic Device Interface
Windows Programming Lecture 12
Windows Programming Lecture 13
CS 1253 Visual Programming Unit I Windows Environment
Windows Programming Lecture 15
19.
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Model, View, Controller design pattern
Graphics Laboratory Korea University
GUI Socket Application
Chapter 14 Drawing in a Window
Presentation transcript:

Simple Gui in C++

Project Selecting

So Far Registering the window class Creating the window

So Far

The major function/Handling Messages WndProc Return value: LRESULT CALLBACK Parameters: HWND hWnd UINT message WPARAM wParam LPARAM lParam): The function handles all events (message): –WM_CREATE –WM_PAINT –WM_LBUTTONUP

Handling Messages(Cont) Historically wParam 16 bit lParam 32 bit; Today both 32 bit Each message use those parameters differently For example –WM_LBUTTON - lParam stores coordinates LOWORD, HIWORD – extract two words

Message Queue There are no interrupts When messages are posted they are added to the message queue After handling them they are removed

Working with Rectangles GetWindowRect(m_hWnd,&rt1) –return the window rectangle in screen coordinates GetClientRect(m_hWnd,&rt2) –return window rectangle in "itself" coordinates SetWindowPos(m_hWnd,NULL,0,0,x,y,SWP_NOMOVE|SWP_NOZORDER); –Determines the window position and size.

Painting When does painting occur? After receiving WM_PAINT

How to Paint First get an handle to the screen hdc = BeginPaint(hWnd, &ps); Using hdc in each “painting” function. Do not forget –EndPaint(hWnd, &ps);

Painting functions LineTo(hdc, int x, int y); –Line from current position to (x,y) MoveToEx(hdc, int x, int y, NULL) –Move the position to (x,y)

case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt,rt1; GetClientRect(hWnd, &rt); GetWindowRect(hWnd, &rt1); int x, y; y = (rt1.bottom - rt1.top) - rt.bottom; x = (rt1.right - rt1.left) - rt.right; //DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); MoveToEx(hdc,0,0, NULL); LineTo(hdc, 100,0); LineTo(hdc, 100,100); LineTo(hdc, 0,100); LineTo(hdc,0,0); SetWindowPos(hWnd,NULL,0,0,100 + x + 1, y + 1,SWP_NOMOVE|SWP_NOZORDER); EndPaint(hWnd, &ps);

Painting (Cont) CreatePen( int nPenStyle, int nWidth, COLORREF crColor ) –Can paint in different styles and colors SelectObject(hdc, HPEN pen) –The next object will be painted by pen Ellipse(x,y,x1,y1) –The coordinates of the bounding rectangle

Alternative Ways CPen* SelectObject( hdc, CPen* pPen ); CBrush* SelectObject( hdc, CBrush* pBrush ); CBitmap* SelectObject(hdc, CBitmap* pBitmap ); Etc…

Working with Bitmap (See Roy Bubis and Keren Michaeli Proj) Insert Bitmaps to Resources LoadImage CreateCompatibleDC ( hdc ); - –Working on another hdc to avoid flickering SelectObject(memdc, bmp); TransparentBlt(hdc,x,y, dx, dy, memdc,0,0,width, height, RGB(255,0,0)); //passing the content of medc to hdc

Forcing RePaint InvalidateRect(m_hWnd,&rect,TRUE); –signal the OS that this window is invalid and need to be repaint. –The OS send all the invalid windows the WM_PAINT message

How does it look?

Adding Options

For more Information A simple tutorial MSDN!!!

Java - Graphics Working with Graphics object Graphics g –DrawLine –DrawRect –SetColor –….

Applet An applet is a small, embeddable Java Program. “Usually” implementing a subclass of applet.

Handling events The events that we want to handle should be define in our subclass boolean mouseDown(Event e, int x, int y) Boolean mouseDrag(Event e, int x, int y) boolean keyDown(Event e, int x, int y) Etc…