Code:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#define compare(a1,b1) !stricmp(a1,b1)
#define ID_OF_BUTTON 1101
#define ID_MYEDIT 3460
const char g_szClassName[] = "myWindowClass";
HWND hWndMyEdit;
WNDPROC MainWindProc;
int doSwilly(char *buf)
{
// this what happens when you click translate
MessageBox(0,"","",MB_OK);
return 0;
}
LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char buf[500];
switch(msg){
case WM_CHAR:
if((int) wParam == VK_RETURN){
GetWindowText(hwnd, buf, 500);
doSwilly(buf);
break;
}
else return CallWindowProc(MainWindProc,hwnd, msg, wParam, lParam);
break;
}
return CallWindowProc(MainWindProc,hwnd, msg, wParam, lParam);
}
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char buf[500];
switch(msg)
{
case WM_KEYDOWN:
if((int) wParam == VK_RETURN){
GetWindowText(hWndMyEdit, buf, 500);
doSwilly(buf);
break;
}
else return DefWindowProc(hwnd, msg, wParam, lParam);
break;
case WM_CLOSE:
DeleteFile("temp.t");
DestroyWindow(hwnd);
break;
case WM_DESTROY:
DeleteFile("temp.t");
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_OF_BUTTON:
GetWindowText(hWndMyEdit, buf, 500);
doSwilly(buf);
break;
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
srand(time(NULL));
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Swilly translator, version 2.",
WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, 580, 50,
NULL, NULL, hInstance, NULL);
hWndMyEdit = CreateWindow("EDIT",
"", WS_CHILD | WS_VISIBLE,
0, 0, 489,20, hwnd,
(HMENU) ID_MYEDIT,
hInstance, NULL);
CreateWindow(
"button",
"Translate!",
WS_CHILD | WS_VISIBLE ,
489, 0,
80, 20,
hwnd,
(HMENU)ID_OF_BUTTON,
0,
NULL
);
MainWindProc = (WNDPROC)SetWindowLong(hWndMyEdit,GWL_WNDPROC,(DWORD)EditProc);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
I have used SetWindowLong to sublass your edit box and filter out all of the enter key presses........have a go and see if its ok for you