cracel
April 20th, 2003, 02:11 PM
hello Gurus,
I have been trying to find a solution or at least an explanation for my problem for over a week now. I have browsed through several books, visited several newsgroups, and browsed the internet through many different search engine. I have not been able to find a single document that explains what I need.
So here is my problem:
I have created a window that is to work as my main app window. On that window I am to create child windows -> records of a database. I am able to create the child windows just fine and I can move them and write on them, but they never seem to be in focus. The title bar is always greyed out.
This problem started with an MFC SDI application that I was designing. ( SDI yes, only one document open ) And after several days of being unable to fix this problem ( on MFC my window also had a drawing problem and CEdit controls did not react to mouse ) I decided to create a basic application with no MFC to see what would happen and I got the same problem.
I have code for the basic application that I have create and will be glad to post it. Please can anyone explain to me what is going on here?
Thank you in advance,
Roger.
poccil
April 20th, 2003, 04:47 PM
It may sound computer-specific. Do applications you didn't write also exhibit this problem?
If not, something may be wrong with your code. Post the code for the non-MFC version, as well as a copy of the application .exe.
teleplayr
April 20th, 2003, 10:23 PM
Yes, I'd be very curious to see the code as well. I'm not sure if child windows created inside an SDI app will ever "look" as though they have focus. Try creating an edit control with a WS_CAPTION style. This may just be a Windows limitation. Why are you creating windows with title bars inside an SDI app, anyway?
-Joe
cracel
April 20th, 2003, 10:42 PM
I am posting my code as well as include the source codes and and exec file. On the MFC forum on Code Guru I was advised to either let the secondary windows roam free ( no child ), which I don't like, or use a MDI and modify the whole code to open only one document ( also known as MSDI, Muti Single Document Interface ) which sounds complicated. I refuse to believe that there is no way to simply create a child window.
Of course other applications don't behave like that : for example VC++ itself -- at some points we have many source code windows open and they work just fine -- or even Photoshop.
At first I thought it was a MFC fluke, but after testing pure windows code I realized that it may take a little more effort than I had previously thought.
#define VC_EXTRALEAN // Exclude rarely used stuff from Windows headers
//#include <afxwin.h> // MFC core and standerd components
//#include <afxext.h> // MFC extension
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC Support for windows 98 common controls
#endif /* _AFX_NP_AFXCMN_SUPPORT */
long FAR PASCAL WndProc( HWND hwnd, UINT msg, UINT wParam,LONG lParam );
long FAR PASCAL chldWndProc( HWND hwnd, UINT msg, UINT wParam,LONG lParam );
int PASCAL WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
/* Define defaults */
static char szAppName[] = "Windows Test Program";
static char szChildName[] = "Child Window";
HWND hwnd;
MSG msg;
WNDCLASS wc;
WNDCLASS wc_child;
HWND chwnd1;
/* Register window class */
if ( !hPrevInstance )
{
wc.style = CS_HREDRAW | CS_VREDRAW;
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__ *) GetStockObject( WHITE_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName= szAppName;
RegisterClass( &wc );
wc_child.style = CS_HREDRAW | CS_VREDRAW;
wc_child.lpfnWndProc = chldWndProc;
wc_child.cbClsExtra = 0;
wc_child.cbWndExtra = 0;
wc_child.hInstance = hInstance;
wc_child.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc_child.hCursor = LoadCursor( NULL, IDC_ARROW );
wc_child.hbrBackground = (HBRUSH__ *) GetStockObject( WHITE_BRUSH );
wc_child.lpszMenuName = NULL;
wc_child.lpszClassName = szChildName;
RegisterClass( &wc_child );
}
hwnd = CreateWindow( szAppName,
"Window Test Application - NO MFC",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
chwnd1=CreateWindow( szChildName,
"Child Window - NO MFC",
WS_OVERLAPPEDWINDOW | WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT,
CW_USEDEFAULT,
400,
100,
hwnd,
NULL,
hInstance,
NULL
);
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
ShowWindow( chwnd1, nCmdShow );
UpdateWindow( chwnd1 );
while ( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
long FAR PASCAL WndProc( HWND hwnd, UINT msg,
UINT wParam, LONG lParam )
{
HDC hdc;
RECT rect;
PAINTSTRUCT ps;
switch( msg )
{
case WM_PAINT: /* PAINT FUNCTION */
hdc = BeginPaint( hwnd, &ps );
GetClientRect( hwnd, &rect );
DrawText( hdc, "This is my first windows test program!",-1,&rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
EndPaint( hwnd, &ps );
return 0;
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
case WM_LBUTTONDBLCLK:
break;
default:
return DefWindowProc( hwnd, msg, wParam, lParam );
break;
}
return 0;
}
long FAR PASCAL chldWndProc( HWND hwnd, UINT msg,
UINT wParam, LONG lParam )
{
HDC hdc;
RECT rect;
PAINTSTRUCT ps;
switch( msg )
{
case WM_PAINT: /* PAINT FUNCTION */
hdc = BeginPaint( hwnd, &ps );
GetClientRect( hwnd, &rect );
DrawText( hdc, "This is my child window",-1,&rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
EndPaint( hwnd, &ps );
return 0;
break;
case WM_DESTROY:
ShowWindow( hwnd, SW_HIDE );
//PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, msg, wParam, lParam );
break;
}
return 0;
}
Again, thank you all for your help figuring this one out.
Roger.
teleplayr
April 20th, 2003, 11:05 PM
I'll give this code a try when I get to a different computer, later tonight.
Incidentally, both Photoshop and MSDEV are MDI applications.
-Joe
lily311
April 20th, 2003, 11:34 PM
You may have to handle it yourself.
void CYourWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
SendMessage(WM_NCACTIVATE, true);
CWnd::OnNcLButtonDown(nHitTest, point);
}
When you click on the titlebar, this function will highlight it.
And you have to write more code to make it inactive when it's not the focus.
Hope this helps.
Bengi
April 21st, 2003, 03:20 AM
this will help ya:
http://freespace.virgin.net/james.brown7/tuts/docking1.htm
(don't be fooled by the tuts's name/description)