키보드로 어떤 값을 입력 받기 위해 가장 먼저 배운 함수는 scanf()였다.

그러나 scanf()함수는 단어 입력 함수로, 공백을 포함한 문자열을 읽기 어렵다.

예를 들어"kim hyo jeong"이라고 입력받고 출력할 경우 "kim"만 출력되는 식이다.

이런 이유로 문자열 입력의 대부분은 C 표준 라이브러리 함수인 gets()함수로 처리한다.

 

1. gets()

사용자가 <Enter>키를 입력할 때까지 문자들을 읽으며(개행문자가 나타날 때까지), 이 문자들은 포인터가 가리키는 배열에 저장한다.

문자열의 경우 공백을 포함하는 경우가 많기 때문에 scanf()함수보다 gets()함수를 많이 사용 한다.

 

1.1 gets()함수의 원형

char *gets(char *string);

 

2. puts()

string이 가리키는 문자열을 화면에 출력하며, 자동으로 줄 바꿈('\n')기능을 포함한다.

 

2.1 puts()함수의 원형

int puts(char *string);

Posted by 마마필로 :

C언어에서 제공하는 문자열 처리함수를 이용하기 위해서는 <STRING.H>헤더파일이 필요하다.

 

<자주 사용되는 문자열 처리 함수>

1. strcpy(to, from)

원형: char *strcpy( char *strDestination, const char *strSource );

기능: from의 문자열이 to에 복사된다. 배열의 경계를 검사하지 않는다.

 

2. strcat(to, from)

원형: char *strcat( char *strDestination, const char *strSource );

기능: 문자열을 결합시켜 준다. 즉, from의 문자열이 to에 추가된다. 배열의 경계를 검사하지 않는다.

 

3. strlen(str)

원형: size_t strlen( const char *string );

기능: 문자열의 길이, 즉 문자 수를 반환한다. null 문자는 포함되지 않는다.

 

4. strcmp(str1, str2)

원형: int strcmp( const char *string1, const char * string2 );

기능: 두 문자열을 비교하여 다음 중 하나의 Return Value를 반환한다.

0: str1, str2 두 문자열이 같다.

양수: str1이 str2 보다 크다.

음수: str1이 str2 보다 작다.

Posted by 마마필로 :

■ 윈도우 기반의 응용프로그램을 만들 수 있는 세가지 개발 환경

1. CPP-MFC

2. Win32(WinAPI)-SDK

3. CS-WinForm

 

그밖에,

RAD Tool(Visual Basic, Delphi, Power Builder 등)이 있으나 기능이 제한적임.

 

■ 함수 이름 짓기

초기화..INITIALIZE...(INITINSTANCE..)

메세지루프..RUN...

메시지처리..HANDLE...(or) 처리하는 행동자체를 이름으로 쓰기도 함(LBUTTONDOWN과 같이)

→ 이름만으로 예측가능한, 실제 동작을 반영하여 짓는다.

 

■ 코드 비교

1. CSWINFORM (C#)

1.1 InitializeComponent() 

private void InitializeComponent()        //윈도우 사양 결정, 가장 먼저 실행되어야 함

        {
            this.SuspendLayout();
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(309, 282);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

1.2

namespace CSWINFORM
{
    static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]

 // STA(Single Thread Apartment): 애플리케이션 스레드의 모델을 단일 스레드로 지정하는 속성. 다중 스레드를 사용하지 않는다는 것을 의미하기도 한다. 메시지 루프가 돌려면 스레드가 필요.
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());        // C#에서 메시지 루프
        }
    }
}

 

내가 구현한적이 없는 함수가 실행될때는 정의로 이동하여 원형/요약 확인. 보다 더 정확한 사용을 보기 위해서는 msdn이용 한다.

 

2. CSDK

 

 

3. Mfc


Posted by 마마필로 :

프로젝트 생성시 옵션설정에 따라,

공통적으로 존재하는 3개의 클래스.

1. App

2. MainFrame

3. View

 

C#(WinForm)

C(WinAPI)

C++(MFC)

어떤것으로 짜든, windows api를 사용하게 됨

이것이 하드웨어로 연결

 

CAPP: 전역데이터 함수 관리. 화면 출력과는 크게 관계 없음.

CView: 윈도우의 view영역 관리.

CMainFrame: 그 외 나머지.(예를 들어 상태 표시줄 관리는 이 클래스에서 가능)

 

