1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
HFONT createNewFont(HWND dialog, char * fName = "Arial", int fSize=10, int fWeight = FW_BOLD ){
const TCHAR* fontName = _T(fName);
const long nFontSize = (long) fSize;
HDC hdc = GetDC(dialog); // hWnd
LOGFONT logFont = {0};
logFont.lfHeight = -MulDiv(nFontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
logFont.lfWeight = fWeight;
_tcscpy_s(logFont.lfFaceName, fontName);
// A pointer to a LOGFONT structure &logFont defines
// the characteristics of the logical font
HFONT hFont = CreateFontIndirect(&logFont); // hFont - handle to logical font
ReleaseDC(dialog, hdc); // hWnd, hdc
return hFont;
}
void createEditbox1(HWND dialog, int id, int x, int y, int w, int h, HFONT hFont){
HWND hwndEdit = CreateWindowEx(
0, "EDIT", // predefined class
NULL, // no window title
WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
ES_NUMBER,
x, y, w, h, // set size in WM_SIZE message
dialog, // parent window
(HMENU) id, // edit control ID
(HINSTANCE) GetWindowLong(dialog, GWL_HINSTANCE),
NULL); // pointer not needed
// Set font
SendMessage(hwndEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)MAKELONG(TRUE, 0));
// add text to window
SendMessage(hwndEdit, WM_SETTEXT, 0, 0);
}
void Display_Matrix(HWND dialog, int matrixSize = 4){
int w = 23;
int h = 16;
int paddingx = 2;
int paddingy = 2;
int offsetx = 130;
int offsety = 130;
int beginx = offsetx;
int beginy = offsety;
int stepx = w + paddingx;
int stepy = h + paddingy;
int endx = offsetx + ( matrixSize * stepx );
int endy = offsety + ( matrixSize * stepy );
int x, y, i = 0;
int count = matrixSize * matrixSize;
int id = 5000;
HFONT hFont = createNewFont(dialog, "Arial", 8, FW_NORMAL );
for (x = beginx-stepx; x < endx; x += stepx )
for (y = beginy-stepy; y < endy; y += stepy ){
id++;
createEditbox1(dialog, id, x, y, w, h, hFont);
}
}
|