Win32 Edit Control

Creating an edit (textbox) control in a Win32 window (hWnd).

Define a unique ID for the edit control:
#define TXT_MYEDIT_ID	502


Create the control after the main Win32 window has been created:
// Create edit control.
CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"", 
	WS_VISIBLE | WS_CHILD | ES_NUMBER,
	95, 9, 90, 20, hWnd, (HMENU)TXT_KEYGUARD_ID, NULL, NULL);


Listen for control activity in your message handler (WndProc):
switch (message) {
case WM_COMMAND:
	wmId    = LOWORD(wParam);
	wmEvent = HIWORD(wParam);
		
	switch (wmId) {
	case TXT_MYEDIT_ID:
		// Your code here.
		break;


Setting and getting text from your edit control:
SetDlgItemText(hWnd, TXT_MYEDIT_ID, "Foo!");
GetDlgItemText(hWnd, TXT_MYEDIT_ID, szBuf, sizeof(szBuf));


This document was last updated February 15th, 2011.
Written by: Dag Jonny Nedrelid
©2007-2012 http://thronic.com


Feel free to leave a comment.
Name:
URL:
0