Re: "edit" control is read only?
Hello John/newsgroups!
I have come down to 3 simple files containing pretty much the minimal
standard code required to get an edit control to work... here is the actual
code... I am still having the problem...Usually when you click on an edit
control, it supposed to automatically get the focus and we should be able to
type text in there! If I may politely ask someone to take a glimpse at the
following code and see why I can't edit the edit control field by simply
clicking on it!
==============================================Main.cpp
#include <windows.h>
//DECLARE CALLBACKS
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc_CW2 (HWND, UINT, WPARAM, LPARAM);
//Name and Class name of main window
static TCHAR *szMW_Name = TEXT ("MAIN APPLICATION 1");
static TCHAR szMW_ClassName[] = TEXT ("MW");
//Child window #2 (Programming GUI)
static TCHAR szCW2_ClassName[] = TEXT("CW2");
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInnstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
//-MAIN WINDOW CONFIGURATION
wndclass.style = CS_HREDRAW |CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szMW_ClassName;
//-REGISTRATION
RegisterClass (&wndclass);
// CHILD WINDOW #2 CONFIGURATION
wndclass.style = CS_HREDRAW |CS_VREDRAW;
wndclass.lpfnWndProc = WndProc_CW2;
wndclass.hIcon = LoadIcon (NULL, IDI_EXCLAMATION);
wndclass.hIcon = NULL;
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szCW2_ClassName;
//-REGISTRATION
RegisterClass(&wndclass); //Programming GUI
//-CREATE MAIN APPLICATION WINDOW
hwnd = CreateWindow (szMW_ClassName,szMW_Name,
WS_OVERLAPPEDWINDOW ,
20, 20, 750, 550, NULL,NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0)) //Window's queue loop
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
================================================
=======================================WndProc.cpp
#include <windows.h>
struct hdMW_WindowButtonsTAG
{
int iCTL_idx;
TCHAR *szMW_btC_Name;
int MW_btC_RectLeft;
int MW_btC_RectTop;
int MW_btC_RectRight;
int MW_btC_RectBottom;
int MW_btC_ID;
};
#define CW2_ID 2 //Child window ID
//Child window title bar name
static TCHAR *szCW2_Name = TEXT("Programming GUI");
//Child window class name
extern TCHAR szCW2_ClassName[] = TEXT("CW2");
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
int i;
//MAIN CONTROL PROPERTIES
hdMW_WindowButtonsTAG WindowButtons[] =
{
1,TEXT("< EXIT >"),650,450,80,40,1,
2,TEXT("< Connect! >"),10,30,180,30,2,
3,TEXT("< GUI >"),200,30,180,30,3,
};
//Child window handle(s)
static HWND hdCWdws[2];
static HWND hdMW_WindowButtons[3]; //Main window buttons
switch(message)
{
case WM_CREATE:
//MAIN WINDOW BUTTON CONTROLS
for(i=0;i<3;i++)
{
hdMW_WindowButtons[i] = CreateWindow( TEXT
("button"),WindowButtons[i].szMW_btC_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON | WS_CLIPSIBLINGS,
WindowButtons[i].MW_btC_RectLeft,
WindowButtons[i].MW_btC_RectTop,
WindowButtons[i].MW_btC_RectRight,
WindowButtons[i].MW_btC_RectBottom,
hwnd,(HMENU)WindowButtons[i].MW_btC_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
}
return 0;
case WM_COMMAND:
//IF EXIT BUTTON CLICKED THEN EXIT APPLICATION
if (LOWORD(wParam) == WindowButtons[0].MW_btC_ID)
{
DestroyWindow(hwnd); //End application
}
//CREATE CHILD WINDOW #2 WHEN BUTTON #2 PRESSED
else if (LOWORD(wParam) == WindowButtons[2].MW_btC_ID)
hdCWdws[1] = CreateWindow(
szCW2_ClassName,szCW2_Name,
WS_CHILD | WS_CAPTION | WS_SYSMENU,
10, 10, 700, 450,hwnd,(HMENU)CW2_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
BringWindowToTop(hdCWdws[1]);
//SHOW CHILD WINDOW #2
ShowWindow(hdCWdws[1],SW_SHOW);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
=================================================
=========================================WndProc_CW2.cpp
#include <windows.h>
struct hdCW2_WindowButtonsTAG
{
int iCTL_idx;
TCHAR *szMW_btC_Name;
int MW_btC_RectLeft;
int MW_btC_RectTop;
int MW_btC_RectRight;
int MW_btC_RectBottom;
int MW_btC_ID;
};
LRESULT CALLBACK WndProc_CW2(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static HWND HWND1;
switch(message)
{
case WM_CREATE:
HWND1 = CreateWindow( TEXT ("edit"), TEXT("zero"),
WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_LEFT | ES_MULTILINE, 10,10,50,30, hwnd,(HMENU)800,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
return 0;
case WM_CLOSE: //Handler to do code on close
break;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
==================================================
All feedback greatly appreciated!
--
Best regards
Robert
"John Carson" wrote:
"Robby" <Robby@discussions.microsoft.com> wrote in message
news:569D217E-1832-44C0-90B2-BD2B4FE6A4E4@microsoft.com
Hello,
I am using the edit class as I am creating a control as so:
==============================================
static HWND HWND1;
LRESULT xxx;
HWND1 = CreateWindow( TEXT ("edit"), TEXT("zero"),
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_MULTILINE,
10,10,50,30, hwnd,(HMENU)800,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
//Set the control as non read only!
xxx = SendMessage(
(HWND) HWND1, // handle to destination control
(UINT) EM_SETREADONLY, // message ID
(WPARAM) false, // = (WPARAM) ()
wParam; (LPARAM) 0); // = 0; not
used, must be zero );
===================================================
Can anyone tell me why the edit control created with CreateWindow
appears as read only. I don't see a flashing cursor in the control,
nor can I type text in it!
I know the above code is not much for you fellows to work with,
however before I spend 4 hours reducing my project to a few
compilable lines, If I may politely ask! I was just wondering if
someone had this problem already where its solution would be an
obvious and simplistic one! If not well, just let me know and its no
problem, I will crunch it down to more of an analysable and
compilable size!
Also, xxx reurns a 1, apparently if the function fails, it should
return a
0. So I guess my control is not set as read only! But why is it still
read only?
My code is 99% the same as the POPPAD1.C from M. Petzold's hand book!
P.396. The only difference is that as a whole, my application is much
larger and I am doing this on a child window where as he is doing it
on the main wndProc window. I don't think this should make a
difference.... But I could be wrong!
When I run your code, I am able to give the edit control the focus by
clicking on it and I can edit its contents without a problem (the
SendMessage call is redundant, by the way). You won't want to hear this
but...the problem is somewhere else in your code.
On another matter, it is a really bad habit to cast everything, as you do in
your SendMessage call. You thereby undermine the type safety built into the
C and C++ languages. Only cast when you have to and only cast when you know
what you are doing. Casting means you are saying to the compiler: "I know
that I am supplying the wrong type, but I know what I am doing, so let me do
it."
--
John Carson