?
Solved

My child window is active yet still appears greyed out

Posted on 2004-08-29
10
Medium Priority
?
261 Views
Last Modified: 2013-11-20
Hi all,

I have made the simplest window program possible. It simply creates a parent window. I then try to create a child window, which works fine. I can move it around it behaves ok. I gave it a caption in a titlebar. But whenever I launch my program, the title bar for the child is always greyed out, even if I am dragging it around the screen. Also when the program starts, it seems the curved area around the top corners of the child window haven't been painted and there is a spot of black there. When I move the child they get painted correctly.

I can't figure out what style I have correctly entered to make it always appear greyed out, and why the corners are not initially the bg color of the parent window. Here I create the child window in my parent's CREATE message:

        case WM_CREATE:

        hwndChild= CreateWindow( szChildClass,
                                                  "MyChildWindow",
                                                  WS_VISIBLE | WS_THICKFRAME | WS_MINIMIZEBOX |WS_MAXIMIZEBOX | WS_CAPTION | WS_CHILDWINDOW | WS_CLIPSIBLINGS,
                                                  100, 100, 300, 200,
                                                  hwndParent,
                                                  (HMENU) 0,
                                                  (HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ),
                                                  NULL );

        ShowWindow(hwndChild, SW_SHOW);
        UpdateWindow( hwndChild );

        break;

My child's WndProc is nothing fancy and has all the basic parts to it. The only other thing I could see having an effect is the way I register my child window. I reigster it in WinMain() right after the parent has been registered:

               // parent has just been registered.

                wndchildclass .style            = CS_HREDRAW | CS_VREDRAW;
                wndchildclass .lpfnWndProc      = ChildWndProc;
                wndchildclass .cbWndExtra      = sizeof( long );
                wndchildclass .hIcon            = NULL;
                wndchildclass .lpszClassName      = szChildClass;
                wndchildclass .hbrBackground      = (HBRUSH) GetStockObject( WHITE_BRUSH );
                wndclass.hInstance            = hInstance;
                wndclass.hCursor            = LoadCursor( NULL, IDC_ARROW );

                RegisterClass( &wndchildclass );

What am I missing that makes the child window not be greyed out when you're moving it etc?

Thanks!
0
Comment
Question by:Already_Googled
  • 5
  • 3
9 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11927595
I see some omissions in your class declaration

          wndchildclass.cbClsExtra    = 0 ;
          wndchildclass.cbWndExtra    = sizeof (WORD);
          wndchildclass.lpszMenuName  = NULL ;
          wndchildclass.lpszClassName = szChildClass;    // don't see a class name

Also your problem could be related to your ChildWndProc() function.

 
0
 

Author Comment

by:Already_Googled
ID: 11927625
My apologies, here is my full wndchildclass:

wndchildclass:.style = CS_HREDRAW | CS_VREDRAW;
wndchildclass:.lpfnWndProc = ChildWndProc;
wndchildclass:.cbClsExtra = 0;
wndchildclass:.cbWndExtra = sizeof(WORD);
wndchildclass:.hInstance = hInstance;
wndchildclass:.hIcon = NULL;
wndchildclass:.hCursor = LoadCursor( NULL, IDC_ARROW );
wndchildclass:.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH );
wndchildclass:.lpszMenuName = NULL;
wndchildclass:.lpszClassName = szChildClass;


with the class name globally defined as:

TCHAR szChildClass[] = TEXT( "Child" );


And here is my child window proc:

LRESULT CALLBACK ChildWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    HDC hdc;
    PAINTSTRUCT ps;
   
    switch( message )
    {
        case WM_CREATE:
            return 0;

        case WM_PAINT:
            hdc = BeginPaint( hwnd, &ps );
            EndPaint( hwnd, &ps );
            return 0;
    }
    return DefWindowProc( hwnd, message, wParam, lParam );
}
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11927670
Hmm... I think could be lacking of overlapped attribute. Try with:

hwndChild= CreateWindow(szChildClass, "MyChildWindow",WS_OVERLAPPEDWINDOW|WS_CHILD, 100, 100, 300, 200,
    hwndParent, (HMENU) 0, (HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ), NULL );


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Already_Googled
ID: 11927686
Shoot still no good, even with styles only including:

WS_OVERLAPPEDWINDOW | WS_CHILD