CAPP → CMainFrame → Cview 순으로 실행되고, 실제 가장 많이 사용되는 것은 CView이다.

 

두 개의 클래스를 동시에 상속받고자 할 때

1. C#에서 지원하지 않는 다중상속을 지원한다.

2. 하나씩 상속받은 두 개의 클래스를 생성하고, 또 다른 클래스를 만들어 하나는 상속, 하나는 호출하여 사용한다.

 

■ MFC의 기본클래스 4개

보이는 클래스-CView, CDocument

보이지 않는 클래스-CAPP, CMainFrame

 

■ 메시지펌핑

메시지 펌핑(MFC)-스레드를 돌려 계속 돌게하고 데이터가 있을때마다 가져오게 하는 것

(WinAPI에서는 메시지 루프와 같은 기능)

 

■ MFC에서의 메시지 처리 루틴(다음시간)

 

ex)

BITMAP파일(정보구조체와 값구조체로 구성)

비트맵파일을 불러오는 함수는 어느 클래스에?

View vs. Document(여러개의 그림파일을 동시에 불러올 수 있음)

 

■ 같은 기능이라도 어떤 프로그램이냐에 따라 구현되어야 하는 클래스가 다르다.

프로그램의 흐름(flow)에 따라 이벤트 발생지점을 파악하여 적절한 클래스에 함수를 구현해 주어야 한다.

 


Posted by 마마필로 :

■ 클래스 소속밝히기

소속된 클래스 이름::함수 이름

Cmfc0331View::Cmfc0331View()

 

■ CObject

:MFC의 최상위 클래스

닷넷에서 최상위 클래스인 Object클래스의 역할과 거의 비슷(닷넷의 오브젝트 클래스-기본 자료형을 가지고 있음)

따라서, CObject클래스에서 파생된 클래스는 모든 데이터 타입을 사용할 수 있다.

 

MFC를 자세히 공부하기 위해서 CObject클래스 부터 파생된 클래스로 학습.

클래스의 내부요소를 자세히 설명해 놓은것이 msdn이다.

 

