Polibiy:
Polibiy.cpp
#include "stdafx.h"
#include "Polibiy.h"
#include "PolibiyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CPolibiyApp
BEGIN_MESSAGE_MAP(CPolibiyApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CPolibiyApp construction
CPolibiyApp::CPolibiyApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CPolibiyApp object
CPolibiyApp theApp;
// CPolibiyApp initialization
BOOL CPolibiyApp::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
CPolibiyDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
StaticTable.cpp
#include "stdafx.h"
#include "StaticTable.h"
// StaticTable
IMPLEMENT_DYNAMIC(StaticTable, CStatic)
StaticTable::StaticTable()
{
col = 1;
row = 1;
colWidth = 1;
rowHeight = 1;
data.resize(col*row);
}
StaticTable::~StaticTable()
{
}
void StaticTable::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
DrawHeaders(lpDrawItemStruct->hDC);
DrawContents(lpDrawItemStruct->hDC);
}
void StaticTable::DrawHeaders(HDC hDC)
{
wchar_t str[4] = {0};
int strLength = 0;
RECT place;
SIZE strSize;
GetClientRect(&place);
Rectangle(hDC, place.left, place.top, place.right, place.bottom);
HPEN pen = CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
HFONT font = CreateFont(-15,0,0,0,FW_DONTCARE,false,false,false,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH,
NULL);
SetBkMode(hDC, TRANSPARENT);
HPEN tempPen = (HPEN)SelectObject(hDC, pen);
HFONT tempFont = (HFONT)SelectObject(hDC, font);
COLORREF textColorTemp = SetTextColor(hDC, RGB(128,128,128));
for (int i=1; i<row; i++)
{
MoveToEx(hDC, place.left, place.top+i*rowHeight, NULL);
LineTo(hDC, place.right, place.top+i*rowHeight);
strLength = swprintf(str, 4, _T("%d"), i);
GetTextExtentPoint32(hDC, str, strLength, &strSize);
TextOut(hDC, place.left+(colWidth-strSize.cx)/2,
place.top+i*rowHeight+(rowHeight-strSize.cy)/2, str, strLength);
}
for (int i=1; i<col; i++)
{
MoveToEx(hDC, place.left+i*colWidth, place.top, NULL);
LineTo(hDC, place.left+i*colWidth, place.bottom);
strLength = swprintf(str, 4, _T("%d"), i);
GetTextExtentPoint32(hDC, str, strLength, &strSize);
TextOut(hDC, place.left+i*colWidth+(colWidth-strSize.cx)/2,
place.top+(rowHeight-strSize.cy)/2, str, strLength);
}
SetTextColor(hDC, textColorTemp);
SelectObject(hDC, tempPen);
SelectObject(hDC, tempFont);
DeleteObject(pen);
DeleteObject(font);}