This is so odd as the child is completely functional yet always remains greyed out!

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11927720
Really it is not easy to help you with pure WinAPI call. That's why MFC is useful, it does the dirty tasks for you. I have reviewed some old projects and I have used WS_POPUP style for this kind of windows also I have used NULL for classname, but make separated tests.
0
 

Author Comment

by:Already_Googled
ID: 11927734
I posted the complete skeleton code here below, I've made sure it compiles as is. If you drop it into a blank project you should see the same characteristics? If you can't spot what I'm doing wrong perhaps I can turn to MFC, thank you!


#include <windows.h>

LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
LRESULT CALLBACK ChildWndProc( HWND, UINT, WPARAM, LPARAM );

TCHAR   szChildClass[] = TEXT( "ChildClass" );


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                              PSTR szCmdLine, int iCmdShow )
{
    static TCHAR szAppName[] = TEXT( "MyAttemptAtChildWindows" );
    HWND        hwnd;
    MSG         msg;
    WNDCLASS    wndclass, wndchildclass;

    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( LTGRAY_BRUSH );
    wndclass.lpszMenuName   = NULL;
    wndclass.lpszClassName  = szAppName;

    if( !RegisterClass( &wndclass ) )
    {
        MessageBox( NULL, TEXT( "Couldn't register wndclass!" ),
                    szAppName, MB_ICONERROR );
        return 0;
    }

    // Register our child window.
    wndchildclass.style         = CS_HREDRAW | CS_VREDRAW;
    wndchildclass.lpfnWndProc   = ChildWndProc;
    wndchildclass.cbClsExtra    = 0;
    wndchildclass.cbWndExtra    = sizeof( long );
    wndchildclass.hInstance          = hInstance;
    wndchildclass.hIcon              = NULL;
    wndchildclass.hCursor       = LoadCursor( NULL, IDC_ARROW );
    wndchildclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
    wndchildclass.lpszMenuName  = NULL;
    wndchildclass.lpszClassName = szChildClass;

    if( !RegisterClass( &wndchildclass ) )
    {
        MessageBox( NULL, TEXT( "Couldn't register wndchildclass!" ),
                    szAppName, MB_ICONERROR );
        return 0;
    }

    hwnd = CreateWindow( szAppName, TEXT( "ParentWindow" ),
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         NULL, NULL, hInstance, NULL );

    ShowWindow( hwnd, iCmdShow );
    UpdateWindow( hwnd );

    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    static HWND      hwndChild;

    switch( message )
    {
    case WM_CREATE:

        hwndChild = CreateWindow( szChildClass,
                                  "ChildWindow",
                                  WS_OVERLAPPEDWINDOW | WS_CHILD,
                                  100, 100, 300, 200,
                                  hwnd,
                                  (HMENU) 0,
                                  (HINSTANCE) GetWindowLong( hwnd, GWL_HINSTANCE ),
                                  NULL );

        ShowWindow(hwndChild, SW_SHOW);
        UpdateWindow( hwndChild );

        return 0;

    case WM_DESTROY:
        PostQuitMessage( 0 );
        return 0;
    }
    return DefWindowProc( hwnd, message, wParam, lParam );
}

LRESULT CALLBACK ChildWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    HDC         hdc;
    PAINTSTRUCT ps;
   
    switch( message )
    {
    case WM_CREATE:
        return 0;

    case WM_PAINT:
        hdc = BeginPaint( hwnd, &ps );
        EndPaint( hwnd, &ps );
        return 0;
    }
    return DefWindowProc( hwnd, message, wParam, lParam );
}
0
 
LVL 19

Accepted Solution

by:
drichards earned 500 total points
ID: 12006846
Interesting that if you take away WS_CHILD from the style, the title bar works as expected.  What does this style really do?
0
 

Author Comment

by:Already_Googled
ID: 12008167
The child style will allow the parent window to control the children. As in, if you move the parent window, the children will move with it. The parent will also clip the children if they try to go outside of it. Popup style windows turned out to be ok for my purposes in this post, but, still not sure why it's impossible to have the title bar be active with a child.
0
 

Author Comment

by:Already_Googled
ID: 12012410
Hi Dan,

drichards had answered another question I had posted in the meantime, worth only 45 pts, I had asked him to post in this one so I could accept in here as well to give him the full number of points I thought he deserved, so it all worked out nicely.

Thanks for the link, I'll check it out,

Best regards
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question