Struggling to read text from Edit Control (box)
Tried few attempts but not winning.. My code creates an edit box and a button. I expect to type some text on the edit box then after pressing the button the text should be displayed on the frame to show that it was read successfully... This is with no avail...
here's my code
Code:
// Creating Controls...
case WM_CREATE:
{
editCntrl = OnCreate(hwnd,cs,initRecArea(100,15,100,20));
CreateButton(hwnd,cs->hInstance,BS_DEFPUSHBUTTON,initRecArea(305,320,150,30),
IDBC_DEFPUSHBUTTON,_T("DISPLAY"));
return 0;
}
//after button press
case WM_COMMAND:
if (LOWORD(wParam) == IDBC_DEFPUSHBUTTON)
{
GetDlgItemText(hwnd, IDCE_DLG, szString, 80);
printText(hwnd, szString, initRecArea(15,25,0,0), hdc);
}
// Function to display text
void printText(HWND hWnd, TCHAR txt[], RECT& rc, HDC hDC)
{
HDC hdc = GetDC(NULL);
long lfHeight = -MulDiv(12, GetDeviceCaps(hDC, LOGPIXELSY), 72);
ReleaseDC(NULL, hdc);
HFONT font = CreateFont(lfHeight, 0, 0, 0, FW_BOLD, FALSE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
SelectObject(hDC, font);
SetBkColor(hDC, g_rgbBackground);
TextOut(hDC, rc.left, rc.top, txt, (int)_tcslen(txt));
DeleteObject(font);
}
I suspect it may have to do with the first argument of GetDlgItemText()... the handle