Free Educational Resource Center for teachers and students. Includes Interviews,
Sourcecode, Free Software, Research Papers, Articles, Tutorials and much more..
     R E S E A R C H A C T I V I T Y . C O M
Our Fellow Research Center for Ph.D Schollars
Home About Submit & Earn Archives: C And C + + Programming » Dev Packages » Interviews » Php Mysql Programming » Windows Programming
search
Windows Programming > create a textbox and track change event in winapi

Create a Textbox / Edit control and track change event

In this example we will create a simple dialog and a simple edit control on it (text box), and track the change by the user, i.e when user changes the text in the text box. A very simple to understand win32 api code.



#include <windows.h>

int textbox_id = 156;

BOOL WINAPI myProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_CLOSE)
PostQuitMessage(0);

//check if text in textbox has been changed by user
if(message==WM_COMMAND && HIWORD(wParam)==EN_CHANGE && LOWORD(wParam)==textbox_id)
{
//text in the textbox has been modified
//do your coding here
}

return false;
}

int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
MSG msg;
HWND myDialog = CreateWindowEx(
0,WC_DIALOG,"My Window",WS_OVERLAPPEDWINDOW | WS_VISIBLE,
400,100,200,200,NULL,NULL,NULL,NULL
);
//create the textbox
CreateWindowEx(
WS_EX_CLIENTEDGE, //special border style for textbox
"EDIT","Modify me",WS_VISIBLE | WS_CHILD,
10,50,170,50,myDialog,(HMENU)textbox_id,NULL,NULL
);

SetWindowLong(myDialog, DWL_DLGPROC, (long)myProc);

while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
}