5. 키보드. –Windows 는 많은 키보드 함수들을 자체적으로 처리한다. 시스템 함수에 관계되는 키스트로크는 보통 무시할 수 있다. ( 보통 Alt 키를 포함한다.) 프로그램의 메뉴를 불러내는 키스트로크는 윈도우프로시저에 오지 만 보통 DefWindowProc 에.

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
Advertisements

1 Windows Programming CIS 577 Bruce R. Maxim UM-Dearborn.
QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.
IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
Intro to Windows Programming Basic Ideas. Program Entry Point Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
Building a Win32API Application Raw access to the API.
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
프로그래밍 기초와 실습 Chapter 7 Enumeration Types and typedef.
KyungHee Univ. 1-0 문자열 입 · 출력 프로그램 작성 예. KyungHee Univ. 1-1  모니터에 문자열 출력 하는 프로그램 작성  표준 출력 장치에 문자를 출력 하는 함수 함수의 기본형 : void SCI_OutChar(letter)  문자를.
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
Further Programming for 3D applications CE Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and.
6. 마우스.
Keyboard In computing, a keyboard is an input device, partially modeled after the typewriter keyboard, which uses an arrangement of buttons or keys, to.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
Lecture Two Event Handling Keyboard and Mouse Input.
QT – Introduction C++ GUI Programming with Qt 4
Windows Programming Text and Fonts This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep.
Deterministic Problem Introduction 이 챕터에서 다음과 같은 Inhomogeneous 타입의 Equation 을 다룰것이다 Deterministic Problem 에서 g 에 대한 해 L 은 유일하다 Analysis: L 과 g 가 주어졌을 때.
Winsock Programming Blocking and Asynchronous Sockets for Windows.
Further games and graphics concepts COSE50581 Introduction to Module and Recap Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
Lecture 7 Menu, controls, scroll bars. Menu Menu item sends WM_COMMAND message to the application window Menu is attached to window when the window is.
Presentation Outline Introduction Painting and Repainting GDI.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
Creating a DirectX Project A DirectPLay Chat Program.
1 Programming and Software Engineering. 2 Software Development We can define two main classes of software: User-written software solve a particular problem,
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
9. 메뉴와 기타 자원. 1. 자원 – 아이콘, 커서, 메뉴, 대화상자는 모두 Windows 의 자원이다. – 자원은 데이터로 생각할 수 있으며, 프로그램의 EXE 파일에 저장된 다. – 실행 가능한 프로그램의 데이터 영역에는 존재하지 않는다. 자원은 프로그램 소스코드에.
Introduction to OpenGL
Learning Programming Windows API Morpheus Feb-28, 2008.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Chapter 3 Keyboard Input Department of Digital Contents Sang Il Park.
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Presentation Outline Introduction Painting and Repainting GDI.
Windows Programming Lecture 10.
Programming Input Devices
Windows Programming Lecture 09.
Window.
Building a Win32API Application
18 & 19.
Chapter 1 Hello, MFC.
Windows Programming Model
Summer 2001 James Amyot Robert Gowans
Aspect-Oriented Programming
Windows Programming using Dev C++
Queued and Nonqueued Messages
The program in traditional OS
Graphic Device Interface
Windows Programming Lecture 12
Windows Programming Lecture 13
CS 1253 Visual Programming Unit I Windows Environment
Windows Programming Lecture 15
Қош келдіңіздер! Информатика пәні 5 “А” сынып!.
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
CS 1253 Visual Programming Unit I Topic 4
Graphics Laboratory Korea University
GUI Socket Application
Word Pad программасымен практикалық сабақ
Word Pad программасымен практикалық сабақ
Presentation transcript:

5. 키보드

–Windows 는 많은 키보드 함수들을 자체적으로 처리한다. 시스템 함수에 관계되는 키스트로크는 보통 무시할 수 있다. ( 보통 Alt 키를 포함한다.) 프로그램의 메뉴를 불러내는 키스트로크는 윈도우프로시저에 오지 만 보통 DefWindowProc 에 전달되어 디폴트 처리된다. – 특정한 키보드 이벤트를 수신하게 되는 윈도우는 입력 포커스를 가지고 있는 윈도우이다. – 윈도우 프로시저는 WM_SETFOCUS 와 WM_KILLFOCUS 메시지 를 가로채어 자신의 윈도우가 언제 입력 포커스를 가지게 되는 지 를 알 수 있다. – 키보드 메시지는 메시지 큐에 저장된다. 동기화 때문에. 1. 키보드 무시하기

