pragma once include WindowOp int getWindowWidth HWND hwnd RECT GetClie

 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
59
60
61
62
63
64
65
66
67
68
#pragma once
#include "WindowOp.h"
int getWindowWidth( HWND hwnd )
{
RECT r;
GetClientRect(hwnd, &r);
return r.right - r.left - MIN_WINDOW_WIDTH;
}
int getWindowHeight( HWND hwnd )
{
RECT r;
GetClientRect(hwnd, &r);
return r.bottom - r.top - MIN_WINDOW_HEIGHT;
}
int getCharWidth( HWND hwnd, char c )
{
HDC hdc;
static int widths[256] = { '0' };
static int filled = 0;
if (!filled)
{
UINT ch;
hdc = GetDC(hwnd);
for (ch = 0; ch < 256; ++ch)
{
GetCharWidth(hdc, (UINT)ch, (UINT)ch, &(widths[ch]));
}
ReleaseDC(hwnd, hdc);
filled = 1;
}
return widths[(UINT)c];
}
int getCharHeight( HWND hwnd )
{
HDC hdc;
TEXTMETRIC tm;
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
ReleaseDC(hwnd, hdc);
return tm.tmHeight;
}
int getLineLength( HWND hwnd, char const * str, int len )
{
SIZE s;
HDC hdc;
hdc = GetDC(hwnd);
GetTextExtentPoint32(hdc, str, len, &s);
ReleaseDC(hwnd, hdc);
return s.cx;
}
int getWindowLineCount( HWND hwnd )
{
return getWindowHeight(hwnd) / getCharHeight(hwnd);
}