15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CPropertySheet /Pages

Tammy N -- Tammy.N.Desrosier@FMR.Com
Thursday, February 08, 1996

[Moderator's note: Yes, this was discussed already this week, but
there was no answer given on how to do it, so I'm letting this
continue the discussion.]

I am struggling finding a solution to the following problem.  I have tried 
Help,MSDN, MFC FAQ and the resources sitting around me.... I nearly give 
up!!!

Here it goes ...
I have a PropertySheet with several PropertyPages.  The functionality I 
would like to perform is to set a tab as "disabled".  This means I would 
like to see the tab and the title on the tab but the title should be grayed 
out (disabled) and the user should not be able to select the tab.  Seems 
easy enough.  I have tried the obvious, and even the not so obvious.

I obtained a handle to each dialog but this is not the same handle as to the 
tabs.  I even disabled ALL the tabs but did not gray out the titles.  Please 
help.



Tina Buch -- tbuch@Onramp.NET
Saturday, February 10, 1996


>I have a PropertySheet with several PropertyPages.  The functionality I 
>would like to perform is to set a tab as "disabled".  This means I would 
>like to see the tab and the title on the tab but the title should be grayed 
>out (disabled) and the user should not be able to select the tab.  Seems 
>easy enough.  I have tried the obvious, and even the not so obvious.
>
>I obtained a handle to each dialog but this is not the same handle as to the 
>tabs.  I even disabled ALL the tabs but did not gray out the titles.  Please 
>help.
>
>

I worked with the above problem in VC++ 1.52. The property sheet code in
VC++ 2.2 is almost identical. Do not know about 4.0 as I haven't gotten
around to looking at it yet.

I had to enable and disable tabs on the fly depending on a radio button
selected on the first page.  You may  note that I have never seen property
pages that are 
disabled/ enabled on the fly, however it is appropriate for my app. 


I called Microsoft regarding this about 6 months ago and was told it could
not be done.  (One guy who had never worked with it said to try subclassing,
however I do not think you can do it.)  The tabs in VC++ 1.52 / 2.2 are
really one rectangle and the tabs are drawn in this rectangle.  You cannot
get a handle to those tabs as they are deep in the code.

I ended up modifying the dlgprop.cpp code. After tracing through the code,
it took me only about 1/2 hour to modify the code and write a disable
function.  If you want to do it right for 32 bit you need to add a #define
32BIT (or whatever)  and add the 2.2 modifications to dlgprop.cpp.

The modifications are not difficult. Rename the Property Sheet classes and
link the new file in to your project file. Add a BOOL "disable" variable to
TabItem
(or whatever it is called).  Trace through everywhere the tabs are drawn and
draw with an italic/grayed out font to indicate disabled. (Search on "Font"
- you will need to add a new Font Variable) There is one place that some
code does not get processed if the tab is disabled. It is where it checks
for a point and tries to determine if it is a tab ... something like that.
This was a long time ago.  Look for a switch statement - at the end of a
switch statement. I think the entire function is one switch(). I also had to
move something from protected to public  (I think).


The appropriate header files will need to be added, and after the header
files you may need to be add

        #pragma pack(1)

or your tab captions will be trashed out.


If there  is  a better way, I'd like to know about it - I haven't had any
problems with the modifications though.

                Tina




Mario Contestabile -- Mario_Contestabile.UOS__MTL@UOSMTL2.universal.com
Monday, February 12, 1996

[Mini-digest: 4 responses]

[Snip()]
I would 
>like to see the tab and the title on the tab but the title should be grayed 
>out (disabled) and the user should not be able to select the tab.
[Snip->End()]

I find that disabling a tab can be disturbing for the user. One could
simply leave the tab enabled but refrain it from accepting any input.
That way the user can see what the tab is composed of. Another reason
one may wish to do this is because of the way sheets work. If you don't
want the third page to be enabled, you can return False in the
OnSetFocus() function. But if you do so the sheet will set the focus on
the fourth page. So, in the OnSetFocus() function for the third page,
you can always return CPropertyPage::OnSetFocus(), but if the page
shouldn't be accepting input, call EnableWindow(FALSE) beforehand, else
call EnableWindow(TRUE).

mcontest@universal.com

-----From: "Mukesh Prasad [Development Contractor]" 

A couple of (untried) suggestions:

Appearance:
    Provide a "WM_GETFONT" handler for your property-pages,
    and return a font with a grayed out appearance for "disabled"
    ones.

Function:
    Intercept WM_LBUTTONDOWN for your properth-sheet override
    class, calculate where the tab-buttons you want invalidated
    are, and don't pass the message along if button is supposed
    to be invalidated.

Not very nice, but doesn't look like MFC really intended this
functionality in the property sheets.

-----From: John Moulder 

Presumably such behaviour of property sheets/pages is contrary to the
Windows standards and conventions. I presume that you have a good reason for
such a facility in your sheets/pages.

You do not say which version of MFC or Windows you are using. If you are
using Windows 95 then it does all the property sheet processing, so things
become a little harder and you must do what MFC does with its own property
sheet implementation.

Here is a rough outline of the sort of thing that is required, off the top
of my head with no guarantees..

I am looking at the 16 bit dlgprop.cpp file.

CTabItem is the object in the row of tabs. CTabItem has a draw function that
draws the tabs; this is probabbly the bit you should change to draw the
disabled tab. You could reimplement the CTabItem to do this.

You would also have to reimplement the CTabControl to add so mechanism for
enabling and disabling the tabs/property sheets. Each tab item would require
a boolean variable to indicate its state. If it was disabled then it would
be drawn greyed out. Additionally, you would have to handle clicks, key
press, etc events when the user clicks on the diasabled tab. Presumably, if
the tab is disabled then you do not want the user to be able to activate
that property page.

It looks reasonably messy with a lot of reusing/redefining/copying the MFC
source code, and you may stumble across something serious tahn will stop
things working.

-----From: Dicky Singh 

This can be alternatively be accomplished by using owner drawn tabs in a 
CTabCtrl.  You can use the "nested dialogs" logic to set up pages etc.

// Dicky
// Dicky@Landmark.com





| Вернуться в корень Архива |