– 키를 누르면 Windows 는 WM_KEYDOWN 이나 WM_SYSKEYDOWN 을 윈도우의 메시지 큐에 전달한다. – 키에서 손을 때면 Windows 는 WM_KEYUP 이나 WM_SYSKEYUP 메시지를 메시지 큐에 전달한다. –WM_SYSKEYUP 과 WM_SYSKEYDOWN 은 보통 ALT 키와 같이 눌려진 키에 의해 생성된다. – 보통 WM_SYSKEYUP 과 WM_SYSKEYDOWN 메시지를 무시하 고 DefWindowProc 에 전달해 준다. case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_SYSCHAR: return 0; -> 모든 Alt 키 동작을 무시하게 한다. – 가상 키 코드는 WM_KEYDOWN,WM_KEYUP, WM_SYSKEYDOWN, 그리고 WM_SYSKEYUP 메시지의 wParam 매개 변수에 저장된다. – 가상 키 코드는 VK_ 로 시작하는 이름을 가진다. WINUSER.H 에 선언 되어있다. VK_LBUTTON,VK_RBUTTON,VK_CANCEL,VK_MBUTTON, VK_BACK,VK_TAB… 2. 키스트로크 메시지

–Shift,Ctrl 그리고 Alt 키나 Caps Lock,Num Lock, Scroll Lock 이 눌 렸는지를 알고 싶을 때는 GetKeyStat 함수를 이용하여 알 수 있다. iState = GetKeyState(VK_SHIFT); – 만약에 Shift 키가 눌려졌을 때는 상위비트가 Setting 된다. iState = GetKeyState(VK_CAPITAL); – 만약에 Caps Lock 키가 켜져 있을 때는 하위 bit 가 Setting 된다. 만약 사용자가 Shift-Tab 을 입력했는지 알고 싶다면 WM_KEYDOWN 메시지를 처리할 때 –GetKeyState(VK_SHIFT) –SendMessage(hwnd,message,wParam,lParam); 윈도우 프로시저에 메시지를 강제로 전달한다. 3. Shift 상태 case WM_KEYDOWN: switch(wParam) { case VK_HOME: SendMessage(hwnd,WM_VSCROLL,SB_TOP,0); break; case VK_END: SendMessage(hwnd,WM_VSCROLL,SB_BOTTOM,0); break; case VK_PRIOR: SendMessage(hwnd,WM_VSCROLL,SB_PAGEUP,0);break; }

–TranslateMessage() 키스트로크 메시지를 문자 메시지로 변환한다. –wParam 에 들어 있는 값은 ANSI 코드이다. – 메시지 순서 WM_KEYDOWN ‘A’ 에 대한 가상 키 코드 WM_CHAR ‘a’ 에 대한 문자 코드 WM_KEYUP ‘A’ 에 대한 가상 키 코드 WM_KEYDOWN VK_SHIFT 가상 키 코드 WM_KEYDOWN ‘A’ 에 대한 가상 키 코드 WM_CHAR ‘A’ 에 대한 문자 코드 WM_KEYUP ‘A’ 에 대한 가상 키 코드 WM_KEYUP VK_SHIFT 가상 키 코드 4. 문자 메시지

