Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction. Windows Programming 2  Windows –32-bit preemptive multitasking and multithreading graphical operating systems –GUI(graphical user interface)

Similar presentations


Presentation on theme: "Introduction. Windows Programming 2  Windows –32-bit preemptive multitasking and multithreading graphical operating systems –GUI(graphical user interface)"— Presentation transcript:

1 Introduction

2 Windows Programming 2  Windows –32-bit preemptive multitasking and multithreading graphical operating systems –GUI(graphical user interface) or graphical windowing environment –Virtualizes hardware of graphics display devices i.e. Windows includes a graphics programming language(GDI) –Provides a wealth of function calls that an application can take advantage of, mostly to implement its user interface and display text and graphics on video display. –Win32 API encompasses all the function calls that an application program can make use of an operating system, as well as definitions of associated data types and structures. –API functions are implemented in dynamic- link libraries, or DLLs. (KERNEL32.DLL, USER32.DLL, GDI32.DLL) –the API is not just a library, but also implies a particular program architecture.

3 Windows Programming 3  Language Options –Using C and the native APIs is not the only way to write programs for Windows. offers you the best performance, the most power, and the greatest versatility in exploiting the features of Windows. provides you with a deeper understanding of Windows internals. –Microsoft Visual Basic, Borland Delphi –Microsoft Visual C++ with Microsoft Foundation Class Libraries(MFC)  API Documentation –http://www.microsoft.com/msdn (MSDN Library Online)http://www.microsoft.com/msdn

4 Windows Programming 4  Unicode –Each character in Unicode is 16-bit wide. –WINNT.H defines TCHAR type and TEXT macro to be used generically for both ASCII char and Unicode char. –Whether the identifier UNICODE is defined or not defines which char code is used in the program.

5 Windows Programming 5  An Architectural Overview –Event-driven programming Event is any kind of action occurred in the system.(Enter the key, Mouse click, Window move, Window resize……..) When an event occurs, a corresponding code is performed –Object-oriented programming A window can be viewed as an object (data + procedures) The window(object) receives the user input in the form of messages A message is predefined data structure that has the information about an event. Every window has an associated “window procedure”. A “window instance” is created based on a “window class” which defines the window procedure that processes messages to the window Windows sends a message to a window by calling a its window procedure. The window procedure does some processing based on the message and then returns control to Windows.

6 Windows Programming 6 When a Windows program begins execution, Windows creates a “message queue” for the program. This message queue stores messages to all the windows a program might create. A window application includes a short chunk of code called “message loop” to retrieve these messages from the queue and dispatch them to the appropriate window procedure. There are some messages that are sent directly to the window procedure without being placed in the message queue.

7 Windows Programming 7  Windows Architecture Message 변환 Main Memory 2. get message 1. Mouse keyboard 외부입력 Windows System Message queue Program Message queue Window instance 사용자 응용 프로그램 WinMainWindow Procedure.. window class 4. callback message loop 3. dispatch message

8 Windows Programming 8  Scenario WinMain WindowsWndProc GetMessage DispatchMessage WndProc CreateWindow MouseClick message 를 Queue 에 넣는다 *

9 Windows Programming 9  The First Windows Program – Hellowin program – 별첨 소스코드 참조  WinMain 함수의 역할 – 프로그램 실행시 사용할 window 의 class 구조를 정의하고 이를 Windows 에 등록한다. – 정의된 window class 로부터 window instance 를 생성한다. 이 때 생성된 window instance 구조는 화면상에 window 를 표현하기 위한 정보들의 모임이다. –Window class 구조는 window 의 기본 틀에 대한 정보, 즉 icon 의 모양, 배경 화면, 사용되는 기본 커서의 모양 등이 정의되며 window instance 는 class 에서 주어진 기본 틀에 대하여 window 를 직접 화면에 그리기 위한 정보를 갖는다.

10 Windows Programming 10 –Window instance 생성하면 Windows 는 응용 프로그램에게 window handle 을 넘겨준다. – 화면상에 나타나는 1 개의 window 에 1 개의 window instance 가 할당되며, 1 개의 window class 로부터는 여러 개의 window instance 가 만들어 진다. –message 처리를 위해 다음과 같은 형태의 Message Loop 를 실행한다 while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }

11 Windows Programming 11  Window procedure 의 역할 –Window procedure 는 Windows 에 의하여 호출되며 이 때 하나의 message 가 전달된다. – 전달된 message 의 종류에 따라 처리해야 할 일을 처리한다.  Windows program 의 작성 – 모든 응용 프로그램에서 WinMain 은 거의 동일하다. – 따라서 window procedure 를 작성하는 경우, 하는 일은 어떤 message 가 전달되었을 때 어떤 일을 해야 하는 가를 기술하는 작업이 된다.

12 Windows Programming 12  Windows 프로그래머가 정확히 알아야 할 내용 –Mouse 나 keyboard 의 조작에 대하여 어떤 message 들이 window procedure 로 전달되는가 ? ( 약 100 여 가지의 서로 다른 message 종류가 있음 ) – 어떤 message 가 전달되는 경우 그 message 안에 어떤 정보들이 함께 전달되는가 ? – 내가 처리하고자 하는 기능을 처리하기 위해서는 Windows 가 제공하는 함수 중 어떤 함수를 사용해야 하는가 ? ( 대략 수천개의 함수가 있음 )  The Header Files –WINDOWS.H is a master include file that includes other Windows header files, some of which also include other header files. WINDEF.H Basic type definition WINNT.H Type definition for Unicode support. WINBASE.H Kernel functions WINUSER. H User interface functions WINGDI.H Graphics device interface functions

13 Windows Programming 13  Message 의 처리 typedef struct tagMSG { HWND hwnd; UNIT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG; typedef struct tagPOINT { LONG x; LONG y; } POINT;

14 Windows Programming 14 –hwnd message 를 발생시킨 window 의 handle –message message identifier, 어떤 message 인지를 표시하기 위한 message 의 번호. Windows 가 생성하는 모든 message 의 번호는 에 WM_ 형태의 symbolic constant 로 정의되어 있음. –wParam, lParam 32-bit message parameter 로서 의미와 값은 message 종류에 따라 다르다. –time message 가 message queue 에 저장된 시간 –pt message 발생 시점에서의 mouse 위치 X, Y 좌표

15 Windows Programming 15  Queued and Nonqueued Message –Queued Message message queue 에 저장되어지는 message WinMain 의 message loop 의 GetMessage 함수의 실행에 의하여 message queue 로부터 인출되고 DispatchMesssage 함수에 의하여 window procedure 에 전달된다.(PostMessage) Keyboard, Mouse, timer 로부터 발생되는 message, WM_PAINT, WM_QUIT message –Nonqueued Message queue 에 저장되지 않고 바로 Windows 로 전달된 후 Windows 에 의하여 window procedure 로 전달되는 message.(SendMessage) queued message 가 아닌 나머지 message

16 Windows Programming 16 –SendMessage 함수 임의로 nonqueued message 를 발생시킴 –PostMessage 함수 임의로 queued message 를 발생시킴 – 일반적으로 WinMain 과 window procedure 는 순차적으로 ( 교대로 ) 실행된다고 보아도 됨. 즉 DispatchMessage 함수에 의하여 window procedure 로 message 가 전달되면 그 message 의 처리가 끝나 window procedure 가 return 하여야 DispatchMessage 함수도 return 하게 됨. –Windows 가 제공하는 API 함수 중 많은 함수가 SendMessage 함수를 이용하여 message 를 발생시킴. 예 ) CreateWindow -> WM_CREATE ShowWindow -> WM_SIZE, WM_SHOWWINDOW UpdateWindow -> WM_PAINT

17 Windows Programming 17 – 한번의 keyboard 나 mouse 조작에 의해서 순차적으로 여러 개의 message 가 발생되는 경우가 많음 예 ) Mouse 로 window title bar 의 close button 을 누른 경우 1) WM_SYSCOMMAND -> window procedure 2) window procedure 내에 WM_SYSCOMMAND message 처리 routine 이 없는 경우 3) DefWindowProcedure 가 WM_CLOSE message 발생 4) window procedure 내에 WM_CLOSE message 처리 routine 이 없는 경우 5) DefWindowProcedure 가 WM_DESTROY message 발생 6) window procedure 가 PostQuitMessage 함수를 이용 WM_QUIT message 를 Message Queue 에 저장 7) WinMain 의 GetMessage 함수가 WM_QUIT message 를 읽으면 WinMain 의 message loop 의 실행이 끝남 window procedure DefWindowProcedure WM_SYSCOMM AND window procedure DefWindowProcedure WM_CLOS E


Download ppt "Introduction. Windows Programming 2  Windows –32-bit preemptive multitasking and multithreading graphical operating systems –GUI(graphical user interface)"

Similar presentations


Ads by Google