Originally Posted by
arjunajay
I'm not sure but don't you need the edit ctrl's HDC to get the font it is using?
I don't see any GetDC() call. Infact I don't even see a HDC variable.
Shouldn't be necessay as I already have the font.
Actual code:
Code:
case WM_CREATE:
{
HFONT font;
LOGFONT f;
font = CreateFont(-MulDiv(10, GetDeviceCaps(GetDC(hwnd), LOGPIXELSY), 72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("MS Shell Dlg"));
if (font == NULL) {
Error();
PostQuitMessage(1);
break;
}
channel = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""),
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL,
0, 0, 0, 0, hwnd, (HMENU) IDC_CHANNEL, GetModuleHandle(NULL), NULL);
if (channel == NULL) {
Error();
PostQuitMessage(1);
break;
}
SendMessage(channel, WM_SETFONT, (WPARAM) font, MAKELPARAM(FALSE, 0));
input = CreateWindowEx(inputexstyle, TEXT("EDIT"), TEXT(""), inputstyle, 0, 0, 0, 0, hwnd, (HMENU) IDC_INPUT, GetModuleHandle(NULL), NULL);
if (input == NULL) {
Error();
PostQuitMessage(1);
break;
}
SendMessage(input, WM_SETFONT, (WPARAM) font, MAKELPARAM(FALSE, 0));
_inputproc = (WNDPROC) SetWindowLongPtr(input, GWL_WNDPROC, (LONG_PTR) inputproc);
GetObject(font, sizeof(f), &f);
fonth = f.lfHeight < 0 ? -f.lfHeight : f.lfHeight;
bg = CreateSolidBrush(RGB(0x00, 0x00, 0x00));
break;
}
fonth is a static LONG that WM_SIZE uses.
I tried calling GetMapMode() and it did return MM_TEXT. I have also already compared the height before and after AdjustWindowRectEx call, which tells me that abs(lfHeight) is 13, r.top is -2 and r.bottom is 15.
Two times the point size seems to give me a perfect edit box (i.e. fonth = 2*10, but this solution isn't applicable for large sizes.
Code:
case WM_SIZE:
{
RECT ca;
RECT r = {0, 0, 0};
GetClientRect(hwnd, &ca);
ca.right -= 2*MARGIN;
r.bottom = fonth;
AdjustWindowRectEx(&r, inputstyle, FALSE, inputexstyle);
r.bottom -= r.top;
SetWindowPos(input, NULL, MARGIN, ca.bottom - r.bottom - MARGIN, ca.right, r.bottom, SWP_NOZORDER);
ca.bottom -= 3*MARGIN + r.bottom;
SetWindowPos(channel, NULL, MARGIN, MARGIN, ca.right, ca.bottom, SWP_NOZORDER);
break;
}
Looks like a mIRC window but without the list box containing users.
Attaching the source.