Code:
LRESULT CALLBACK EditProc (HWND hWndEdit, UINT msg,
WPARAM wParam, LPARAM lParam)
{
static TCHAR szBuffer[100];
if (msg == WM_KEYDOWN)
{
switch (wParam)
{
case VK_RETURN:
Edit_GetText (hWndEdit, szBuffer, 100);
if (szBuffer == TEXT ("text"))
{
Beep (300, 100);
}
else
{
MessageBox (hWndEdit, szBuffer, NULL, MB_OK);
}
Edit_SetText (hWndEdit, TEXT(""));
PeekMessage (&message, hWndEdit, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE);
break;
}
}
return CallWindowProc (wndProc, hWndEdit, msg, wParam, lParam) ;
}
Upon pressing the Enter key in run time with the Edit Control in focus, Edit_GetText should get the text in the Edit Control and copy it in szBuffer, and if szBuffer is "text", it should beep. However, during run time, when I typed in "text" (without the quotes) in the Edit Control and pressed enter, it instead goes to 'else' and displays what is in szBuffer in a message box, which verifies that szBuffer is "text".
Code:
#include <windows.h>
#include <Windowsx.h>
#include "resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstance;
static TCHAR szAppName[] = TEXT ("Project ZENNOU");
WNDPROC wndProc;
MSG message;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int iCmdShow)
{
WNDCLASS wndclass;
HWND hWnd;
wndclass.lpszClassName = szAppName;
wndclass.lpfnWndProc = WndProc;
wndclass.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON));
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
RegisterClass (&wndclass);
hWnd = CreateWindow (szAppName, szAppName, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, 700, 500, NULL, NULL, hInstance, NULL);
ShowWindow (hWnd, iCmdShow);
UpdateWindow (hWnd);
while (GetMessage (&message, NULL, 0, 0))
{
TranslateMessage (&message);
DispatchMessage (&message);
}
return message.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT paintstruct;
static HWND hWndEdit;
TEXTMETRIC textmetric;
int cyChar;
HFONT hFont;
switch (msg)
{
case WM_CREATE:
hWndEdit = CreateWindow (TEXT ("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_AUTOHSCROLL | ES_MULTILINE, 0, 0, 0, 0, hWnd, (HMENU) ID_EDIT,
((LPCREATESTRUCT) lParam) -> hInstance, NULL);
SendMessage (hWndEdit, EM_LIMITTEXT, 100, 0);
hFont = CreateFont (15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Verdana"));
SendMessage (hWndEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
wndProc = (WNDPROC) SetWindowLong (hWndEdit, GWL_WNDPROC, (LPARAM) EditProc);
return 0;
case WM_PAINT:
BeginPaint (hWnd, &paintstruct);
EndPaint (hWnd, &paintstruct);
return 0;
case WM_COMMAND:
return 0;
case WM_SIZE:
hDC = GetDC (hWnd);
GetTextMetrics (hDC, &textmetric);
cyChar = textmetric.tmHeight;
MoveWindow (hWndEdit, 0, HIWORD (lParam) - (cyChar + 4), LOWORD (lParam), (cyChar + 4), TRUE);
return 0;
case WM_DESTROY:
ReleaseDC (hWnd, hDC);
PostQuitMessage (0);
return 0;
default:
return (DefWindowProc (hWnd, msg, wParam, lParam));
}
}
LRESULT CALLBACK EditProc (HWND hWndEdit, UINT msg,
WPARAM wParam, LPARAM lParam)
{
static TCHAR szBuffer[100];
if (msg == WM_KEYDOWN)
{
switch (wParam)
{
case VK_RETURN:
Edit_GetText (hWndEdit, szBuffer, 100);
if (szBuffer == TEXT ("text"))
{
Beep (300, 100);
}
else
{
MessageBox (hWndEdit, szBuffer, NULL, MB_OK);
}
Edit_SetText (hWndEdit, TEXT(""));
PeekMessage (&message, hWndEdit, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE);
break;
}
}
return CallWindowProc (wndProc, hWndEdit, msg, wParam, lParam) ;
}