|
|
|
Modern Operating Systems by Herbert Bos and Andrew S. Tanenb...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf
Showing 438-439 out of 1137
Modern Operating Systems by Herbert Bos and Andrew...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Modern Operating Systems by Herbert...
Modern_Operating_Systems_by_Herbert_Bos_and_Andrew_S._Tanenbaum_4th_Ed.pdf-M ODERN O PERATING S YSTEMS
Page 438
SEC. 5.6
USER INTERFACES: KEYBOARD, MOUSE, MONITOR
407
Thumb
Title bar
File
Edit
View
Tools
Options
Help
Client area
(200, 100)
(0, 0)
(0, 767)
Menu bar
Tool bar
Window
Scroll bar
(1023, 767)
(1023, 0)
12
6
9
3
4
8
5
7
1
11
2
10
Figure 5-35.
A sample window located at (200, 100) on an XGA display.
To make this programming model clearer, consider the example of Fig. 5-36.
Here we see the skeleton of a main program for Windows. It is not complete and
does no error checking, but it shows enough detail for our purposes.
It starts by in-
cluding a header file,
windows.h
, which contains many macros, data types, con-
stants, function prototypes, and other information needed by Windows programs.
The main program starts with a declaration giving its name and parameters.
The
WINAPI
macro is an instruction to the compiler to use a certain parameter-pas-
sing convention and will not be of further concern to us. The first parameter,
h
, is
an instance handle and is used to identify the program to the rest of the system.
To
some extent, Win32 is object oriented, which means that the system contains ob-
jects (e.g., programs, files, and windows) that have some state and associated code,
called
methods
, that operate on that state. Objects are referred to using handles,
and in this case,
h
identifies the program. The second parameter is present only for
reasons of backward compatibility.
It is no longer actually used. The third parame-
ter,
szCmd
, is a zero-terminated string containing the command line that started the
program, even if it was not started from a command line. The fourth parameter,
Page 439
408
INPUT/OUTPUT
CHAP. 5
#include <windows.h>
int WINAPI WinMain(HINSTANCE h, HINSTANCE, hprev, char
*
szCmd, int iCmdShow)
{
WNDCLASS wndclass;
/
*
class object for this window
*
/
MSG msg;
/
*
incoming messages are stored here
*
/
HWND hwnd;
/
*
handle (pointer) to the window object
*
/
/
*
Initialize wndclass
*
/
wndclass.lpfnWndProc = WndProc;
/
*
tells which procedure to call
*
/
wndclass.lpszClassName = "Program name";
/
*
text for title bar
*
/
wndclass.hIcon = LoadIcon(NULL, IDI
APPLICATION);
/
*
load program icon
*
/
wndclass.hCursor = LoadCursor(NULL, IDC
ARROW);
/
*
load mouse cursor
*
/
RegisterClass(&wndclass);
/
*
tell Windows about wndclass
*
/
hwnd = CreateWindow ( ... )
/
*
allocate storage for the window
*
/
ShowWindow(hwnd, iCmdShow);
/
*
display the window on the screen
*
/
UpdateWindow(hwnd);
/
*
tell the window to paint itself
*
/
while (GetMessage(&msg, NULL, 0, 0)) {
/
*
get message from queue
*
/
TranslateMessage(&msg);
/
*
translate the message
*
/
DispatchMessage(&msg);
/
*
send msg to the appropriate procedure
*
/
}
return(msg.wParam);
}
long CALLBACK WndProc(HWND hwnd, UINT message, UINT wParam, long lParam)
{
/
*
Declarations go here.
*
/
switch (message) {
case WM
CREATE:
... ;
return ... ;
/
*
create window
*
/
case WM
PAINT:
... ;
return ... ;
/
*
repaint contents of window
*
/
case WM
DESTROY :
... ;
return ... ;
/
*
destroy window
*
/
}
return(DefWindowProc(hwnd, message, wParam, lParam)); /
*
default
*
/
}
Figure 5-36.
A skeleton of a Windows main program.
iCmdShow
, tells whether the program’s initial window should occupy the entire
screen, part of the screen, or none of the screen (task bar only).
This declaration illustrates a widely used Microsoft convention called
Hungar-
ian notation
.
The name is a play on Polish notation, the postfix system invented
by the Polish logician J. Lukasiewicz for representing algebraic formulas without
using precedence or parentheses. Hungarian notation was invented by a Hungarian
programmer at Microsoft, Charles Simonyi, and uses the first few characters of an
identifier to specify the type. The allowed letters and types include c (character), w
(word, now meaning an unsigned 16-bit integer), i (32-bit signed integer), l (long,
Ace your assessments! Get Better Grades
Browse thousands of Study Materials & Solutions from your Favorite Schools
Concordia University
Concordia_University
School:
Operating_Systems
Course:
Introducing Study Plan
Using AI Tools to Help you understand and remember your course concepts better and faster than any other resource.
Find the best videos to learn every concept in that course from Youtube and Tiktok without searching.
Save All Relavent Videos & Materials and access anytime and anywhere
Prepare Smart and Guarantee better grades
Students also viewed documents
lab 18.docx
lab_18.docx
Course
Course
3
Module5QuizSTA2023.d...
Module5QuizSTA2023.docx.docx
Course
Course
10
Week 7 Test Math302....
Week_7_Test_Math302.docx.docx
Course
Course
30
Chapter 1 Assigment ...
Chapter_1_Assigment_Questions.docx.docx
Course
Course
5
Week 4 tests.docx.do...
Week_4_tests.docx.docx
Course
Course
23
Week 6 tests.docx.do...
Week_6_tests.docx.docx
Course
Course
106