CreateWindowEx, DestroyWindow, CreateWindowEx
-
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.
-
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.
-
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.
-
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
-
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
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; .............
-
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; .............
-
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.
-
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
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.