Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all:

I use the normal way to create the Tab in MFC,
and I find a problem about Tab control, recently.
The Tab is abnormal after I opened the another application with User Account Control(UAC) in Win7.
Like this picture: http://i.imgur.com/xntxhDV.jpg[^]
When the problem happened, it still can use, and if I selected the another page in Tab, it's gonna normal!
I think it happened because the slices of display is not normal after the UAC...
Hope someone can give me a hand,
thank you!!

I pasted my Tab code below:
in OnInitDialog( ):
C++
TCITEM tc1,tc2;
tc1.mask = TCIF_TEXT;
tc1.pszText = _T("page1");
tc2.mask = TCIF_TEXT;
tc2.pszText = _T("page2");

m_tab.InsertItem(0, &tc1);
m_tab.InsertItem(1, &tc2);

CRect rec;
m_tab.GetClientRect(&rec);

    //I don't show the edge about Tab
rec.bottom += 0;
rec.left -= 0;
rec.top += 20;
rec.right -= 0;

m_page1.Create(IDD_DIALOG1, GetDlgItem(IDC_TAB1));
m_page2.Create(IDD_DIALOG2, GetDlgItem(IDC_TAB1));
m_page1.MoveWindow(&rec);
m_page2.MoveWindow(&rec);
m_page1.ShowWindow(SW_SHOW);
m_page2.ShowWindow(SW_HIDE);

C++
void Ctab3Dlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) 
{  
   switch (m_tab.GetCurSel()) 
    { 
      case 0: 
            m_page1.ShowWindow(SW_SHOW); 
            m_page2.ShowWindow(SW_HIDE ); 
            break; 
       case 1: 
            m_page1.ShowWindow(SW_HIDE); 
            m_page2.ShowWindow(SW_SHOW); 
            break; 
      default: 
            break; 
    }
	*pResult = 0; 
}
Posted
Comments
chaau 4-Dec-13 1:15am    
What is the the base class of your m_page1 and m_page2. I think the second parameter of the Create function (GetDlgItem(IDC_TAB1)) is incorrect
Sergey Alexandrovich Kryukov 4-Dec-13 1:57am    
Hard to believe it could be related to UAC. It could be something else. Try to open any full-screen window and remove it, move this application out of screen and put back, or Ctrl+Alt+Del, or something like that, related to window update. It would be good to reproduce the problem is some other way.
—SA
Member 10307999 4-Dec-13 3:17am    
thanks for your reply, Kryukov! I have tried the way which you said, and I found it will happen in Ctrl+Alt+Del, too... But the other cases didn't abnormal@@
Sergey Alexandrovich Kryukov 4-Dec-13 3:24am    
This is what I expected. It is related to redrawing/invalidation of the image in form. Now, after you got abnormal view, could you try to invalidate it? For this purpose, drag your application window half-way behind the edge of the screen, and than drag back. Will the view get to normal in the part of the window which was hidden, after you drag it back? I don't know you desktop settings, so stop the dragging (release mouse button) when window is half-hidden, then drag back again.
—SA
Member 10307999 4-Dec-13 4:28am    
I tried the test which you said, and it's normal. The abnormal display appears only if I press Ctrl+Alt+Del or opened the another application with UAC. I don't know why...

1 solution

We have done some interactive experiments (please see comments to the question) in attempts to more accurately characterize the symptom and eventually locate the problem. As I suspected, something in the code, which I cannot see from the code sample, prevents proper re-rendering of all the graphics. For the next step, try to experiment with two functions: CWnd::Invalidate (first of all) or CWnd::RedrawWindow:
http://msdn.microsoft.com/en-us/library/ax04k970.aspx[^],
http://msdn.microsoft.com/en-us/library/0fdz8ey6.aspx[^].

See also: http://msdn.microsoft.com/en-us/library/btaacw58.aspx[^].

In particular, the to invalidate or redraw it in a handler of the message WM_ACTIVATE:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646274%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
Comments
Member 10307999 6-Dec-13 2:36am    
Thank you, SA!! there methods can solve the abnormal Tab.
Because I don't know when the user redraw the desktop of OS(I guessed what causes the abnormal), I scanned the application by OnTimer function (0.5 sec),
but it let my application glistened.
I only wanted to redraw the Tab Page, so I used the SetRedraw() to reduce the redraw area,
but it still glistened obviously T_T
I think if there is a function that could judge the desktop of OS has redraw, and then I can SetRedraw() if the OS has redraw.
Thanks a lot!!
Sergey Alexandrovich Kryukov 6-Dec-13 11:33am    
Consider this as the intermediate step. Scanning anything by timer (polling) is of course unacceptable. Did you handle WM_ACTIVATE? Maybe it does not fire...
—SA
Member 10307999 8-Dec-13 9:28am    
I have read the WM_ACTIVATE form your link, but I still don't understand how to use it...
Would you teach me how to use it, maybe a easy example, please.
Thanks for your help!!
Sergey Alexandrovich Kryukov 8-Dec-13 12:33pm    
Handling windows messages in MFC is ugly. Just read about it.
But I cannot imagine that you did not handle them before, I though Windows programming is nearly impossible without it.
But in this case, you can override CWnd::OnActivate...
With messages, start here: http://msdn.microsoft.com/en-us/library/6d1asasd.aspx.
—SA
Member 10307999 9-Dec-13 4:24am    
I try it:

void TabDlg::OnActivate(UINT nState,CWnd* pWndOther,BOOL bMinimized )
{
switch(nState)
{
case WA_CLICKACTIVE:
case WA_ACTIVE:
case WA_INACTIVE:
{
m_tab.SetRedraw(true);
}
break;
default:
break;
}
CDialog::OnActivate(nState,pWndOther,bMinimized);
}

, but the abnormal display was still alive :(
Only when I clicked the application anywhere, the display became normal
(by WA_CLICKACTIVE).
Did I miss something@@?
thanks!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900