Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CreateWindowEx, DestroyWindow, CreateWindowEx

CreateWindowEx, DestroyWindow, CreateWindowEx

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I made a toolbar in my program, and on the main menubar, made a "View" menu item with a list of toolbars. So I wrote CreateWindowEx to create the toolbar on program load. When you click the red X on the toolbar, I DestroyWindow, and the toolbar is gone. Then if I go to View, and click the toolbar, I run CreateWindowEx and make the Toolbar again. Symptom: When I make the toolbar the 2nd time, the toolbar window is not active. I can load stuff in it, but can't use the red x or the treeview inside the window. I get get focus on the window to use it. Question: I'm not sure what I did wrong, or if I'm just missing something in one of the Proc's.

    J B J 3 Replies Last reply
    0
    • J jkirkerx

      I made a toolbar in my program, and on the main menubar, made a "View" menu item with a list of toolbars. So I wrote CreateWindowEx to create the toolbar on program load. When you click the red X on the toolbar, I DestroyWindow, and the toolbar is gone. Then if I go to View, and click the toolbar, I run CreateWindowEx and make the Toolbar again. Symptom: When I make the toolbar the 2nd time, the toolbar window is not active. I can load stuff in it, but can't use the red x or the treeview inside the window. I get get focus on the window to use it. Question: I'm not sure what I did wrong, or if I'm just missing something in one of the Proc's.

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      That was a really bad idea there. I went back to hide and show, and figured out how to avoid the WM_DESTROY message when clicking the close button on the window bar.

      1 Reply Last reply
      0
      • J jkirkerx

        I made a toolbar in my program, and on the main menubar, made a "View" menu item with a list of toolbars. So I wrote CreateWindowEx to create the toolbar on program load. When you click the red X on the toolbar, I DestroyWindow, and the toolbar is gone. Then if I go to View, and click the toolbar, I run CreateWindowEx and make the Toolbar again. Symptom: When I make the toolbar the 2nd time, the toolbar window is not active. I can load stuff in it, but can't use the red x or the treeview inside the window. I get get focus on the window to use it. Question: I'm not sure what I did wrong, or if I'm just missing something in one of the Proc's.

        B Offline
        B Offline
        Binu MD
        wrote on last edited by
        #3

        could you post the CreateWindowEx() code snippet :)

        J 1 Reply Last reply
        0
        • B Binu MD

          could you post the CreateWindowEx() code snippet :)

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          It turned out to be a big mess. The Bool bRegister was a unsuccessful attempt to unregister the class after it was created. I thought if I could create the class, create the window, that I could destroy the window, and unregister the class to create a clean slate, and start the process again. On the 2nd time around, the window would paint, but it would not respond. When I took the other toolbar and dragged it across the regenerated toolbar, the regenerated toolbar would not paint again and dissappear. So I added the WS_CLIPSIBLINGS, and upon regeneration, no window at all. So I went back to show and hide, and added a return 1 to the WM_CLOSE in the Windows Proc, to cancel destroying the window, and to just run ShowWindow and update the checkbox in the main menu.

          HWND _project_Explorer_Create( HWND hWndMain, HINSTANCE hInstance, HWND hMDIClientArea, HWND hWndStatusBar )
          {

          hProjectExplorer\_Instance = hInstance;
          LoadString( hInstance, IDM\_PROJECT\_EXPLORER\_CLASS, sz\_ProjectExplorer\_Class, MAX\_LOADSTRING );
          
          //BOOL bRegister = FALSE;
          //bRegister = UnregisterClass( sz\_ProjectExplorer\_Class, hInstance );
          //DWORD dwErrorCode = GetLastError();
          	
          WNDCLASSEX toolWindow;
          toolWindow.cbSize = sizeof(WNDCLASSEX);
          
          if ( !GetClassInfoEx( hInstance, sz\_ProjectExplorer\_Class, &toolWindow ) ) {
          
          	toolWindow.style		= CS\_HREDRAW | CS\_VREDRAW;
          	toolWindow.lpfnWndProc		= \_project\_Explorer\_WndProc;
          	toolWindow.cbClsExtra		= 0;
          	toolWindow.cbWndExtra		= 0;
          	toolWindow.hInstance		= hInstance;
          	toolWindow.hIcon		= 0;
          	toolWindow.hCursor		= 0;
          	toolWindow.hbrBackground	= (HBRUSH)(COLOR\_WINDOW+1);
          	toolWindow.lpszMenuName		= 0;
          	toolWindow.lpszClassName	= sz\_ProjectExplorer\_Class;
          	toolWindow.hIconSm              = 0;
          
          	RegisterClassEx( &toolWindow );
          
          }
          								
          RECT winRect, statusBarRect;
          INT winWidth, winHeight, tbWidth, tbHeight, sbWidth, sbHeight;	
          
          if(GetWindowRect( hMDIClientArea, &winRect)) {
          	winWidth = winRect.right - winRect.left;
          	winHeight = winRect.bottom - winRect.top;
          
          	GetWindowRect( hWndStatusBar, &statusBarRect );
          	sbWidth = statusBarRect.right - statusBarRect.left;
          	sbHeight = statusBarRect.bottom - statusBarRect.top;
          					
          	tbWidth = 250;
          	tbHeight = (INT)floor(( (float)winHeight \* (float).60 ) - 1 );		
          	
          	// Create the Project Explorer Window
          	hWnd\_ProjectExplorer = CreateWindowEx(
          		WS\_EX\_TOOLWINDOW,
          		sz\_ProjectExplorer\_Class,
          		TEXT( "Project Explorer" ),
          		WS\_CHILD | WS\_SYSMENU | WS\_CAPTION
          
          B 1 Reply Last reply
          0
          • J jkirkerx

            It turned out to be a big mess. The Bool bRegister was a unsuccessful attempt to unregister the class after it was created. I thought if I could create the class, create the window, that I could destroy the window, and unregister the class to create a clean slate, and start the process again. On the 2nd time around, the window would paint, but it would not respond. When I took the other toolbar and dragged it across the regenerated toolbar, the regenerated toolbar would not paint again and dissappear. So I added the WS_CLIPSIBLINGS, and upon regeneration, no window at all. So I went back to show and hide, and added a return 1 to the WM_CLOSE in the Windows Proc, to cancel destroying the window, and to just run ShowWindow and update the checkbox in the main menu.

            HWND _project_Explorer_Create( HWND hWndMain, HINSTANCE hInstance, HWND hMDIClientArea, HWND hWndStatusBar )
            {

            hProjectExplorer\_Instance = hInstance;
            LoadString( hInstance, IDM\_PROJECT\_EXPLORER\_CLASS, sz\_ProjectExplorer\_Class, MAX\_LOADSTRING );
            
            //BOOL bRegister = FALSE;
            //bRegister = UnregisterClass( sz\_ProjectExplorer\_Class, hInstance );
            //DWORD dwErrorCode = GetLastError();
            	
            WNDCLASSEX toolWindow;
            toolWindow.cbSize = sizeof(WNDCLASSEX);
            
            if ( !GetClassInfoEx( hInstance, sz\_ProjectExplorer\_Class, &toolWindow ) ) {
            
            	toolWindow.style		= CS\_HREDRAW | CS\_VREDRAW;
            	toolWindow.lpfnWndProc		= \_project\_Explorer\_WndProc;
            	toolWindow.cbClsExtra		= 0;
            	toolWindow.cbWndExtra		= 0;
            	toolWindow.hInstance		= hInstance;
            	toolWindow.hIcon		= 0;
            	toolWindow.hCursor		= 0;
            	toolWindow.hbrBackground	= (HBRUSH)(COLOR\_WINDOW+1);
            	toolWindow.lpszMenuName		= 0;
            	toolWindow.lpszClassName	= sz\_ProjectExplorer\_Class;
            	toolWindow.hIconSm              = 0;
            
            	RegisterClassEx( &toolWindow );
            
            }
            								
            RECT winRect, statusBarRect;
            INT winWidth, winHeight, tbWidth, tbHeight, sbWidth, sbHeight;	
            
            if(GetWindowRect( hMDIClientArea, &winRect)) {
            	winWidth = winRect.right - winRect.left;
            	winHeight = winRect.bottom - winRect.top;
            
            	GetWindowRect( hWndStatusBar, &statusBarRect );
            	sbWidth = statusBarRect.right - statusBarRect.left;
            	sbHeight = statusBarRect.bottom - statusBarRect.top;
            					
            	tbWidth = 250;
            	tbHeight = (INT)floor(( (float)winHeight \* (float).60 ) - 1 );		
            	
            	// Create the Project Explorer Window
            	hWnd\_ProjectExplorer = CreateWindowEx(
            		WS\_EX\_TOOLWINDOW,
            		sz\_ProjectExplorer\_Class,
            		TEXT( "Project Explorer" ),
            		WS\_CHILD | WS\_SYSMENU | WS\_CAPTION
            
            B Offline
            B Offline
            Binu MD
            wrote on last edited by
            #5

            thanks for ur reply, use this code snippet .......... static bool reg =false; WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if( reg ) { UnregisterClass(szWindowClass, hInstance ); } if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Win32 Guided Tour"), NULL); return 1; } reg = true; .............

            J 1 Reply Last reply
            0
            • B Binu MD

              thanks for ur reply, use this code snippet .......... static bool reg =false; WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); if( reg ) { UnregisterClass(szWindowClass, hInstance ); } if (!RegisterClassEx(&wcex)) { MessageBox(NULL, _T("Call to RegisterClassEx failed!"), _T("Win32 Guided Tour"), NULL); return 1; } reg = true; .............

              J Offline
              J Offline
              jkirkerx
              wrote on last edited by
              #6

              Well thanks, but I'm not going to try that. I don't see the point of it. I'd rather have an explanation as to why I can't destroy a window and it's class and recreate it like an MDI Child Window.

              1 Reply Last reply
              0
              • J jkirkerx

                I made a toolbar in my program, and on the main menubar, made a "View" menu item with a list of toolbars. So I wrote CreateWindowEx to create the toolbar on program load. When you click the red X on the toolbar, I DestroyWindow, and the toolbar is gone. Then if I go to View, and click the toolbar, I run CreateWindowEx and make the Toolbar again. Symptom: When I make the toolbar the 2nd time, the toolbar window is not active. I can load stuff in it, but can't use the red x or the treeview inside the window. I get get focus on the window to use it. Question: I'm not sure what I did wrong, or if I'm just missing something in one of the Proc's.

                J Offline
                J Offline
                JohnCz
                wrote on last edited by
                #7

                Toolbar with treeview? What kind of toolbar you are referring to? Are you sure you are creating a toolbar? Maybe it is a tool window? Could you please post a snippet showing how you create this toolbar.

                JohnCz

                J 1 Reply Last reply
                0
                • J JohnCz

                  Toolbar with treeview? What kind of toolbar you are referring to? Are you sure you are creating a toolbar? Maybe it is a tool window? Could you please post a snippet showing how you create this toolbar.

                  JohnCz

                  J Offline
                  J Offline
                  jkirkerx
                  wrote on last edited by
                  #8

                  It's a tool window, I just called it a toolbar so folks got the bigger picture of what I was trying to do. So far so good, I have my MDI frame, and the 2 sidebars (toolbars) on the left. They size correctly, move and resize upon mid resize. The hide and show works good. Next phase is to dock them, but I need to tighten up the program first, and do an initial alpha test release. Hopefully this week.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups