cant modify edit box text

Hi, I have created an 'edit' window using the following line:

edit = CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILDWINDOW | WS_BORDER | ES_CENTER, 4, 4, 296, 20, hWnd, edit_id, hInst, NULL);

And declared edit and edit_id as follows:

HWND edit;
HMENU edit_id = (HMENU)50;

I see the 'edit' window when i run my program but when i click inside of it to add text nothing happens. nomatter what i click on the keyboard no text is inserted in the box. If i start with initial text in the 'edit' window i can delete the text by pressing 'Delete' on the keyboard but i cant put in text of my own. HELP?


#include <Windows.h>
#include <WinGDI.h>
#include <iostream>

HWND window1;
HWND window2;

HWND buttonA;
HWND buttonB;
HWND buttonC;
HWND button1;

HWND edit;
HMENU edit_id = (HMENU)50;

HMENU buttonA_ID = (HMENU)1;
HMENU buttonB_ID = (HMENU)2;
HMENU buttonC_ID = (HMENU)3;
HMENU button1_ID = (HMENU)4;

#define ID_FILE_MBOX 100
#define ID_FILE_EXIT 101



int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
{
CreateMainWindow("WindowApp", hInst);
CreateMainWindow("2x2MatrixSolve", hInst);

window1 = CreateWindow("WindowApp", "Window 1", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInst, 0);
window2 = CreateWindow("2x2MatrixSolve", "Window 2", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInst, 0);

CreateObjects(window1, hInst);
CreateObjects(window2, hInst);

ShowWindow(window1, cmdShow);
UpdateWindow(window1);

return(CheckMessages());
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;

switch(message)
{
case WM_CREATE:
{
CreateMenu(hWnd);
}
break;

case WM_COMMAND:
{
CheckButtons(wParam);
CheckMenu(wParam);
}
break;

case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
PaintObjects();
EndPaint(hWnd, &ps);
}
break;

case WM_CLOSE:
{
if(hWnd == window1)
{
PostQuitMessage(0);
}
if(hWnd == window2)
{
ShowWindow(window2, 0);
UpdateWindow(window2);
}
}

case WM_DESTROY:
{
if(hWnd == window1)
{
PostQuitMessage(0);
}
}
break;
}
return ::DefWindowProc (hWnd, message, wParam, lParam );
}

void CreateObjects(HWND hWnd, HINSTANCE hInst)
{
if(hWnd == window1)
{
buttonA = CreateWindow("BUTTON", "A", WS_VISIBLE | WS_CHILDWINDOW, 2, 2, 50, 50, hWnd, buttonA_ID, hInst, NULL);
buttonB = CreateWindow("BUTTON", "B", WS_VISIBLE | WS_CHILDWINDOW, 52, 52, 50, 50, hWnd, buttonB_ID, hInst, NULL);
buttonC = CreateWindow("BUTTON", "C", WS_VISIBLE | WS_CHILDWINDOW, 102, 102, 50, 50, hWnd, buttonC_ID, hInst, NULL);
edit = CreateWindow("EDIT", "", WS_VISIBLE | WS_CHILDWINDOW | WS_BORDER | ES_CENTER, 4, 4, 296, 20, hWnd, edit_id, hInst, NULL);

}
if(hWnd == window2)
{
button1 = CreateWindow("BUTTON", "1", WS_VISIBLE | WS_CHILDWINDOW, 2, 2, 50, 50, hWnd, button1_ID, hInst, NULL);
}
}

void CreateMenu(HWND hWnd)
{
HMENU hMenu, hSubMenu;

hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();

AppendMenu(hSubMenu, MF_STRING, ID_FILE_MBOX, "&MBOX");
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "&EXIT");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");

SetMenu(hWnd, hMenu);
}

void PaintObjects()
{
HFONT font = CreateFont(36,10,0,0,0,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_ROMAN, "Times");

SendMessage(buttonA, WM_SETFONT, (WPARAM)font, TRUE);
SendMessage(buttonB, WM_SETFONT, (WPARAM)font, TRUE);
SendMessage(buttonC, WM_SETFONT, (WPARAM)font, TRUE);

SendMessage(button1, WM_SETFONT, (WPARAM)font, TRUE);
}

void CheckButtons(WPARAM wParam)
{
if(LOWORD(wParam) == WORD(buttonA_ID))
{
ShowWindow(window2, 1);
UpdateWindow(window2);
}
if(LOWORD(wParam) == WORD(buttonB_ID))
{
MessageBox ( NULL, "Button B Pushed", "WindowApp", MB_OK );
}
if(LOWORD(wParam) == WORD(buttonC_ID))
{
MessageBox ( NULL, "Button C Pushed", "WindowApp", MB_OK );
}
if(LOWORD(wParam) == WORD(button1_ID))
{
SendMessage(window2, WM_CLOSE, NULL, NULL);
}
}

void CheckMenu(WPARAM wParam)
{
if(LOWORD(wParam) == WORD(ID_FILE_EXIT))
{
PostQuitMessage(0);
}
if(LOWORD(wParam) == WORD(ID_FILE_MBOX))
{
MessageBox ( NULL, "Menu MBOX Pushed", "WindowApp", MB_OK );
}
}

ATOM CreateMainWindow(char const *WindowClass, HINSTANCE hInst)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0; //MAKEINTRESOURCE(IDC_TEST);
wcex.lpszClassName = WindowClass;
wcex.hIconSm = 0;

return RegisterClassEx(&wcex);
}

WPARAM CheckMessages()
{
MSG msg;
int status;

while ((status = ::GetMessage (&msg, 0, 0, 0)) != 0)
{
if (status == -1)
return -1;
::DispatchMessage (&msg);
}

return msg.wParam;
}

oh btw, you should know that i am trying to avoid using a RC file. I can make edit box's work fine in the standard Win32 application that visual c++ makes for you, but i am trying to strip that code down into something simple i can understand
Try calling TranslateMessage (&msg); right before DispatchMessage (&msg);
closed account (3pj6b7Xj)
UberTron is correct. The editbox will not work right with out TranslateMessage() with out it, you deliver raw char data to the editbox.
Topic archived. No new replies allowed.