Lecture 2: Windows Basics - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Lecture 2: Windows Basics

Description:

NULL, //parent window handle. NULL, // window menu handle. hInstance, // program instance handle ... Have to trap WM_CLOSE message as discussed on Web. ... – PowerPoint PPT presentation

Number of Views:71
Avg rating:3.0/5.0
Slides: 13
Provided by: phi140
Category:
Tags: basics | lecture | parent | the | trap | windows

less

Transcript and Presenter's Notes

Title: Lecture 2: Windows Basics


1
Lecture 2 Windows Basics
  • Windows is a 32 bit, preemptive, multitasking,
    multithreaded, graphical operating system.
  • Preemptive multitasking multiple programs
    executing, OS time slices all programs.
  • Multithreaded Program decomposed into multiple
    threads, threads are time sliced.

2
Windows Basics Continued
  • Virtualizes video display hardware.
  • Application gets handle to a device context.
  • Implemented as a set of dynamic link libraries
    (dlls).
  • Dlls are not loaded into executable.
  • Provide the Application Program Interface (API).
  • API dictates event-driven (asynchronous) program
    architecture.
  • Reacts to messages sent by OS or application.

3
Unicode
  • Characters are 8 bits 256 combinations.
  • Unicode extends to 16 bits 65,536 comb.
  • Use TEXT(this is a string) macro.
  • TCHAR Pointer to a string.
  • Static TCHAR grumpy TEXT (I feel grumpy)

4
Printf
  • Windows does not understand sdtin, stdout.
  • wsprintf(buf, format string, variables)
  • char buf100
  • int a,b,c, len
  • a 10 b 2 c a b
  • wsprintf(buf, The sum of a d and b d is
    d, a, b, c)
  • s, c, f

5
Program Architecture
  • Asynchronous.
  • Message driven Logically, program receives
    messages from OS and provides handlers.
  • When program begins, OS creates message queue for
    all windows application may create.
  • Application provides message loop.
  • Polling for messages and causing them to get
    dispatched to the appropriate message processing
    function.

6
Windows Programs
  • All windows based on class, each class has
    exactly one message processing function.
  • Provide handlers for messages of interest.
  • All others handled by default processing
    function.
  • Messages are asynchronous (cannot predict which
    msg will be received next).
  • Message passing is really the OS calling the
    message processing function for the window.
  • Messages can be placed in message queue, or the
    OS can call window procedure directly.

7
Function Prototypes
  • include ltwindows.hgt
  • LRESULT CALLBACK WndProc (HWND, UINT, WPARAM,

    LPARAM)
  • Int WinAPI WinMain(HINSTANCE hInstance,
  • HINSTANCE hPrevInstance,
  • PSTR szCmdLine,
  • int iCmdShow)

8
Variable Declarations
  • static TCHAR szAppName TEXT(HelloWin)
  • HWND hwnd
  • MSG msg
  • WNDCLASS wndclass

9
Fill in Class Characteristics
  • wndclass.style CS_HREDRAW CS_VREDRAW
  • wndclass.lpfnWndProc WndProc
  • .
  • wndclass.hInstance hInstance
  • wndclass.hIcon LoadIcon(NULL,
    IDI_APPLICATION)
  • wndclass.hCursor LoadCursor(NULL, ID_ARROW)
  • wndclass.hbrBackground (HBRUSH)
  • GetStockObject(WHITE_BRUSH)
  • wndclass.lpszClassName szAppName

10
Register Class
  • if (!RegisterClass (wndclass))
  • MessageBox (..)
  • return 0

11
Create Window
  • hwnd CreateWindow(szAppName, //set above
  • TEXT(The Hello Program), //caption
  • WS_OVERLAPPEDWINDOW, //style
  • CW_USEDEFAULT, // initial x
  • CW_USEDEFAULT, // initial y
  • CW_USEDEFAULT, // initial x size
  • CW_USEDEFAULT, // initial y size
  • NULL, //parent window handle
  • NULL, // window menu handle
  • hInstance, // program instance
    handle
  • NULL // creation parameters)

12
Lab 2
  • Declare an array of size WM_USER to track
    messages sent but not processes.
  • Element 0 of array tracks number of messages of
    type 0 (if message 0 is not processed by
    application), element 1 tracks number of messages
    of type 1and so forth.
  • Print out the top 5 such messages.
  • Scan the array (at least) 5 times to pick out
    max.
  • Have to trap WM_CLOSE message as discussed on Web.
Write a Comment
User Comments (0)
About PowerShow.com