2_f09_win32api - Win32 API Programming See also the old...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
(C) Richard R. Eckert Win32 API Programming • See also the old notes at: http://www.cs.binghamton.edu/~reckert/360/class2a.htm http://www.cs.binghamton.edu/~reckert/360/class3a.htm (C) Richard R. Eckert • Event-driven , graphics oriented • Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals from mouse – figures out which window user has selected – sends a message to that window’s program: • "User has clicked over (X,Y)” • "Do something and return control to me” – Program reads message data, does what's needed, returns control to Windows Win32 API Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(C) Richard R. Eckert (C) Richard R. Eckert Overview of Win32 API Program Structure--2 main tasks: • Initial activities • Process messages from Windows – the message loop
Background image of page 2
(C) Richard R. Eckert Pseudocode • Initialize variables, memory space • Create and show program's window • Loop – Fetch any message sent from Windows to this program – If message is WM_QUIT • terminate program, return control to Windows – If message is something else • take actions based on message and parameters • return control to Windows • End Loop (C) Richard R. Eckert Essential Parts of a Win32 API Pgm • I. The source program (.c/.cpp file): – A. WinMain() function • 0. declarations, initialization, etc. • 1. register window “class” • 2. create a window based on a registered “class” • 3. show window, make it update its client area • 4. the message loop (get messages from Windows, dispatch back to Windows for forwarding to correct callback message-processing function, the WndProc) – B. WndProc(): the message-processing function • we write this function
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(C) Richard R. Eckert • II. The resource script (.rc file): – contains resource (Windows static) data – separate from code and dynamic data – compiled by a separate "Resource Compiler” – Resources determine the app’s “look and feel” – Examples of Windows Resources: • Keyboard Accelerators, Bitmaps, Cursors, Dialog Box specs, Fonts, Icons, Menus, String Tables – Separation of resources and program code==> • can change user interface without touching code (C) Richard R. Eckert The WinMain( ) Function • int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow); • WinMain() starts first • integer exit code returned to Windows OS • PASCAL: l-to-r parameter passing on stack • 4 parameters passed in from Windows – hInstance: a “handle”, identifies current pgm instance – lpszCmdLine: string containing command line args – nCmdShow: how window is to appear when shown
Background image of page 4
(C) Richard R. Eckert Hungarian Notation • help clarify variable types • precede name with key letters representing type • named after Hungarian Microsoft programmer, Charles Simonyi (C) Richard R. Eckert prefix data type --------------------------------- by BYTE (unsigned char)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

2_f09_win32api - Win32 API Programming See also the old...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online