Problem with creating new window, from another window

This is a discussion on Problem with creating new window, from another window within the Windows Programming forums, part of the Platform Specific Boards category; Okay, here is the problem. My program is designed to start up, as any usual program does. It has the ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Problem with creating new window, from another window

    Okay, here is the problem. My program is designed to start up, as any usual program does. It has the initial window (created as usual). But instead of going to a dialog from there, I decided to work with another window, that is called and created once you hit the control button.

    But the problem is when I hit the control, the new window is created and it does appear. But then if I "x" (destroy) that window, I am looking back at the main window, from initial start up. Well, here's the problem: after "x"ing (destroying) the secondary window and going back to the main window, if I hit the control to call the secondary window, then the 2nd time around the secondary window does not appear.

    And also, when I call the secondary window from the main window, and I exit the whole program, there is still the "process" going on in Task Manager. The process only remains if I call the secondary window. For instance, if I start up the program in main window, and do not hit the control for the secondary window, then it is all fine. But if I start up the program, and hit the control for the secondary window then, even when the program is terminated, the process is still there in Task Manager and I have to manually terminate the process.

    Any idea as to what I need to do? Do you need to see my code that creates and calls the secondary window? Do you need to see any other code?

    Thanks!
    1978 Silver Anniversary Corvette

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    >> ...then the 2nd time around the secondary window does not appear.
    Zip up and post a bare-bones sample application that demonstrates the behavior.

    >> ... when I call the secondary window from the main window ...
    What does that mean?

    >> ... I exit the whole program, there is still the "process" ...
    Then you didn't exit the program. If you want you're application to exit cleanly then may have to do some "cleanup" work.

    gg

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    Most likely you're not handling WM_CLOSE and WM_DESTROY correctly:
    Code:
        case WM_CLOSE:
          DestroyWindow(hWndYourWindow);
          break;
    
        case WM_DESTROY: 
          PostQuitMessage(0);
          break;
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Do you need to see my code that creates and calls the secondary window? Do you need to see any other code?
    How 'bout the creating code and also the destroying code?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I really slimmed it down to a couple of functions (calling, creating, handling) where the problem probably is. Here is the source file. So, what is wrong?

    Here you go:
    Attached Files Attached Files
    1978 Silver Anniversary Corvette

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    >>> then the 2nd time around the secondary window does not appear.
    >> if(!RegisterClassEx(&wincl)) return 0;

    Guess what happens when that code is run a second time...

    As for the your process cleanup issues, Codulation has already shown one solution.

    Keep fiddling around, and post when you get stuck.
    And post code that compiles next time.

    gg

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, after I posted this I did track it down to the registration of the class. I think I have it working now.
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Creating File for File Processing
    By Dampecram in forum C Programming
    Replies: 2
    Last Post: 12-07-2008, 01:26 AM
  2. Creating a window causes a trackbar to stop working?
    By kidburla in forum Windows Programming
    Replies: 2
    Last Post: 09-20-2007, 06:44 AM
  3. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 11:14 PM
  5. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 05:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21