msdn said something about focus not going to window that is not
active, but i do not know how to make those windows active, they
were not active in 3.1 version, and i did not care, because the
edit controls worked anyway.
So how to get around this problem with minimal changes? Do i have
to start using "MDI" windows?
Here is the code example, any win95 c(++) compiler should do (i used BC5.0B) :
Note that this works ok with "old" compilers.
--------------------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int PASCAL WinMain
(
HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int
)
{
static char szAppName[] = "editwin" ;
MSG msg ;
WNDCLASS wndclass ;
HWND main_hwnd;
HWND child_hwnd;
HWND edit_hwnd;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = DefWindowProc; // ;)
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass (&wndclass);
}
main_hwnd = CreateWindow
(
szAppName, // window class name
szAppName, // window caption
WS_OVERLAPPEDWINDOW,
0, // initial x position
0, // initial y position
500, // initial x size
200, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
);
ShowWindow (main_hwnd, SW_SHOW);
UpdateWindow (main_hwnd);
child_hwnd = CreateWindow
(
szAppName, // window class name
"Child", // window caption
WS_CHILD | WS_CAPTION, // captioned child window style, edit control does not work
//WS_CHILD, // non-captioned child window style, edit control works
10, // initial x position
10, // initial y position
400, // initial x size
160, // initial y size
main_hwnd, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
);
ShowWindow(child_hwnd, SW_SHOW);
UpdateWindow(child_hwnd);
edit_hwnd = CreateWindow
(
"EDIT", // window class name
"Edit", // window caption
WS_CHILD | WS_VISIBLE |
WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, // window style
10, // initial x position
10, // initial y position
100, // initial x size
100, // initial y size
child_hwnd, // parent window handle
(HMENU)100, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
);
ShowWindow(edit_hwnd, SW_SHOW);
UpdateWindow(edit_hwnd);
SetWindowText(edit_hwnd, "Edith");
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
> edit control inside titled child window in "4.0" not getting focus
>
> When i ported my application into win95, some edit controls refused
> to get focus, so that it was impossible to type anything into them.
>
> msdn said something about focus not going to window that is not
> active, but i do not know how to make those windows active, they
> were not active in 3.1 version, and i did not care, because the
> edit controls worked anyway.
>
> So how to get around this problem with minimal changes? Do i have
> to start using "MDI" windows?
>
> Here is the code example, any win95 c(++) compiler should do (i used BC5.0B)
:
> Note that this works ok with "old" compilers.
There are (at least) two kinds of parenthood (-ness? -iality?).
There is also "ownership" and maybe even "master/slave" or
"mother/daughter" or "father/son" and their combinations :)
1. in CreateWindow() you define the parent that will "destroy" this
window when closing.
2. By calling SetParent() you define that this window will not
"go out" of parent window.
The solution is to use WS_POPUP | WS_CAPTION in Createwindow()
and call SetParent().
Corrected sample:
--------------------------------------------------------------
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int PASCAL WinMain
(
HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int
)
{
static char szAppName[] = "editwin" ;
MSG msg ;
WNDCLASS wndclass ;
HWND main_hwnd;
HWND child_hwnd;
HWND edit_hwnd;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = DefWindowProc;
RegisterClass (&wndclass);
}
WS_POPUP | WS_CAPTION, // window style
10, // initial x position
10, // initial y position
200, // initial x size
160, // initial y size
main_hwnd, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
);
SetParent(child_hwnd, main_hwnd);
ShowWindow(child_hwnd, SW_SHOW);
UpdateWindow(child_hwnd);
edit_hwnd = CreateWindow
(
"EDIT", // window class name
"Edit", // window caption
WS_CHILD | WS_VISIBLE |
WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL, // window style
10, // initial x position
10, // initial y position
100, // initial x size
100, // initial y size
child_hwnd, // parent window handle
(HMENU)100, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
);
ShowWindow(edit_hwnd, SW_SHOW);
UpdateWindow(edit_hwnd);
SetWindowText(edit_hwnd, "Edith");
HWND child_2 = CreateWindow
(
szAppName, // window class name
"Child_2", // window caption
WS_POPUP | WS_CAPTION,
250, // initial x position
10, // initial y position
100, // initial x size
160, // initial y size
main_hwnd, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL // creation parameters
);
SetParent(child_2, main_hwnd);
ShowWindow(child_2, SW_SHOW);
UpdateWindow(child_2);