How would I gather the data that a user inputed into a editbox, and then compare it with a string?
Thanks, August.
How would I gather the data that a user inputed into a editbox, and then compare it with a string?
Thanks, August.
GetWindowText(Client_Edit_Message, Buffer, sizeof(Buffer));
strcmp() enter buffer and other string
You make your edit box. <assumed you did this>
Client_Edit_Message = CreateWindowEx(WS_EX_STATICEDGE, "Edit", "", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 1, 135, 400, 20, hWnd, NULL, g_hInst, 0);
SendMessage(Client_Edit_Message, WM_SETFONT, (WPARAM)hDefaultFont, MAKELPARAM(FALSE, 0));
then when user enters data in Client_Edit_Message box window you use GetWindowText(Client_Edit_Message, Buffer, sizeof(Buffer));
you declared a Buffer[] to store your data from the window and the sizeof tell the functions howmuch to store in your Buffer[] variable.
use strcmp() to compare the string you want to compare. ie test = strcmp( buffer , teststring );
in winpr0c typicaly when a button has been pressed with case BN_CLICKED: message sent the getwindowtext is used so the proggie knows when valid data is there. ok?
Last edited by kryptkat; 05-10-2005 at 01:02 PM.
Well I tried this:
No errors, but it doesn't work. What did I do wrong?Code:char Sgr[2]; HWND hEdit; case WM_CREATE: { HFONT hfDefault; hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 5, 170, 386, 75, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL); SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0)); if(hEdit == NULL) { MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);} else { } break; } case WM_LBUTTONDOWN: { GetWindowText(hEdit, Sgr, sizeof(Sgr)); if (lstrcmp(Sgr,_T("w1"))==0) { MessageBox(hwnd, "gOOD, iT WORKS!", "wOW!", MB_OK ); } break; }
For one you are missing the switchcase() wich should belong to the winmain() or the proc.
just started looking at it. that was the first i noticed let me look some more or get you an example.
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
then your case here:
you also need
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
it is not a compleat prog.
edit:
You need to decide what type of window you want. You have the editbox. and reg the window.
you need a message loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
and the window procedure see above code.
Last edited by kryptkat; 05-11-2005 at 08:39 PM.
And the handle to the edit will have lost scope (as soon as the WN_CREATE was processed).
Use a static HWND
Or use
GetWindowText( GetDlgItem(hwnd , IDC_MAIN_EDIT) ,.......
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
I got it working. Thanks, for the help guys.
Last edited by Queatrix; 05-12-2005 at 10:06 AM.