1. CreateFont
폰트를 만들기 위해 필요한 함수 (핸들은 HFONT)
HFONT CreateFont(int nHeight, int nWidth, int nEscapement, int nOriention, int fnWeight, DWORD fdwltalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet, DWORD fdwOutPrecision, DWORD fdwCilpPrecision, DWORD fdwQuality, DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
이 중 실질적으로 변경해야 할 필요가 있는 인수는 문자의 크기를 지정하는 nHeight와 글꼴모양을 지정하는 lpszFace이다.
2. 텍스트의 색상
폰트 오브젝트외에 출력되는 문자열에 영향을 주는 여러 가지 함수가 있다.
COLORREF SetTextColor(HDC hdc, COLORREF crColor); //글자색상 설정
COLORREF SetBkColor(HDC hdc, COLORREF crColor); //글자배경색 설정
int SetBkMode(HDC hdc, int iBkMode); //배경색모드 설정
iBkMode에 넣을 수 있는 인수
3. 글자 회전시키기
CreateFont 함수의 세 번째 인수인 nEscapement를 0~900까지 100단위로, 즉 각도를 10단위로 계속 증가 시키며 문자열을 출력,
i값이 증가할 때마다 매번 MyFont를 만들고 출력이 끝난 후 MyFont를 삭제하고 있다.
폰트를 만들기 위해 필요한 함수 (핸들은 HFONT)
HFONT CreateFont(int nHeight, int nWidth, int nEscapement, int nOriention, int fnWeight, DWORD fdwltalic, DWORD fdwUnderline, DWORD fdwStrikeOut, DWORD fdwCharSet, DWORD fdwOutPrecision, DWORD fdwCilpPrecision, DWORD fdwQuality, DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
인 수 |
설 명 |
nHeight |
폰트의 크기 설정 |
nWidth |
폰트의 폭 설정 |
nEscapement |
폰트의 각도를 0.1도 단위 설정 |
nOriention |
글자한자와 X축과의 각도를 지정 |
fnWeight |
폰트의 두께 설정 |
fdwltalic |
기울임체 설정 |
fdwUnderline |
밑줄 설정 |
fdwStrikeOut |
관통선 설정 |
fdwCharSet |
문자코드와 문자의 대응관계를 정의하는 문자셋 |
fdwOutPrecision |
출력 정확도 설정 |
fdwCilpPrecision |
클리핑 정확도 설정 |
fdwQuality |
논리적 폰트를 물리적 폰트에 얼마나 근접시킬것인가 지정 |
fdwPitchAndFamily |
폰트의 피치와 그룹을 설정 |
lpszFace |
글꼴의 이름을 나타내는 문자열을 설정 |
이 중 실질적으로 변경해야 할 필요가 있는 인수는 문자의 크기를 지정하는 nHeight와 글꼴모양을 지정하는 lpszFace이다.
#include "MsgProc.h"
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont, OldFont;
TCHAR *str = TEXT("폰트 Test 1234");
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
hdc = BeginPaint(hWnd, &ps);
hFont = CreateFont(50,0,0,0,0,0,0,0,HANGEUL_CHARSET,0,0,0,VARIABLE_PITCH|FF_ROMAN,TEXT("궁서"));
OldFont = (HFONT)SelectObject(hdc,hFont);
TextOut(hdc,100,100,str,lstrlen(str));
SelectObject(hdc,OldFont);
DeleteObject(hFont);
EndPaint(hWnd, &ps);
return 0;
}
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont, OldFont;
TCHAR *str = TEXT("폰트 Test 1234");
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
hdc = BeginPaint(hWnd, &ps);
hFont = CreateFont(50,0,0,0,0,0,0,0,HANGEUL_CHARSET,0,0,0,VARIABLE_PITCH|FF_ROMAN,TEXT("궁서"));
OldFont = (HFONT)SelectObject(hdc,hFont);
TextOut(hdc,100,100,str,lstrlen(str));
SelectObject(hdc,OldFont);
DeleteObject(hFont);
EndPaint(hWnd, &ps);
return 0;
}
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
2. 텍스트의 색상
폰트 오브젝트외에 출력되는 문자열에 영향을 주는 여러 가지 함수가 있다.
COLORREF SetTextColor(HDC hdc, COLORREF crColor); //글자색상 설정
COLORREF SetBkColor(HDC hdc, COLORREF crColor); //글자배경색 설정
int SetBkMode(HDC hdc, int iBkMode); //배경색모드 설정
iBkMode에 넣을 수 있는 인수
인 수 |
설 명 |
OPAQUE |
불투명한 배경을 사용, 그래서 배경 색상에 의해 뒤쪽의 그림이 지워진다. |
TRANSPARENT |
투명한 배경색상을 사용, 그래서 문자를 출력한 후에도 배경이 바뀌지 않는다. 문자획 사이의 여백에 있는 원래 배경이 지워지지 않는다 |
#include "MsgProc.h"
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont, OldFont;
TCHAR *str = TEXT("폰트 Test 1234");
HBRUSH MyBrush, OldBrush;
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
hdc = BeginPaint(hWnd, &ps);
MyBrush = CreateHatchBrush(HS_CROSS,RGB(0,0,255));
OldBrush = (HBRUSH)SelectObject(hdc,MyBrush);
Rectangle(hdc,50,50,400,200);
SelectObject(hdc,OldBrush);
hFont = CreateFont(30,0,0,0,0,0,0,0,HANGEUL_CHARSET,0,0,0,VARIABLE_PITCH|FF_ROMAN,TEXT("궁서"));
OldFont = (HFONT)SelectObject(hdc,hFont);
SetTextColor(hdc,RGB(255,0,0));
SetBkColor(hdc,RGB(255,255,0));
TextOut(hdc,100,100,str,lstrlen(str));
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc,100,150,str,lstrlen(str));
SelectObject(hdc,OldFont);
DeleteObject(MyBrush);
DeleteObject(hFont);
EndPaint(hWnd, &ps);
return 0;
}
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
HDC hdc;
PAINTSTRUCT ps;
HFONT hFont, OldFont;
TCHAR *str = TEXT("폰트 Test 1234");
HBRUSH MyBrush, OldBrush;
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
hdc = BeginPaint(hWnd, &ps);
MyBrush = CreateHatchBrush(HS_CROSS,RGB(0,0,255));
OldBrush = (HBRUSH)SelectObject(hdc,MyBrush);
Rectangle(hdc,50,50,400,200);
SelectObject(hdc,OldBrush);
hFont = CreateFont(30,0,0,0,0,0,0,0,HANGEUL_CHARSET,0,0,0,VARIABLE_PITCH|FF_ROMAN,TEXT("궁서"));
OldFont = (HFONT)SelectObject(hdc,hFont);
SetTextColor(hdc,RGB(255,0,0));
SetBkColor(hdc,RGB(255,255,0));
TextOut(hdc,100,100,str,lstrlen(str));
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc,100,150,str,lstrlen(str));
SelectObject(hdc,OldFont);
DeleteObject(MyBrush);
DeleteObject(hFont);
EndPaint(hWnd, &ps);
return 0;
}
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
3. 글자 회전시키기
#include "MsgProc.h"
HDC hdc;
PAINTSTRUCT ps;
int i;
HFONT MyFont, OldFont;
TCHAR *str = TEXT(" Beautiful Korea");
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
hdc = BeginPaint(hWnd, &ps);
SetBkMode(hdc,TRANSPARENT);
for(i=0; i<900; i+=100)
{
MyFont = CreateFont(50,0,i,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH|FF_SWISS,TEXT("Times New Roman"));
OldFont = (HFONT)SelectObject(hdc,MyFont);
TextOut(hdc,0,450,str,lstrlen(str));
SelectObject(hdc,OldFont);
DeleteObject(MyFont);
}
EndPaint(hWnd, &ps);
return 0;
}
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
HDC hdc;
PAINTSTRUCT ps;
int i;
HFONT MyFont, OldFont;
TCHAR *str = TEXT(" Beautiful Korea");
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
hdc = BeginPaint(hWnd, &ps);
SetBkMode(hdc,TRANSPARENT);
for(i=0; i<900; i+=100)
{
MyFont = CreateFont(50,0,i,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH|FF_SWISS,TEXT("Times New Roman"));
OldFont = (HFONT)SelectObject(hdc,MyFont);
TextOut(hdc,0,450,str,lstrlen(str));
SelectObject(hdc,OldFont);
DeleteObject(MyFont);
}
EndPaint(hWnd, &ps);
return 0;
}
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
CreateFont 함수의 세 번째 인수인 nEscapement를 0~900까지 100단위로, 즉 각도를 10단위로 계속 증가 시키며 문자열을 출력,
i값이 증가할 때마다 매번 MyFont를 만들고 출력이 끝난 후 MyFont를 삭제하고 있다.
'API' 카테고리의 다른 글
컨트롤(체크박스) (0) | 2011.09.20 |
---|---|
컨트롤(버튼) (0) | 2011.09.19 |
비트맵 (0) | 2011.09.15 |
색, 브러시, 투명 오브젝트 (0) | 2011.09.09 |
TextOut 예제 (0) | 2011.08.23 |