,,,
MFC. MFC. MFC Visual C++
MFC. CObject ( /) →CGDIObject ( ); CDC (, ); CExeption ( MFC); CFile ( ); CMenu ( ); CCmdTarget ( )1)→CWnd ( ); FrameWnd; 2)→CWinThread;CwinApp;
MFC . MFC , , 2 . CWnd CWinThread. : 1) , CWinApp. 2) , CFrameWnd. 3) InitInstance(). 4) Create . 5) . 6) . 7) .
//App.h class CApp: public CWinApp {public: BOOL InitInstance ();}; Class CMainWin:public CFrameWnd {public: CMainWin (); DECLARE_MESSAGE_MAP () }; |
//App.cpp #include <afxwin.h> #include App.h BOOL CApp::InitInstance () {m_pMainWnd=newCMainWin;m_pMainWnd→ShouWindow (m_nCmdShow); m_pMainWnd→UpdateWindow (); return TRUE;} CMainWin::CMainWin () {Create (NULL, MFC-);} CApp App; BEGIN_MESSAGE_MAP (CMainWin, CFrameWnd) END_MESSAGE_MAP () |
MFC - (Microsoft Foundation Class Library) ; MFC. MFC , C++. CObject, , , , , , . . , CObject, RUNTIME _CLASS(). C++ RTTI, , MFC, .
. , CObject, . MFC .
. - , , , , . , .
. CObject. CCmdTarget, CFile, CDC, CGDIObject CMenu. CCmdTarget . CFile . CDC . . GDI. CGDIObject DGI-, , , . CMenu . CCmdTarget CWnd. , ("") , . CFrameWnd. , . CCmdTarget, CWinThread, , , , MFC- : WinApp. , . . , .
- MFC. , MFC-, , . API - MFC. , API . , - MFC.
MFC. . Afx. ( MFC , AFX, Application Framework. AFX MFC, .) , AfxMessageBox(), . - MessageBox(). , -. AFXWIN.H. MFC- AFXWIN.H. , , , , MFC. , MFC, WINDOWS.H, Windows API , "" APL.
MFC-. , MFC, , : , , , . , CWinApp, - CFrameWnd. . , , Windows. , . MFC , . , . . CFrameWnd. CMainWin. DECLARE_MESSAGE_MAP(). , , - Windows. , . . Create(). . . . , , NULL.
CWinApp. . - : virtual BOOL CWinApp::lnitlnstance(); , . , . TRUE FALSE . , CMainWin, m_pMainWnd. CWinThread. CWnd* MFC-, . - . , : BOOL CWnd::ShowWindow(int How);
. Windows , . . Windows ( API) . switch , . . MFC . .
MFC. MFC - , . , , . . : . - , . -.
2. , , WM_HAR, WM_PAINT
, Windows-, , . , .
, . , , .
Windows- GetDC(), ReleaseDC(). Windows , , . MFC , . , CClientDC . , ReleaseDC() . ClientDC :
ClientDC (CWnd *Windows);
Windows , . this.
TextOut():
virtual BOOL CDC::TextOut(int X, int Y, LPCSTR lpszStr, int Length);
X, Y ( ), lpszStr , , Length . - (1, 1) .
char str [80]; //
void CMainWin::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{CClientDC dc(this); //
dc.TextOut(1,1," ", 3); //
wsprintf(str,"%", ch); //
dc.TextOut(1, 1, str, strlen(str)); // (1, 1)
}
, , , CClientDC. WM_PAINT.
WM_PAINT. . .. , , .
WM_PAINT ON_WM_PAINT(), OnPaint(). :
WM_PAINT
void CMainWin::OnPaint()
{CPaintDC dc(this); //
dc.TextOut(1,1, str, strlen(str)); //
}
OnPaint(), , OnChar(), . , , CPaintDC. CClientDC, , CPaintDC .
, Windows , WM_PAINT. , , , , , ... . , WM_PAINT, InvalidateRect() CWnd, :
void CWnd::InvalidateRect(LPCRECT lpRegion, BOOL Erase=TRUE);
lpRegion , , Erase , TRUE . NULL, . InvalidateRect() WM_PAINT OnPaint().
, :
InvalidateRect(NULL);
, . , , :
Rect region(10,10,100,100);
InvalidateRect(region);
, (10,10) (100,100). , , WM_TIMER.
3. MFC. , , ,
Windows . ( , , ), .
, Windows, . (typeface) - , . : Arial, Times New Roman, MS Sans Serif. - , , - . 1/72 . . - . Windows : (normal), (italic), (bold) (bold italic). , (fixed pitch', - Courier New, (variable pitch), - Times New Roman.
Windows : ( - MS Sans Serif, Fixedsys) TrueType ( - Arial, Courier New). . . , . TrueType - , . . ( 30 ) . (). - , . TrueType , Windows (Times New Roman, Arial Courier New), .
MFC CDC::TextOut(). . , . . . , .
TextOutQ ( ) . :
virtual COLORREF CDC::SetTextColor(COLORREF Color); virtual COLORREF CDC::SetBkColor(COLORREF Color);
. COLORREF 32- - , , 8 . RGB().
SetBkMode() . : int CDC::SetBkMode(int Mode);
, ( ) . : OPAQUE TRANSPARENT. . ( ""). OPAQUE.
, . , , . Windows , .
, , . :
BOOL CDC::GetTextMetrics(LPTEXTMETRICS TextAtttrib) const; TEXTMETRIC, . . :
LONG tmHeight
LONG tmAscent
LONG tmDescent
LONG tmlntemalLeading
LONG tmExternalLeading
LONG tmMaxCharWidth
tmHeight tmExternalLeading. , .
, CFont, ( , ). - SelectObject(), - . . , .
:
, CFont , , . , . , , , , . , MFC Windows . , , :
BOOL CFont: :CreateFont(int nHeight, int nWidth,
int nEscapement,
int nOrientation,
int nWeight,
BYTE bltalic,
BYTE bUnderline,
BYTE cStrikeOut,
BYTE nCharSet,
BYTE nOutPrecision,
BYTE nClipPrecision,
BYTE nQuality,
BYTE nPitchAndFamily,
LPCTSTR IpszFacename);
, .
, , : , , a Windows . , ( ). - , . . , PostScript. , , , ( , ). , . , : , , , , .
, , , . CreateFontQ .
, . , ( mjpFoni):
void CMainFrame::SetClientFont(CString Typeface, //
int Size, //
BOOL Bold, //
BOOL Italic //
}
{
//
CWindowDC winDC(this);
// ,
int pixelsPerlnch = winDC.GetDeviceCaps(LOGPIXELSY);
// Size
int fontHeight = -MulDiv(Size, pixelsPerlnch, 72);
// CreateFont()
int Weight = FW_NORMAL;
if(Bold)
Weight = FWBOLD;
// CreateFont().
delete m pFont;
mjpFont = new CFont;
// . .
m_pFont->CreateFont(fontHeight, 0, 0, 0, Weight, Italic, , ,
DEFAULT_CHARSET,OUT_DEFAULT PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, Typeface);
}
1. .., .. . - .: . ., 2007.- 271 .
2. " " ". 2005.
3. . .. . 1999.
MFC. MFC. MFC Visual C++ MFC. CObject ( /) →CGDIObject ( ); CDC (,
Copyright (c) 2024 Stud-Baza.ru , , , .