■ C++클래스에서 함수의 선언부와 구현부(C#과의 차이)

C#의 경우 클래스내에 필드블럭/메서드블럭으로 구분되었다.

메서드의 구현부에서 바로 구현하였을 뿐, 메서드의 선언부를 따로 두지 않았다.

 

그러나 C++은 함수가 구현되면 함수의 선언부가 반드시 코드 블럭내에 존재해야 한다.

미리 선언하지 않은 함수는 소속을 밝히더라도 멤버가 아니라는 에러가 발생한다.

해당 클래스에 미리 함수의 선언부를 작성해 주어야 한다.

선언부 없이 구현부만 존재할 경우 에러발생 하지만, 선언만 하고 구현하지 않는 것은 괜찮다.

변수를 선언하고 사용하지 않는 것과 같은 원리이다.

 

▷ 함수의 선언부=헤더파일=필드블럭(함수의 선언부는 C#에서의 필드블럭과 같다고 볼 수 있다)

▷ 함수의 구현부=소스파일(.cpp)에 존재=메서드블럭

 

▷ 이렇게 함수를 선언부와 구현부를 분리해서 작성하는 이유

1. 구현부를 보여 줄 필요가 없기 때문에.

헤더파일에서 선언부만 보아도 함수의 용도를 알 수 있기 때문에 구현부를 보여줄 필요가 없다.

그러나 C#은 선언부가 없기 때문에 구현되는 코드 전체를 보여주어야 한다.

2. 코드 길이가 너무 길어지는 것을 막기 위해.

 

■  전역함수 및 변수

어떤 클래스에도 소속되지 않은 함수 혹은 변수를 만들때

프로젝트 내의 어떤 부분에 두어도 상관 없다.

'클래스 뷰'의 '전역 함수 및 변수'에서 해당 함수 또는 변수를 더블클릭하면 그 위치를 찾을 수 있다.

 

전역함수의 경우 함수 원형을 선언하지 않아도 된다.

C의 표준라이브러리 함수 사용 가능.(함수 원형 선언 없이)

 

C++에서 전역함수나 변수는 C#에서의 의미와는 차이가 있다.

전역이라고 하더라도 어디서든 자유롭게 쓸 수 있는 것은 아니다.

같은 함수명(변수명)으로 선언된 전역함수(전역변수)라 할지라도 클래스 별로 그 의미는 다르다.(같은 것이라고 볼 수 없다)

선언된 클래스 내에서만 사용할 수 있다.


Posted by 마마필로 :

■ MFC(Microsoft Foundation Class)

: c와 c++로 만든 개체지향기반의 마이크로소프트웨어에서 만든 프레임웍

 

■ Document와 View

 

가장 큰 윈도우는 바탕화면(Window) → 표준윈도우(Window) → 대화상자(Dialog Box), 최소/최대화버튼이 없고, 대신 물음표가 있다) → Message Box → Control(확인버튼 같은 것)

 

□ Document:부모 윈도우의 클라리언트 영역. Document는 출력하지 않는다. 자식 윈도우의 출력사양을 결정해 준다

 

□ View:윈도우의 클라이언트 영역만을 의미(윈도우의 클라이언트 영역=MFC에서는 View). API로 보면 부모윈도우에 자식윈도우를 띄웠을 때, 클라이언트 영역만 있는 자식윈도우에 해당.

따라서, 자식윈도우를 하나 만드면 view가 1개, 자식윈도우를 두개 만드면 view가 2개

 

■ Application Frameworks

API는 정교한 조작(?)에 의해 개발해야 하기 때문에 생산 기간이 길다.

따라서 생명주기가 긴 장비 안에 들어가는 프로그램 개발에 주로 사용된다.(ATM, 자동차 내부 등)

 

지나치게 긴 개발 기간을 단축하기 위해 프레임웍을 생각.

프레임 웍 개발을 위해 AFX(Application Framework technology development group)를 만들고 AFX 1.0으로 개발.

이후 MFC라는 이름으로 개발됨.

MFC는 다운로드 할 필요없이(닷넷 프레임웍은 따로 설치가 필요) 윈도우즈 운영체제 내에 설치 되어 있으므로

윈도우즈 운영체제를 기반으로 한다면,  MFC로 개발한 모든 프로그램은 실행 가능하다.

 

C++로 만든이유

객체 지향 언어이기 때문에.

객체 지향 언어에서만 숨기는 것(변수, 함수 등)이 가능하다.

C++은 C를 포함한다.

 

Win API와 MFC를 이용하면 윈도우 기반 OS에서 구동되는 모든 프로그램은 개발 가능 해진다.

 

MFC는 새로운 버전이 이전 버전을 다 포함한다.

.net Framework의 경우 운영체제의 버전에 상관없이 프레임웍의 버전만 수정해서 운영체제의 버전에 맞는 프레임웍을 설치해야 한다.

새로운 프레임웍 버전에서는 이전의 함수를 수정해 버린다.

반면,  MFC는 이전 버전의 함수도 새 버전에 다 포함시켜 놓고, 운영체제의 버전을 체크하여 버전에 관계없이 실행할 수 있게 한다.

 

▶ MFC의 장점

윈도우 어플리케이션의 개발 기간 단축.

윈도우 기반 운영체제라면 별다른 설치 없이 이용 가능.

상위 버전이 이전 버전을 포함-버전 간 호환 가능.

 

■ MFC의 구성

1) 일반적인 용도를 위한 class

2) Exception-handling class: 예외 처리를 위한 함수 제공. 메모리/입출력 에러, OLE(Object Linking and Embeded)-프로그램 안에 다른 프로그램이 존재. 그런 프로그램의 데이타베이스에서 오는 에러 등의 처리를 위한 함수 제공.

3) Collection class

 

컬렉션을 사용하는 이유

소프트웨어에서 다루어야 하는 데이터의 양이 많아짐.

데이터의 크기가 커질때 문제점-원하는 데이터를 찾기가 어려워짐, 하나로 다룰 수 있는 데이타타입이 필요

이러한 문제점 해결을 위해 컬렉션 존재. 많은 양의 데이터를 다룰 수 있는 데이터타입을 만들 수 있음.

 

4) Dynamic string class

5) File class

6) Time class

7) 기타(CPoint, CSize, CRect 등)

Posted by 마마필로 :

■ _beginthread, _beginthreadex

스레드(thread)를 만든다.

 

■ Syntax

uintptr_t _beginthread( // NATIVE CODE
   void( __cdecl *start_address )( void * ),
   unsigned stack_size,
   void *arglist
);
uintptr_t _beginthread( // MANAGED CODE
   void( __clrcall *start_address )( void * ),
   unsigned stack_size,
   void *arglist
);
uintptr_t _beginthreadex( // NATIVE CODE
   void *security,
   unsigned stack_size,
   unsigned ( __stdcall *start_address )( void * ),
   void *arglist,
   unsigned initflag,
   unsigned *thrdaddr
);
uintptr_t _beginthreadex( // MANAGED CODE
   void *security,
   unsigned stack_size,
   unsigned ( __clrcall *start_address )( void * ),
   void *arglist,
   unsigned initflag,
   unsigned *thrdaddr
);

 

■ Parameters

1) start_address : 스레드가 시작되는 곳의 주소(스레드 함수에 대한 주소값)

2) stack_size : 새로운 스레드를 위한 스택의 크기 또는 0

3) arglist : 인수의 목록 또는 NULL (스레드 함수로 전달할 인수)

4) security

5) initflag

6) thrdaddr

 

 

출처: http://msdn.microsoft.com/en-us/library/kdzttdcb(v=VS.90).aspx

'PROGRAMMING > api reference' 카테고리의 다른 글

[Function] InvalidateRect  (0) 2011.03.23
[Structure] TEXTMETRIC  (0) 2011.03.23
함수정리  (0) 2011.03.20
Posted by 마마필로 :

■ InvalidateRect

특정한 윈도우의 업데이트 영역에 rectangle을 추가하는 함수. 업데이트 영역(update region, 무효화영역)이란 다시 그려질 필요가 있는

윈도우 클라이언트 영역의 한 부분을 말한다.

즉, InvalidateRect함수는 특정 영역을 다시 그리도록 해주는 함수이다.(무효화시킴)

 

■ Syntax

BOOL InvalidateRect(
  __in  HWND hWnd,
  __in  const RECT *lpRect,
  __in  BOOL bErase
);

 

■ Parameters

1) hWnd : 변화가 있어 업데이트해야할 윈도우 영역의 핸들. 이 파라미터 값이 NULL이면, 시스템은 이 응용프로그램뿐만 아니라

모든 윈도우를 무효화하고 다시 그린다. 또한, 함수를 리턴하기 전에 WM_ERASEBKGND 와 WM_NCPAINT 메시지를 보낸다.

이 파라미터를 NULL값으로 하는것은 추천하지 않는다.

 

2) lpRect : 무효화할 영역. 이 파라미터가 NULL일경우, 전체 클라이언트 영역이 무효화대상 영역이다.

 

3) bErase : 무효화 영역이 진행될 때 무효화영역 내의 배경을 지울것인가를 결정.

이 파라미터 값이 TRUE일 경우, 배경은 BeginPaint함수가 호출될때 지워지고, FALSE이면 배경은 그대로 남는다.

 

■ Return Value

함수가 성공이면 리턴값은 nonzero, 실패이면 0.

 

 

출처: http://msdn.microsoft.com/en-us/library/dd145002(VS.85).aspx


'PROGRAMMING > api reference' 카테고리의 다른 글

[Function] _beginthread, _beginthreadex  (0) 2011.03.23
[Structure] TEXTMETRIC  (0) 2011.03.23
함수정리  (0) 2011.03.20
Posted by 마마필로 :

TEXTMETRIC

실제적인 문자의 기본적인 정보를 포함하고 있는 구조체.

 

■ Syntax

typedef struct tagTEXTMETRIC {
  LONG  tmHeight;
  LONG  tmAscent;
  LONG  tmDescent;
  LONG  tmInternalLeading;
  LONG  tmExternalLeading;
  LONG  tmAveCharWidth;
  LONG  tmMaxCharWidth;
  LONG  tmWeight;
  LONG  tmOverhang;
  LONG  tmDigitizedAspectX;
  LONG  tmDigitizedAspectY;
  TCHAR tmFirstChar;
  TCHAR tmLastChar;
  TCHAR tmDefaultChar;
  TCHAR tmBreakChar;
  BYTE  tmItalic;
  BYTE  tmUnderlined;
  BYTE  tmStruckOut;
  BYTE  tmPitchAndFamily;
  BYTE  tmCharSet;
} TEXTMETRIC, *PTEXTMETRIC;

 

■ Members

tmHeight

The height (ascent + descent) of characters.

tmAscent

The ascent (units above the base line) of characters.

tmDescent

The descent (units below the base line) of characters.

tmInternalLeading

The amount of leading (space) inside the bounds set by the tmHeight member. Accent marks and other diacritical characters may occur in this area. The designer may set this member to zero.

tmExternalLeading

The amount of extra leading (space) that the application adds between rows. Since this area is outside the font, it contains no marks and is not altered by text output calls in either OPAQUE or TRANSPARENT mode. The designer may set this member to zero.

tmAveCharWidth

The average width of characters in the font (generally defined as the width of the letter x ). This value does not include the overhang required for bold or italic characters.

tmMaxCharWidth

The width of the widest character in the font.

tmWeight

The weight of the font.

tmOverhang

The extra width per string that may be added to some synthesized fonts. When synthesizing some attributes, such as bold or italic, graphics device interface (GDI) or a device may have to add width to a string on both a per-character and per-string basis. For example, GDI makes a string bold by expanding the spacing of each character and overstriking by an offset value; it italicizes a font by shearing the string. In either case, there is an overhang past the basic string. For bold strings, the overhang is the distance by which the overstrike is offset. For italic strings, the overhang is the amount the top of the font is sheared past the bottom of the font.

The tmOverhang member enables the application to determine how much of the character width returned by a GetTextExtentPoint32 function call on a single character is the actual character width and how much is the per-string extra width. The actual width is the extent minus the overhang.

tmDigitizedAspectX

The horizontal aspect of the device for which the font was designed.

tmDigitizedAspectY

The vertical aspect of the device for which the font was designed. The ratio of the tmDigitizedAspectX and tmDigitizedAspectY members is the aspect ratio of the device for which the font was designed.

tmFirstChar

The value of the first character defined in the font.

tmLastChar

The value of the last character defined in the font.

tmDefaultChar

The value of the character to be substituted for characters not in the font.

tmBreakChar

The value of the character that will be used to define word breaks for text justification.

tmItalic

Specifies an italic font if it is nonzero.

tmUnderlined

Specifies an underlined font if it is nonzero.

tmStruckOut

A strikeout font if it is nonzero.

tmPitchAndFamily

Specifies information about the pitch, the technology, and the family of a physical font.

The four low-order bits of this member specify information about the pitch and the technology of the font. A constant is defined for each of the four bits.

 

 

An application should carefully test for qualities encoded in these low-order bits, making no arbitrary assumptions. For example, besides having their own bits set, TrueType and PostScript fonts set the TMPF_VECTOR bit. A monospace bitmap font has all of these low-order bits clear; a proportional bitmap font sets the TMPF_FIXED_PITCH bit. A Postscript printer device font sets the TMPF_DEVICE, TMPF_VECTOR, and TMPF_FIXED_PITCH bits.

The four high-order bits of tmPitchAndFamily designate the font's font family. An application can use the value 0xF0 and the bitwise AND operator to mask out the four low-order bits of tmPitchAndFamily, thus obtaining a value that can be directly compared with font family names to find an identical match. For information about font families, see the description of the LOGFONT structure.

tmCharSet

The character set of the font. The character set can be one of the following values.

  • ANSI_CHARSET
  • BALTIC_CHARSET
  • CHINESEBIG5_CHARSET
  • DEFAULT_CHARSET
  • EASTEUROPE_CHARSET
  • GB2312_CHARSET
  • GREEK_CHARSET
  • HANGUL_CHARSET
  • MAC_CHARSET
  • OEM_CHARSET
  • RUSSIAN_CHARSET
  • SHIFTJIS_CHARSET
  • SYMBOL_CHARSET
  • TURKISH_CHARSET
  • VIETNAMESE_CHARSET

Korean language edition of Windows:

  • JOHAB_CHARSET

Middle East language edition of Windows:

  • ARABIC_CHARSET

  • HEBREW_CHARSET

Thai language edition of Windows:

  • THAI_CHARSET

□ 참고

 

이미지출처: http://blog.naver.com/tais11/40110366169

 

 

원문출처: http://msdn.microsoft.com/en-us/library/dd145132(v=VS.85).aspx

 

'PROGRAMMING > api reference' 카테고리의 다른 글

[Function] _beginthread, _beginthreadex  (0) 2011.03.23
[Function] InvalidateRect  (0) 2011.03.23
함수정리  (0) 2011.03.20
Posted by 마마필로 :

[0322수업[ 스레드

2011. 3. 22. 00:37 from PROGRAMMING/winAPI

...

'PROGRAMMING > winAPI' 카테고리의 다른 글

[0321수업] 키보드/마우스 입력  (0) 2011.03.21
GDI  (0) 2011.03.20
[0318수업] 윈도우 메시지  (0) 2011.03.18
[0317수업] struct SCROLLINFO  (0) 2011.03.17
DC(Device Contexts)  (0) 2011.03.17
Posted by 마마필로 :