– 윈도우에서 키보드 문자 입력을 읽고 싶은 경우는 WM_CHAR 메 시지를 처리한다. –WM_CHAR 메시지는 문자만을 입력하는 메시지이므로 문자 이 외의 키는 입력 받을 수 없다. – 커서 키, 함수 키,Delete, Insert, Ctrl 그리고 Alt 는 WM_CHAR 메시 지가 전달되지 않는다. 위의 키는 KEYDOWN 에서 다룬다. –Tab, Enter, Backspace, Escape 는 WM_CHAR 에서 다루는 것이 더 좋다. 5. 제어문자 처리 case WM_CHAR : switch(wParam) { case ‘ \b ’ ; //backspace break; case ‘ \t ’ : //tab break; case ‘ \n ’ : // 줄 바꿈 break; case ‘ \r ’ : // 캐리지 리턴 break; defaule : // 문자 코드 }

–Caret 함수 CreateCaret 윈도우와 연결된 캐럿을 생성. SetCaretPos 윈도우 내에서 캐럿의 위치를 설정. ShowCaret 캐럿을 보여줌. HideCaret 캐럿을 숨김. DestoryCaret 캐럿을 소멸시킴. –WM_SETFOCUS 메시지에서 CreateCaret –WM_KILLFOCUS 메시지에서 DestroyCaret 6. 캐럿 ( 커서가 아님 )

7. 폰트 HFONT CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, int iWeight, DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet, DWORD fdwOutputPrecision, DWORD fdwClipPrecision,DWORD fdwQuality, DWORD fdwPitchAndFamily, LPCTSTR lpszFace); 인수설명 nHeight 폰트의 높이, 이 값이 0 일 경우에는 디폴트 크기가 사용된다. nWidth 폰트의 폭, 이 값이 0 이면 nHeight 에서 지정한 높이에 따라 폭을 자동으 로 결정한다. nEscapement 폰트의 각도를 0.1 도 단위로 설정한다. 이 각도는 문자가 출력될 X 축과 문자열과의 각도이다. nOrientation 글자 한 자와 X 축과의 각도를 지정한다. nEscapement 는 전체 문자열의 기울기를 지정하는데 비해 이 인수는 개별 문자의 기울기를 설정한다. fnWeight 폰트의 무게를 0 – 1000 까지의 값으로 지정한다. 폰트의 두께를 설정한 다. 보통 굵기는 FW_NORMAL 이 400 이다. fdwItalic fdwUnderline fdwStrikeOut 기울임체, 밑줄, 관통선 속성을 설정한다. DWORD 이지만 불린형처럼 사용한다.

7. 폰트 인수설명 fdwCharSet 문자 셋을 설정한다. 실제 사용할 수 있는 옵션은 ANSI_CHARSET( 윈도우에서 사용 ),OEM_CHARSET( 도스에서 사용 ) 과 HANGEUL_CHARSET 이 있다. fdwOutputPre cision 출력 정확도를 설정한다. fdwClipPrecisi on 클리핑 정확도를 설정한다. fdwQuality 논리적 폰트를 물리적 폰트에 얼마나 근접시킬 것인가를 지정 fdwPitchAndF amily 폰트의 피치와 그룹을 설정한다. lpszFace 글꼴의 이름을 나타내는 문자열을 설정한다.

7. 폰트 –COLORREF SetTextColor( HDC hdc, COLORREF crColor); Text 의 컬러를 Setting 하는 함수 –COLORREF SetBkColor( HDC hdc, COLORREF crColor); 글자의 배경색을 설정하는 함수 –int SetBkMode( HDC hdc, int iBkMode ); 배경색상을 사용할 방법을 설정 OPAQUE : 불투명한 배경을 사용한다. ( 디폴트 ) TRANSPARENT : 문자 사이의 여백에 있는 원래 배경이 지워지지 않는다.

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: { HDChdc; PAINTSTRUCT ps; hdc = BeginPaint(hwnd,&ps); for(int i = 0;i < 900;i+=100) { HFONT hMyFont = CreateFont(50,0,i,0,FW_NORMAL,FALSE,FALSE,FALSE, HANGEUL_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,VARIABLE_PITCH|FF_SWISS," 굴림 "); HFONT hOldFont = (HFONT)SelectObject(hdc,hMyFont); TextOut(hdc,0,300," 강원대학교 ",10); SelectObject(hdc,hOldFont); DeleteObject(hMyFont); } EndPaint(hwnd,&ps); } return 0; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }

/* TYPER.C -- Typing Program (c) Charles Petzold, */ #include #define BUFFER(x,y) *(pBuffer + y * cxBuffer + x) LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("Typer") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, TEXT ("Typing Program"),WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; }

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static DWORD dwCharSet = DEFAULT_CHARSET ; static int cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer,xCaret, yCaret ; static TCHAR * pBuffer = NULL ; HDC hdc ; int x, y, i ; PAINTSTRUCT ps ; TEXTMETRIC tm ; switch (message) { case WM_INPUTLANGCHANGE: dwCharSet = wParam ; case WM_CREATE: hdc = GetDC (hwnd) ; SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmAveCharWidth ; cyChar = tm.tmHeight ; DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ; ReleaseDC (hwnd, hdc) ; case WM_SIZE: if (message == WM_SIZE) { cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; } cxBuffer = max (1, cxClient / cxChar) ; cyBuffer = max (1, cyClient / cyChar) ; if (pBuffer != NULL) free (pBuffer) ; pBuffer = (TCHAR *) malloc (cxBuffer * cyBuffer * sizeof (TCHAR)) ; for (y = 0 ; y < cyBuffer ; y++) for (x = 0 ; x < cxBuffer ; x++) BUFFER(x,y) = ' ' ; xCaret = 0;yCaret = 0 ; if (hwnd == GetFocus ()) SetCaretPos (xCaret * cxChar, yCaret * cyChar) ; InvalidateRect (hwnd, NULL, TRUE) ; return 0 ;

case WM_SETFOCUS: CreateCaret (hwnd, NULL, cxChar, cyChar) ; SetCaretPos (xCaret * cxChar, yCaret * cyChar) ; ShowCaret (hwnd) ; return 0 ; case WM_KILLFOCUS: HideCaret (hwnd) ; DestroyCaret () ; return 0 ; case WM_KEYDOWN: switch (wParam) { case VK_HOME: xCaret = 0 ;break ; case VK_END: xCaret = cxBuffer - 1 ;break ; case VK_PRIOR: yCaret = 0 ;break ; case VK_NEXT: yCaret = cyBuffer - 1 ;break ; case VK_LEFT: xCaret = max (xCaret - 1, 0) ;break ; case VK_RIGHT: xCaret = min (xCaret + 1, cxBuffer - 1) ;break ; case VK_UP: yCaret = max (yCaret - 1, 0) ;break ; case VK_DOWN: yCaret = min (yCaret + 1, cyBuffer - 1) ;break ; case VK_DELETE: for (x = xCaret ; x < cxBuffer - 1 ; x++) BUFFER (x, yCaret) = BUFFER (x + 1, yCaret) ; BUFFER (cxBuffer - 1, yCaret) = ' ' ; HideCaret (hwnd) ; hdc = GetDC (hwnd) ; SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0,dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ; TextOut (hdc, xCaret * cxChar, yCaret * cyChar,&BUFFER (xCaret, yCaret),cxBuffer - xCaret) ; DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ; ReleaseDC (hwnd, hdc) ; ShowCaret (hwnd) ; break ; } SetCaretPos (xCaret * cxChar, yCaret * cyChar) ; return 0 ;

case WM_CHAR: for (i = 0 ; i < (int) LOWORD (lParam) ; i++) { switch (wParam) { case '\b': // backspace if (xCaret > 0) {xCaret-- ; SendMessage (hwnd, WM_KEYDOWN, VK_DELETE, 1) ; } break ; case '\t': // tab do {SendMessage (hwnd, WM_CHAR, ' ', 1) ; }while (xCaret % 8 != 0) ; break ; case '\n': // line feed if (++yCaret == cyBuffer) yCaret = 0 ; break ; case '\r': // carriage return xCaret = 0 ; if (++yCaret == cyBuffer) yCaret = 0 ; break ; case '\x1B': // escape for (y = 0 ; y < cyBuffer ; y++) for (x = 0 ; x < cxBuffer ; x++) BUFFER (x, y) = ' ' ; xCaret = 0 ;yCaret = 0 ; InvalidateRect (hwnd, NULL, FALSE) ; break ; default: // character codes BUFFER (xCaret, yCaret) = (TCHAR) wParam ; HideCaret (hwnd) ; hdc = GetDC (hwnd) ; SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ; TextOut (hdc, xCaret * cxChar, yCaret * cyChar,&BUFFER (xCaret, yCaret), 1) ; DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))); ReleaseDC (hwnd, hdc) ; ShowCaret (hwnd) ; if (++xCaret == cxBuffer) {xCaret = 0

if (++yCaret == cyBuffer) yCaret = 0 ; } break ; } SetCaretPos (xCaret * cxChar, yCaret * cyChar) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ; for (y = 0 ; y < cyBuffer ; y++) TextOut (hdc, 0, y * cyChar, & BUFFER(0,y), cxBuffer) ; DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }