Simple Gui in C - PowerPoint PPT Presentation

About This Presentation
Title:

Simple Gui in C

Description:

How to Paint. First get an handle to the screen. hdc = BeginPaint(hWnd, &ps) ... Can paint in different styles and colors. SelectObject(hdc, HPEN pen) ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 20
Provided by: csta3
Category:
Tags: colors | gui | paint | simple

less

Transcript and Presenter's Notes

Title: Simple Gui in C


1
Simple Gui in C
2
Project Selecting
3
(No Transcript)
4
So Far
  • Registering the window class
  • Creating the window

5
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

6
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

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

8
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_NOMOVESWP_NOZORDER)
  • Determines the window position and size.

9
Painting
  • When does painting occurs?
  • After receiving WM_PAINT

10
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)

11
Painting functions
  • LineTo(hdc, int x, int y)
  • Line from current position to (x,y)
  • MoveToEx(hdc, int x, int y, NULL)
  • Move the cursor to (x,y)

12
  • 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, 100
    y 1,SWP_NOMOVESWP_NOZORDER)

13
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

14
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

15
Adding Options
16
For more Information
  • A simple tutorial
  • MSDN!!!

17
Java - Graphics
  • Working with Graphics object
  • Graphics g
  • DrawLine
  • DrawRect
  • SetColor
  • .

18
Applet
  • An applet is a small, embeddable Java Program.
  • Usually implementing a subclass of applet.

19
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
Write a Comment
User Comments (0)
About PowerShow.com