Joe you mentioned passing a pointer with the data to the PAGE. The data is in
the sheet. I guess sometimes data hiding can't be perfectly achieved then.
"WITHOUT A GETTER \ SETTER" type of function call. Seems fair enough with
large blocks of data.
Thanks for your insight on this.
"Joseph M. Newcomer" wrote:
See below...
On Fri, 19 Dec 2008 14:08:01 -0800, Jimbo_Jimbob_Jiminator
<JimboJimbobJiminator@discussions.microsoft.com> wrote:
Joe,
OK so the SHEET send messages to the PAGEs. And, the SHEET has an exposed
interface. This is where I am not sure how much to use the interface (public
members) and how much to use messages between the dialog and SHEET.
****
This is really a judgment call. I can easily argue in favor or against either approach.
As long as the sheet knows nothing about the implementation of the pages, and the
interface presented at the sheet level to the client of the sheet also hides the
organization and meaning of the pages, I consider the use of public members of the
property sheet a clean interface.
If you are using > VS6, note that the message handlers are erroneously declared as
'public' members; change this to 'protected'. Not in the entire history of MFC has it
made any logical sense to make handlers be public methods. The continuing failure to
declare them protected is a design error of the wizard. Also, no control member variables
should ever be public. Due again to a design error in the wizards, the "Add Variable"
defaults to marking these variables as 'public'. Mark them as 'protected'. The only
public members should be the IDD symbol, the constructor and destructor, and the methods
you wish to present as the interface.
joe
****
"Joseph M. Newcomer" wrote:
*->You just SendMessage to the sheet, and it worries about dispatching;
*->You can use member functions of the property sheet subclass because
-->that is your external interface.
(I cut the first line of yours (above) from a separate reply farther up in
this thread.)
From your response, you use SendMessage to the sheet. But also, you can use
member functions. Where is the line.
*****
About here. Or four inches to the left.
Seriously, you get to draw it. The choice of methods vs. messages is largely an aesthetic
argument most of the time.
*****
I understand that the member functions put in by MSoft, ShowWindow(),
Create(), etc. must be used as a member function. That is how they are
implemented.
****
Yes, but that's a different issue. You get to decide, for your interface, how you want to
implement it
****
But, what about all the functionality that I am adding? Should I try to
implement as much of my own code as possible as message mapped?
****
It is up to you. I'd probably favor public methods most of the time, but it depends on a
lot of factors, such as whether or not I want to make any of the C++ interface visible.
For plug-ins, I tend to favor messaging. Your Mileage May Vary. Void Where Prohibited By
Law. Contains Small Parts, Not Suitable For Children Under The Age of 3. May Cause
Nausea, Headache, Or Constipation.
That is, there is no hard-and-fast criterion here. Each mechanism has its powers and
flaws. Messaging restricts what you can send, and enforces how you send it. If you use
public methods, their implementation will probably use SendMessage, or
SendMessageToDescendants. But then, you can change the nature of what is handled
transparently.
****
And I understand the dialog and app must not access anything in the PAGEs at
all.
I also see that the SHEET should know nothing about the PAGEs. What is the
best mechanism then to get data into the PAGE at the actual transfer level.
****
I favor SendMessageToDecendants. One simple approach is to specify a message type and a
WPARAM/LPARAM pair. Another I favor is to specify just one message type, WPARAM encodes
the type of the data, and LPARAM encodes the parameter to the notification, which can be a
pointer to a struct, e.g.,
/************************************************************************************
* UWM_NOTIFY_PAGE
* WPARAM: (WPARAM)(InfoType): THe type of the information
*
* LPARAM: (LPARAM)lParam: The value associated with the InfoType. See
* the defintion of InfoType
* LRESULT:
* Depends on the InfoType
************************************************************************************/
static const UINT UWM_NOTIFY_PAGE = ::RegisterWindowMessage(
_T("UWM_NOTIFY_PAGE") _T("guid here"));
class CMyPropertySheet : public CPropertySheet {
protected:
typedef enum {
NAME, // (LPARAM)(const CString*) the name of the person
HEIGHT, // (LPARAM) the height of the person in mm
...more definitions here
} InfoType;
public:
void SetName(const CString & name) ;
void SetHeight(UINT height);
...
};
void CMyPropertySheet::SetName(const CString & name)
{
SendMessageToDescendants(UWM_NOTIFY_PAGE,
NAME,
(LPARAM)&name);
}
joe
Let's say a PAGE needs initialization for the user has an edit box with 1200
characters, 20 controls (combo's etc.) to populate with data. The page sends
a message to the main window to be initialized. The main window sends a
message to SHEET to do it. The SHEET sends the "Decendants" message. But,
there is 2000 byte of data to transfer. Do you send the pointer to the data
in the message to the PAGE?
If so, now the PAGE is directly accessing data in
the SHEET; Not good. The SHEET knows nothing about the PAGE so it doesn't
know what subset of the 5k of data it has to give to the page. At the rubber
and asphalt level, how does this transaction of data occur?
****
No, it is a SendMessage, it is synchronous, it is not "passing data from the sheet" it is
passing data. Nobody cares where the data is.
You would not pass 2000 bytes of "mixed data" which the control has to sort out, you would
pass either a pointer to a value (as I show above) or a pointer to a struct full of
values.
void CMyPropertySheet::SetEverything(const Everything & values)
{
SendMessageToDescendants(UWM_NOTIFY_PAGE,
EVERYTHING,
(LPARAM)&values);
}
void CSomePage::OnNotifyPage(WPARAM wParam, LPARAM lParam)
{
switch(wParam)
{
case EVERYTHING:
SetEverything( (const Everything *) lParam);
break;
}
}
void CSomePage::SetEverything(const Everything * values)
{
c_Name.SetWindowText(values->name);
c_Height.SetWIndowText(values->height);
...
}
If you don't like the ugly switch statement, then you define messages like
UWM_SET_EVERYTHING, UWM_SET_NAME, UWM_SET_HEIGHT, etc.
These are just aesthetic decisions. Some people prefer one, some prefer another. I tend
to favor the lots-of-different-messages approach.
joe
*****
Jim
Jim
"Joseph M. Newcomer" wrote:
See below...
On Fri, 19 Dec 2008 12:41:30 -0800, Jimbo_Jimbob_Jiminator
<JimboJimbobJiminator@discussions.microsoft.com> wrote:
Joe,
Thanks, it appears that sending the messages to the PAGE or SHEET may be
overkill for my little utility. I am going to implement some messaging anyway
for the experience. As you can see from my previous conversation with AliR. I
am having trouble deciding when to message and when to just use member
functions. I suppose there is a lot of overlap there.
****
How is it "overkill"? Besides, the point of this is that if the program is small, you are
developing a pattern so that the next time you need it, it is in your head.
You can use member functions of the property sheet subclass because that is your external
interface. You would never call methods of a page because not even the property sheet
should know or care what is on the pages.
joe
*****
By the way, if I haven't told you before:
Your site is FANTASTIC!
I found it some time ago (couple of years) and find it very useful.
If your wondering "He found my site a couple of years ago why isn't he more
up to speed?"
Up to this point, I have only been maintaining some existing Windows based
utilities. Currently, I have to write a Windows utility from the get-go. I
usually do embedded micro-controller programming (usually without an OS or
just a rudimentary task-switcher). Up until 4 or 5 years ago, the embedded
compilers did not support C++ or at least the company didn't pony up the cash
to buy the latest. I decided to stay with MFC this go-around as I am somewhat
familiar with it from maintaining other MFC applications.
I am told I should move to C# and .NET.
Just Great...!#$%!@...sassa...frassa...&*&^%%.
I see I have many years to make up on the Window learning curve.
Regards,
Jim
"Joseph M. Newcomer" wrote:
Registering window messages is trivial; see my essay on message management on my MVP Tips
site.
joe
On Fri, 19 Dec 2008 10:34:08 -0800, Jimbo_Jimbob_Jiminator
<JimboJimbobJiminator@discussions.microsoft.com> wrote:
"Joseph M. Newcomer" wrote:
See below...
On Fri, 19 Dec 2008 07:15:01 -0800, Jimbo_Jimbob_Jiminator
<JimboJimbobJiminator@discussions.microsoft.com> wrote:
In a previous post a while back, Joe pointed out that my structure was
incorrect on my app (in fact, I believe the quote was, paraphrased, "that
kind of code sets my teeth on edge").
I was, and still am, sending messages to the parent dialog. I can send a
message to the parent dialog from the Property Pages but have not had any
luck with the reverse.
****
I find SendMessageToDescendants to be a good technique. I use Registered Window Messages
to do this. If a page does not recognize the message, or the page does not exist, nothing
happens, no loss. If a page cares about the notification, it handles it. If several
pages care about the notification, they all handle it. Completely general, works right
all the time.
****
=========
Thanks Joe. I will look at this this. I have found the Message to Siblings
(forgot the exact name) but of course, that is not what I want. I like your
other solution farther down because I don't have to investigate registering
Windows messages right away.
=========
I am trying to move it in the right direction by sending messages to the
Property Page from the parent.
To send a message to the parent I use:
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
LRESULT Rslt = ::SendMessage(m_pMainWnd->m_hWnd ,UWM_INIT_PG1, 0, 0);
****
If you have m_pMainWnd, why not write
LRESULT Rst = m_pMainWnd->SendMessage(UWM_INIT_PG1);
and be done with it. Why use the raw ::SendMessage?
****
=========
I will give this a try first! Thanks.
Some of my Yahoo/Google searches on sending messages to PropPAGEs found
others that were having difficulty getting the messaging to work too. I
thought maybe they were special, as far a message routing, because of the
SHEET being in the middle.
=========