Sign in to follow this  
AndyGeers

More Windows dialog weirdness

Recommended Posts

AndyGeers    132
I've made a bit of progress on my attempt to try and get a tabbed control working on my dialog created using the Windows API, but now I've got a new problem. Basically, the situation is as follows: 1) I call InitCommonControlsEx to enable the use of the tab control 2) I create the parent dialog from a resource using the CreateDialog function. This dialog contains a tab control. 3) I create two child dialogs, also using resources and CreateDialog, and use their window handles to add two tabs to the parent dialog. 4) When the parent dialog receives WM_NOTIFY messages I switch tabs by hiding the old tab dialog and showing the new one. The weird part is this: a) I have some radio buttons (that look like normal command buttons) on one of the tabs, and they work perfectly, getting WM_COMMAND messages each time they're pressed and so on. b) I have a normal command button on the SAME tab, and when you click on that the whole thing just locks up and dies. The last messages received are WM_MOUSEACTIVATE and then two WM_SETCURSORs. The (shared) DialogProc for the parent and the tabs is as follows:
int CALLBACK CEditor::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    if (uMsg <= 0x038F)
    {
        LOG_EVENT_L2_1(CLog::E_LOG_MISC, "Editor received windows message (%s)", NDebug::g_szMessageName[uMsg]);
    }
    else if (uMsg == 0x0400)
    {
        LOG_EVENT_L2_0(CLog::E_LOG_MISC, "Editor received windows message (WM_USER)");
    }

    switch (uMsg) 
    { 
        case WM_INITDIALOG:
        {
            // Do nothing
            return TRUE;
        }

        case WM_CLOSE:
        {			
            // Check if it's the main dialog or one of the tabs
            if (hWnd == CEditor::Get()->GetHwnd())
            {
                // Disable editor
                CEditor::Get()->Deactivate();		
            }
            return TRUE;		
        }		

        case WM_NOTIFY:
        {
            LPNMHDR pnmh = (LPNMHDR) lParam;
            switch (pnmh->code)
            {
                case TCN_SELCHANGE:
                {
                    // Select the current tab
                    CEditor::Get()->SelectTab();
                    return TRUE;
                };
            }
            break;
        }		

        case WM_COMMAND:
        {			
            switch (LOWORD(wParam))
            {
                case IDC_AREA_CUSTOM:
                case IDC_AREA_SUBSETS:
                case IDC_AREA_TRIS:
                {
                    // (The radio buttons)
                    // Process this message    
                    CEditor::Get()->ModifyArea(LOWORD(wParam));
                    return TRUE;
                }

                case IDC_NEWAREA:
	        {
                    // (The command button)
                    // Create new area
                    CEditor::Get()->NewArea();
                    return TRUE;
                }
            };
            break;
	}

	// Call default processor
	return FALSE;
}

void CEditor::SelectTab()
{
	// Get handle to tabs control
	HWND hTabs = GetDlgItem(m_hDialog, IDC_TAB1);

	// See how many tabs there are, and which is selected
	int nTabCount = TabCtrl_GetItemCount(hTabs);
	int nSelectedTab = TabCtrl_GetCurSel(hTabs);

	// Loop over each tab in turn
	for (int nTab = 0; nTab < nTabCount; nTab ++)
	{
		// Get tab details
		TC_ITEM tiTab;
		tiTab.mask = TCIF_PARAM;		
		TabCtrl_GetItem(hTabs, nTab, &tiTab);

		if (tiTab.lParam)
		{
			if (nTab == nSelectedTab)
			{
				// Show this tab
				ShowWindow((HWND)tiTab.lParam, SW_SHOW);			
			}
			else
			{
				// Hide this tab
				ShowWindow((HWND)tiTab.lParam, SW_HIDE);
			}
		}
	}
}

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