Solved

Property page activation

Posted on 1998-05-06
13
502 Views
Last Modified: 2013-11-20
I have a modeless property sheet that I use to display properties for selected items in a tree view. Whenever the tree view selection changes, the pages in the sheet are updated. (New pages may be added and irrelevant pages may be removed)
Because of the dynamic nature of the sheet pages, sometimes an active page may be removed when the user changes the selection.
This causes the sheet to make another page active. When this happens, the sheet window is made active.
This is not what I want because the user still expects to have the focus in the tree view.
I tried to prevent the sheet window activation by handling the WM_WINDOWPOSCHANGING message but it didn't work (I added the SWP_NOACTIVATE flag).
Using Spy++ I see that the sheet gets the WM_WINDOWPOSCHANGING and WM_ACTIVATE messages.

Do you know of a way I can prevent window activation? Or is there another way to work arround tis property sheet behaviour?
0
Comment
Question by:Shami
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 1

Expert Comment

by:guruprasad031298
ID: 1307966
Let's say the tree control member of your tree view is m_pTreeCtrl, then after finishing the processing of updating the property sheet, just call m_pTreeCtrl->SetActiveWindow(). This should reclaim the activity back to the tree view.

Hope this helps !!!
0
 

Author Comment

by:Shami
ID: 1307967
I already thought of this and actually this is my workarround currently but this causes window flashes as the sheet window gets focus and then I return the focus to the view (The window title flashes).
I'm looking for a way to prevent activation of the sheet window.
0
 
LVL 8

Expert Comment

by:gelbert
ID: 1307968
Try to handle OnActivate() in your property page derived class.
void YourProertyPage::OnActivate( UINT nState, CWnd* pWnd, ... )
{
    if (WA_ACTIVE == nState )
    {
      // set focus back
      SetFocus( pWnd );
    }
    .......
}
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Shami
ID: 1307969
Setting the focus back to the old active window will flash the window titles. This workarround is not acceptable.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1307970
You may solve the problem by preventing the property sheet window from receiving the deactivate message WM_NCACTIVATE.

Override the WM_NCACTIVATE message in you property sheet class.
Add a bool (m_bAllowNcActivate) that determines if the base-class handler for WM_NCACTIVATE should be called.

BOOL CMySheet::OnNcActivate(BOOL bActive)
{
    if(m_bAllowNcActivate)
        return CPropertySheet::OnNcActivate(bActive);
    return 0;
}

Set this bool to TRUE as default (in the constructor).

Now, when you modify the page-layout (where you have the problem) set the m_bAllowNcActivate to FALSE. before adding or removing pages and back to true after.

0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1307971
I tried to handle the WM_NCACTIVATE the way you offered.
Sometimes the title bar does not repaint and sometimes it does.
Anyway, this workarround still leaves me with a focus problem so I had to call SetActiveWindow for the old window, which caused the title to be repainted. I tried to handle WM_NCACTIVATE for the window that loses the focus as well, but sometimes the focus still goes to the sheet (This maybe happens after I finish changing the pages).
0
 

Author Comment

by:Shami
ID: 1307972
OK. If you could create a sample app and E-mail it to me it would be at lot easier for me to help you. (You can se my E-mail by clicking on piano_boxer).
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1307973
Have you considered using a thread-specific Windows event hook?  Installing a CBT hook that processes HCBT_ACTIVATE and HCBT_SETFOCUS events should give you absolute control over input focus and window activation.

See "Win32 Platform SDK \ Windows Base Services \ Interprocess Communication \ Hooks" for more information.

Read the documentation for the following:
SetWindowsHookEx()
WH_CBT
CBTProc

Good luck,

Forest

0
 
LVL 1

Expert Comment

by:fwilkinson
ID: 1307974
Did something go wrong when you sent the answer? Why is it empty?
0
 

Author Comment

by:Shami
ID: 1307975
[Upon returning here, the answer I sent appears intact.  I don't know why it showed up empty for you, but here it is again.  -Forest]

Have you considered using a thread-specific Windows event hook?  Installing
a CBT hook that processes HCBT_ACTIVATE and HCBT_SETFOCUS events
should give you absolute control over input focus and window activation.

For more information, see Win32 Platform SDK: Windows Base
Services / Interprocess Communication / Hooks.

Read the documentation for the following:
SetWindowsHookEx()
WH_CBT
CBTProc

Good luck,

Forest
0
 
LVL 1

Accepted Solution

by:
fwilkinson earned 240 total points
ID: 1307976
I don't know why my answer keeps showing up empty, but you can now see it as a "rejected answer", a couple of frames above.
0
 
LVL 1

Expert Comment

by:fwilkinson
ID: 1307977
The CBTProc documentation specify that CBTProc must be in a DLL (in the remarks section).
Do you have an idea if this is true only for global CBT hooks or for any CBTProc? (I really don't want to write a DLL because I need to monitor messages only for one thread).
0
 

Author Comment

by:Shami
ID: 1307978
The CBTProc doesn't have to be in a DLL if you're only going to hook your own application's messages.  If your CBTProc is in your EXE, and you want to hook the current thread, you can do something like this:

hook_handle = SetWindowsHookEx( WH_CBT, CBTProc, NULL,
        AfxGetThread()->m_nThreadID);


0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 80
haveThree challenge 22 122
Line meaning 9 88
Capture logon name 13 88
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question