Sign in to follow this  
Waaayoff

[Win32] Closing Child window causes Parent window to close?

Recommended Posts

Waaayoff    952
How do i prevent that? (i want to be able to close the child window w/o closing its parent) I'm just using the code you get when creating a new Win32 app in Visual Studio plus this:
 c_hWnd = CreateWindowW(szWindowClass, L"Child", WS_CHILD | WS_OVERLAPPEDWINDOW,
     400, 100, 200, 300, hWnd, NULL, hInstance, NULL);

   ShowWindow(c_hWnd, nCmdShow);
   UpdateWindow(c_hWnd);

Share this post


Link to post
Share on other sites
Aardvajk    13207
Please show:

  • if you are using the same WndProc for both windows
  • What you are doing in response to WM_DESTROY or WM_CLOSE in the WndProc for your child window


  • Reason I ask is that posted code relates to window creation, not destruction.

    Share this post


    Link to post
    Share on other sites
    Waaayoff    952
    Yes i'm using the same WndProc for both windows and i'm not doing anything special for my Child window incase of a WM_DESTROY message..

    Share this post


    Link to post
    Share on other sites
    Aardvajk    13207
    If you have two different windows, they probably shouldn't have the same WndProc. It is likely that your child window's either explicit or default handling of WM_DESTROY is calling PostQuitMessage(0).

    You should create a WndProc for your child window that is designed for a child rather than application window. If you post the WndProc here, that would probably get to the bottom of things.

    I feel obliged to suggest that Windows API is a rubbish way to write GUI-based applications compared to C# and WinForms, but bleh.

    Share this post


    Link to post
    Share on other sites
    Waaayoff    952
    So i will have to create and register a new Window Class for the Child Window? (to pass the new WndProc)

    I really don't use Win32 much, don't see how it could be useful for gaming really..

    I'm just asking about child windows so as to create one that pops up when a user launches my game to specify some options. Like if he wants to run the game in fullscreen, what resolution to use, etc..

    Share this post


    Link to post
    Share on other sites
    Aardvajk    13207
    Yeah, normally if you have a new type of window, you'd register the new window class. You can subclass the window and set a new window procedure using SetWindowLongPtr, but this sounds more like a new window class case than a subclass case to me.

    Personally, I use a dialog as a first-run window, created in the RC file for the project, but if I was creating the first-run window in code, I'd certainly create a new window class and have it's own WndProc.

    Having your existing codebase in unmanaged C++ and wanting a first-run dialog is a good excuse (IMHO) for using Windows API for this sort of thing. If you are using Express VS, you might like to look into ResEdit for creating dialogs without the pain.

    Share this post


    Link to post
    Share on other sites
    Aardvajk    13207
    You're welcome. You're welcome. You're welcome. [smile]

    Post back if you have any trouble figuring out how to integrate the resources into your app. Unfortunately creating the dialog only half the battle.

    Share this post


    Link to post
    Share on other sites
    Waaayoff    952
    Well i've been reading this [long] article on Resource Files.. Sounds very confusing really. But i think by the time i'm done with it i'll have a good grasp on the subject.. If not, i hope you're around to answer ;)

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this