Creating dialog controls at run-time

I've been researching how to do this, but whenever I try what other
people do, I get very bad results. But my challenge doesn't end there.
The number of controls I want to create is only known at run-time. The
problems I face are manifold:

1. The code most people use fails badly. Not only is the font
unconventionally big, but when I click the checkbox I create, the whole
dialog disappears. If that's not enough, the pointer to the control is
NULL when the dialog's destructor is called, so I can't delete the
instance, and get a memory leak message when the program ends:
CADialog::~CADialog() {
	if (m_pButton != NULL) //this is always NULL at this point
          delete m_pButton;
}

BOOL CADialog::OnInitDialog() {
	CDialog::OnInitDialog();
	CButton *m_pButton = new CButton();

	DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP |
BS_AUTOCHECKBOX;
	CRect rect(5, 5, 100, 30);
	m_pButton->Create("hey man", dwStyle, rect, this, 1);
I also tried CArray<CButton, const CButton &> m_buttons as a member,
which fixed the memory leak problem, as long as I didn't use members
like Add(), and SetAtGrow(), since CButton doesn't have a copy
constructor.

2. How do you choose the resource ID for the control? I've got 1 there,
because the choice obviously seems arbitrary. Does it matter what the
number is, as long as it is unique among the other controls in that
dialog?

3. Since the number of controls is dynamic, so should be the size of
the dialog. This seems pretty straight-forward, but I have some
questions.
This should do nothing, right? I put it in the OnInitDialog():
	WINDOWPLACEMENT placement;
	VERIFY(GetWindowPlacement(&placement));
	VERIFY(SetWindowPlacement(&placement));
Well it doesn't. The VERIFYs don't stop the program, but the dialog
moves to the upper-left corner of what I think is called the client
area of the parent dialog. Other than that, however, the window changes
size predictably.

I haven't connected any messages to the control. All the code you see
for the checkbox (except the declaration of the variable, and the
initalization to NULL) is shown above.

0
2/24/2005 9:19:42 PM
vc.mfc 33608 articles. 0 followers. Follow

14 Replies
832 Views

Similar Articles

[PageSpeed] 24

"Jo" <JoJoTwilligo@hotmail.com> wrote in message
news:1109279982.663792.229860@o13g2000cwo.googlegroups.com...
> I've been researching how to do this, but whenever I try what other
> people do, I get very bad results. But my challenge doesn't end there.
> The number of controls I want to create is only known at run-time. The
> problems I face are manifold:
>
> 1. The code most people use fails badly. Not only is the font
> unconventionally big, but when I click the checkbox I create, the whole
> dialog disappears. If that's not enough, the pointer to the control is
> NULL when the dialog's destructor is called, so I can't delete the
> instance, and get a memory leak message when the program ends:
> CADialog::~CADialog() {
> if (m_pButton != NULL) //this is always NULL at this point
>           delete m_pButton;
> }
>
> BOOL CADialog::OnInitDialog() {
> CDialog::OnInitDialog();
> CButton *m_pButton = new CButton();

    m_pButton = new CButton();

You shouldn't delcare button variable on the Stack.  From the looks of it
you already have a variable in your class decleration so remove the CButton
* from in line where you new the button object.  What you are doing here is
assigning the object returned from new CButton to a local variable which
will go out of scope at the end of OnInitDialog and the pointer will be
lost.

>
> DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP |
> BS_AUTOCHECKBOX;
> CRect rect(5, 5, 100, 30);
> m_pButton->Create("hey man", dwStyle, rect, this, 1);
> I also tried CArray<CButton, const CButton &> m_buttons as a member,
> which fixed the memory leak problem, as long as I didn't use members
> like Add(), and SetAtGrow(), since CButton doesn't have a copy
> constructor.
>

If you are declaring your Array like that you won't be able to do Add.  If
you delcare it like this then you would be able to CArray<CButton *,CButton
*&>.
But CArray<CButton,CButton &> should be fine, as long as you set the size of
the array before you start creating your buttons.

CArray<CButton,CButton &> m_Buttons

BOOL CMyDlg::OnInitDialog()
{
    m_Buttons.SetSize(m_NumButtons);

    for (int i = 0; i < m_NumButtons;i++)
    {
        m_Buttons.GetAt(i).Create(.....);
    }
}


> 2. How do you choose the resource ID for the control? I've got 1 there,
> because the choice obviously seems arbitrary. Does it matter what the
> number is, as long as it is unique among the other controls in that
> dialog?
>

No it doesn't matter.

> 3. Since the number of controls is dynamic, so should be the size of
> the dialog. This seems pretty straight-forward, but I have some
> questions.
> This should do nothing, right? I put it in the OnInitDialog():
> WINDOWPLACEMENT placement;
> VERIFY(GetWindowPlacement(&placement));
> VERIFY(SetWindowPlacement(&placement));
> Well it doesn't. The VERIFYs don't stop the program, but the dialog
> moves to the upper-left corner of what I think is called the client
> area of the parent dialog. Other than that, however, the window changes
> size predictably.
>

You should use SetWindowPos to change the size of you dialog box.

> I haven't connected any messages to the control. All the code you see
> for the checkbox (except the declaration of the variable, and the
> initalization to NULL) is shown above.
>

You can use ON_CONTROL_RANGE to direct the notifications of all the controls
to one method.  the system will pass the id of the button that is sending
the notification to that method.

#define ID_CHECK_FIRST    1000
#define ID_CHECK_LAST     2000        //This will allow you to make up to a
1000 checkboxes.

ON_CONTROL_RANGE(BN_CLICKED,ID_CHECK_FIRST,ID_CHECK_MAX,OnCheckClicked)

void CMyDlg::OnCheckClicked(int ID)
{
    .....
}

AliR.


0
AliR1 (391)
2/24/2005 9:45:24 PM
It was a dark and stormy night when "AliR" <AliR@newsgroup.nospam>
wrote:

>
>"Jo" <JoJoTwilligo@hotmail.com> wrote in message
>news:1109279982.663792.229860@o13g2000cwo.googlegroups.com...
>> I've been researching how to do this, but whenever I try what other
>> people do, I get very bad results. But my challenge doesn't end there.
>> The number of controls I want to create is only known at run-time. The
>> problems I face are manifold:
>>
>> 1. The code most people use fails badly. Not only is the font
>> unconventionally big, but when I click the checkbox I create, the whole
>> dialog disappears. If that's not enough, the pointer to the control is
>> NULL when the dialog's destructor is called, so I can't delete the
>> instance, and get a memory leak message when the program ends:
>> CADialog::~CADialog() {
>> if (m_pButton != NULL) //this is always NULL at this point
>>           delete m_pButton;
>> }
>>
>> BOOL CADialog::OnInitDialog() {
>> CDialog::OnInitDialog();
>> CButton *m_pButton = new CButton();
>
>    m_pButton = new CButton();
	*slap of the forehead* Of course! The pointer is made a local,
so the member one never gets assigned. As you might have guessed, I
was adapting old code.
	But this only deals with the leak problem. The much bigger
problem of the dialog disappearing when I click a control remains.

>
>You shouldn't delcare button variable on the Stack.  From the looks of it
>you already have a variable in your class decleration so remove the CButton
>* from in line where you new the button object.  What you are doing here is
>assigning the object returned from new CButton to a local variable which
>will go out of scope at the end of OnInitDialog and the pointer will be
>lost.
>
>>
>> DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP |
>> BS_AUTOCHECKBOX;
>> CRect rect(5, 5, 100, 30);
>> m_pButton->Create("hey man", dwStyle, rect, this, 1);
>> I also tried CArray<CButton, const CButton &> m_buttons as a member,
>> which fixed the memory leak problem, as long as I didn't use members
>> like Add(), and SetAtGrow(), since CButton doesn't have a copy
>> constructor.
>>
>
>If you are declaring your Array like that you won't be able to do Add.  If
>you delcare it like this then you would be able to CArray<CButton *,CButton
>*&>.
>But CArray<CButton,CButton &> should be fine, as long as you set the size of
>the array before you start creating your buttons.
>
>CArray<CButton,CButton &> m_Buttons
>
>BOOL CMyDlg::OnInitDialog()
>{
>    m_Buttons.SetSize(m_NumButtons);
>
>    for (int i = 0; i < m_NumButtons;i++)
>    {
>        m_Buttons.GetAt(i).Create(.....);

	I don't think I should be using GetAt(). It will create
another instance, which is destroyed at the end of this statement.

>    }
>}
>
>
>> 2. How do you choose the resource ID for the control? I've got 1 there,
>> because the choice obviously seems arbitrary. Does it matter what the
>> number is, as long as it is unique among the other controls in that
>> dialog?
>>
>
>No it doesn't matter.
>
>> 3. Since the number of controls is dynamic, so should be the size of
>> the dialog. This seems pretty straight-forward, but I have some
>> questions.
>> This should do nothing, right? I put it in the OnInitDialog():
>> WINDOWPLACEMENT placement;
>> VERIFY(GetWindowPlacement(&placement));
>> VERIFY(SetWindowPlacement(&placement));
>> Well it doesn't. The VERIFYs don't stop the program, but the dialog
>> moves to the upper-left corner of what I think is called the client
>> area of the parent dialog. Other than that, however, the window changes
>> size predictably.
>>
>
>You should use SetWindowPos to change the size of you dialog box.

	Hmmm... are you sure? It's much more difficult to use, because
there is not a complementary GetWindowsPos(). How do I call
SetWindowsPos() w/out clobbering anything?

>
>> I haven't connected any messages to the control. All the code you see
>> for the checkbox (except the declaration of the variable, and the
>> initalization to NULL) is shown above.
>>
>
>You can use ON_CONTROL_RANGE to direct the notifications of all the controls
>to one method.  the system will pass the id of the button that is sending
>the notification to that method.
>
>#define ID_CHECK_FIRST    1000
>#define ID_CHECK_LAST     2000        //This will allow you to make up to a
>1000 checkboxes.
>
>ON_CONTROL_RANGE(BN_CLICKED,ID_CHECK_FIRST,ID_CHECK_MAX,OnCheckClicked)
>
>void CMyDlg::OnCheckClicked(int ID)
>{
>    .....
>}
>
>AliR.
	Well, I'll be able to get there when I can get the dialog to
stay around long enough for me to handle the message.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
0
angus294 (13)
2/24/2005 10:08:03 PM
> *slap of the forehead* Of course! The pointer is made a local,
> so the member one never gets assigned. As you might have guessed, I
> was adapting old code.
> But this only deals with the leak problem. The much bigger
> problem of the dialog disappearing when I click a control remains.

I don't know why it disappears. Not enough info here for that. Sounds like
an unhandled exception.

>
> I don't think I should be using GetAt(). It will create
> another instance, which is destroyed at the end of this statement.

What version of VC++ are you using. If you are using version 6.0 what you
said would be true.  If you are using 2002 and above, get at returns a
reference, so no copy is involved.  So if you are using V6.0 then you need
to use the [] operator!!!

>
> Hmmm... are you sure? It's much more difficult to use, because
> there is not a complementary GetWindowsPos(). How do I call
> SetWindowsPos() w/out clobbering anything?
>

GetWindowRect, GetClientRect, take your pick.


Here is an example

http://www.learnstar.com/alir/dynamicbuttons.zip


AliR.


0
AliR1 (391)
2/24/2005 11:15:15 PM
It was a dark and stormy night when "AliR" <AliR@newsgroup.nospam>
wrote:

>> *slap of the forehead* Of course! The pointer is made a local,
>> so the member one never gets assigned. As you might have guessed, I
>> was adapting old code.
>> But this only deals with the leak problem. The much bigger
>> problem of the dialog disappearing when I click a control remains.
>
>I don't know why it disappears. Not enough info here for that. Sounds like
>an unhandled exception.

	Actually, that's exactly what it was. Here I was concerned
with interfering identifiers, and that's exactly what I should have
been worried about!

>
>>
>> I don't think I should be using GetAt(). It will create
>> another instance, which is destroyed at the end of this statement.
>
>What version of VC++ are you using. If you are using version 6.0 what you
>said would be true.  If you are using 2002 and above, get at returns a
>reference, so no copy is involved.  So if you are using V6.0 then you need
>to use the [] operator!!!

	Really? 2002 does that, eh? Got rid of the ElementAt(), did
they? Yes, I have 6.0.

>> Hmmm... are you sure? It's much more difficult to use, because
>> there is not a complementary GetWindowsPos(). How do I call
>> SetWindowsPos() w/out clobbering anything?
>>
>
>GetWindowRect, GetClientRect, take your pick.

	Ok, but what do I do about parameters like pWndInsertAfter? I
see you've got NULL in that example you gave me, but I'm worried about
clobbering something. The same with nFlags. I don't know how to
extract a value for nFlags.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
0
angus294 (13)
2/25/2005 12:05:33 AM
Now I have a different problem. I'm creating a control at run-time,
but I don't know how big to make the rectangle. FWIW, all these
controls will be checkboxes. So is there any easy way to calculate how
much room the text will take?

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
0
angus294 (13)
2/25/2005 12:11:38 AM
"Angus March" <angus@hamgate.concordia.ca> wrote in message
news:juqs11hebabh7ir1ijmosak6pjbgo54i0s@4ax.com...
> Now I have a different problem. I'm creating a control at run-time,
> but I don't know how big to make the rectangle. FWIW, all these
> controls will be checkboxes. So is there any easy way to calculate how
> much room the text will take?
>

//Select a font into your dialog's device context (or any window, for that
matter).

CDC *dc = GetDC();

CFont SomeFont;
SomeFont.CreateFont(FontSize, 0, 0, 0, FW_NORMAL,
    false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
    DEFAULT_PITCH, FontFace);
CFont *pOldFont = dc->SelectObject(&SomeFont);

// then use GetTextExtent
CSize TextSize = dc->GetTextExtent(TheLabel);

dc->SelectObject(pOldFont);


> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption
=----


0
billt61 (145)
2/25/2005 1:24:08 AM
Well, the code you are using is not correct.

If you don't like the font, you can set it. Usually easily. For example, if you do, in the
dialog, 

CFont * f = GetFont();
control->SetFont(f);

then it will use the same font as the dialog.

Choose some range for controls like 10,000 to 11,000.

If you don't know the number of buttons unitl runtime, how can you have a destructor that
uses only a single variable?

You don't need to do a NULL test because delete works on a NULL pointer.

As usual, you are another person who is totally clueless about Hungarian Notation. If you
don't know how to use it, DON'T USE IT!!!!! 

You declare a local variable in OnInitDialog called m_pButton. This is clearly a blunder.
The m_ prefix means it is a class member variable NOT A LOCAL VARIABLE. So what has
probably happened here is that you either overrode the class name with a local name, or
you are really confused about naming conventions. 

Next, since there is only one button being created, there is no reason to create it at
runtime. Create it at design time. 

The use of a CRect with fixed constant bounds is nonsensical. These values might work on
your installation, with the current display driver, resolution, display, and system font
selelction, but it will not work anywhere else, so forget, forever, the notion of
hardwired constants in this context.

If you need to create a button, if there is only one button, create it at design time.
Period. No reason to create it dynamically. If you need to create buttons dynamically, you
should create a "prototype" button on the dialog at design time, assign it a control
variable, mark it as invisible, and use it to get GetWindowRect to get the correct size
for a button.Then, no matter what combination of video drivers, displays, resolution, and
fonts you encounter, you will always get a button of the right size. Sometimes I use only
the height and compute the width on the fly. I usually use a single-space or double-space
dimension on each side of the text width to compute the desired width.

AHA! I see you made the classic error! You used a HARDWIRED INTEGER VALUE for the button
ID. If you are creating buttons dynamically, you cannot use hardwired integer values. If
you are using hardwired integer values, you do not need to create them dynamically. And,
you chose the worst possible integer value, Your button looks like the OK button (IDOK is
1), so of course your dialog will close, because you ASKED IT TO!

If you had not overridden the name as a local name--and used the naming conventions
incorrectly--then you would not have had the memory leak. 

You choose the resource IDs by choosing a very high-numbered range. 

MoveWIndow/SetWindowPos can change the size of the dialog. SetWindowPlacement is almost
certainly the wrong call to use.

To connect the dynamic controls to a handler, use ON_CONTROL_RANGE or ON_COMMAND_RANGE.
					joe

On 24 Feb 2005 13:19:42 -0800, "Jo" <JoJoTwilligo@hotmail.com> wrote:

>I've been researching how to do this, but whenever I try what other
>people do, I get very bad results. But my challenge doesn't end there.
>The number of controls I want to create is only known at run-time. The
>problems I face are manifold:
>
>1. The code most people use fails badly. Not only is the font
>unconventionally big, but when I click the checkbox I create, the whole
>dialog disappears. If that's not enough, the pointer to the control is
>NULL when the dialog's destructor is called, so I can't delete the
>instance, and get a memory leak message when the program ends:
>CADialog::~CADialog() {
>	if (m_pButton != NULL) //this is always NULL at this point
>          delete m_pButton;
>}
>
>BOOL CADialog::OnInitDialog() {
>	CDialog::OnInitDialog();
>	CButton *m_pButton = new CButton();
>
>	DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP |
>BS_AUTOCHECKBOX;
>	CRect rect(5, 5, 100, 30);
>	m_pButton->Create("hey man", dwStyle, rect, this, 1);
>I also tried CArray<CButton, const CButton &> m_buttons as a member,
>which fixed the memory leak problem, as long as I didn't use members
>like Add(), and SetAtGrow(), since CButton doesn't have a copy
>constructor.
>
>2. How do you choose the resource ID for the control? I've got 1 there,
>because the choice obviously seems arbitrary. Does it matter what the
>number is, as long as it is unique among the other controls in that
>dialog?
>
>3. Since the number of controls is dynamic, so should be the size of
>the dialog. This seems pretty straight-forward, but I have some
>questions.
>This should do nothing, right? I put it in the OnInitDialog():
>	WINDOWPLACEMENT placement;
>	VERIFY(GetWindowPlacement(&placement));
>	VERIFY(SetWindowPlacement(&placement));
>Well it doesn't. The VERIFYs don't stop the program, but the dialog
>moves to the upper-left corner of what I think is called the client
>area of the parent dialog. Other than that, however, the window changes
>size predictably.
>
>I haven't connected any messages to the control. All the code you see
>for the checkbox (except the declaration of the variable, and the
>initalization to NULL) is shown above.

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/25/2005 1:34:24 AM
It was a dark and stormy night when Joseph M. Newcomer
<newcomer@flounder.com> wrote:

>If you don't know the number of buttons unitl runtime, how can you have a destructor that
>uses only a single variable?

	Well, I can't, but at that stage I was performing experiments
to see how the code would perform, and was happy to use a single
variable, rather than risk several man-hours on something that
wouldn't work.

>
>You don't need to do a NULL test because delete works on a NULL pointer.
>
>As usual, you are another person who is totally clueless about Hungarian Notation. If you
>don't know how to use it, DON'T USE IT!!!!! 

	So who says I am using it? Actually, I was going to make the
same comparison between you and Canadian Notation.

>
>You declare a local variable in OnInitDialog called m_pButton. This is clearly a blunder.
>The m_ prefix means it is a class member variable NOT A LOCAL VARIABLE. So what has
>probably happened here is that you either overrode the class name with a local name, or
>you are really confused about naming conventions. 

	You didn't read the whole thread, did you? You'll see that I
had no intension of making m_pButton local--or maybe you did read it,
but couldn't relate to it, 'cuz you don't make mistakes, do you?

>Next, since there is only one button being created, there is no reason to create it at
>runtime. Create it at design time. 

	Actually, you're still looking at the experimental code. The
release version will probably be initially supporting several dozen
controls, so I'll probably need to learn about scroll bars as well.

>The use of a CRect with fixed constant bounds is nonsensical. These values might work on
>your installation, with the current display driver, resolution, display, and system font
>selelction, but it will not work anywhere else, so forget, forever, the notion of
>hardwired constants in this context.

	The code is still just for experimental purposes.

>If you need to create a button, if there is only one button, create it at design time.
>Period. No reason to create it dynamically. If you need to create buttons dynamically, you
>should create a "prototype" button on the dialog at design time, assign it a control
>variable, mark it as invisible, and use it to get GetWindowRect to get the correct size
>for a button.Then, no matter what combination of video drivers, displays, resolution, and
>fonts you encounter, you will always get a button of the right size. Sometimes I use only
>the height and compute the width on the fly. I usually use a single-space or double-space
>dimension on each side of the text width to compute the desired width.

	Still experimental code.

>AHA! I see you made the classic error! You used a HARDWIRED INTEGER VALUE for the button
>ID. If you are creating buttons dynamically, you cannot use hardwired integer values. If

	Persistently experimental

>you are using hardwired integer values, you do not need to create them dynamically. And,
>you chose the worst possible integer value, Your button looks like the OK button (IDOK is
>1), so of course your dialog will close, because you ASKED IT TO!

	But that wasn't supposed to be part of the experiment. Indeed,
it was the resource id of 1 that caused OnOK() to be called.

>If you had not overridden the name as a local name--and used the naming conventions
>incorrectly--then you would not have had the memory leak. 

	Well... if you knew that I had declared the variable as a
member, you must have seen that it was not intended to be overriden
and used as a local.

	But all your other advice was very useful. Thanks


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
0
angus294 (13)
2/25/2005 3:04:37 AM
I am so sorry Angus, I woke up this morning and remembered that you are
giving ID 1 to your button, that's IDOK, and that's why the dialog is going
away.


AliR.


"Angus March" <angus@hamgate.concordia.ca> wrote in message
news:1eps11t5b0sauh7h6kfrld0qttjhq47hoa@4ax.com...
> It was a dark and stormy night when "AliR" <AliR@newsgroup.nospam>
> wrote:
>
> >> *slap of the forehead* Of course! The pointer is made a local,
> >> so the member one never gets assigned. As you might have guessed, I
> >> was adapting old code.
> >> But this only deals with the leak problem. The much bigger
> >> problem of the dialog disappearing when I click a control remains.
> >
> >I don't know why it disappears. Not enough info here for that. Sounds
like
> >an unhandled exception.
>
> Actually, that's exactly what it was. Here I was concerned
> with interfering identifiers, and that's exactly what I should have
> been worried about!
>
> >
> >>
> >> I don't think I should be using GetAt(). It will create
> >> another instance, which is destroyed at the end of this statement.
> >
> >What version of VC++ are you using. If you are using version 6.0 what you
> >said would be true.  If you are using 2002 and above, get at returns a
> >reference, so no copy is involved.  So if you are using V6.0 then you
need
> >to use the [] operator!!!
>
> Really? 2002 does that, eh? Got rid of the ElementAt(), did
> they? Yes, I have 6.0.
>
> >> Hmmm... are you sure? It's much more difficult to use, because
> >> there is not a complementary GetWindowsPos(). How do I call
> >> SetWindowsPos() w/out clobbering anything?
> >>
> >
> >GetWindowRect, GetClientRect, take your pick.
>
> Ok, but what do I do about parameters like pWndInsertAfter? I
> see you've got NULL in that example you gave me, but I'm worried about
> clobbering something. The same with nFlags. I don't know how to
> extract a value for nFlags.
>
>
> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption
=----


0
AliR1 (391)
2/25/2005 3:15:03 PM
See below...
On Thu, 24 Feb 2005 22:04:37 -0500, Angus March <angus@hamgate.concordia.ca> wrote:

>It was a dark and stormy night when Joseph M. Newcomer
><newcomer@flounder.com> wrote:
>
>>If you don't know the number of buttons unitl runtime, how can you have a destructor that
>>uses only a single variable?
>
>	Well, I can't, but at that stage I was performing experiments
>to see how the code would perform, and was happy to use a single
>variable, rather than risk several man-hours on something that
>wouldn't work.
>
>>
>>You don't need to do a NULL test because delete works on a NULL pointer.
>>
>>As usual, you are another person who is totally clueless about Hungarian Notation. If you
>>don't know how to use it, DON'T USE IT!!!!! 
>
>	So who says I am using it? Actually, I was going to make the
>same comparison between you and Canadian Notation.
*****
You are. m_ is part of Hungarian Notation. So you ARE using it. No question whatsoever.
And the name of your variable was m_pButton, and the "p" prefix also is part of Hungarian
Notation. So there is no question you are using it. You yourself, by the notation you have
used, has said you are using it. And, by declaring a local name with m_ in the name, you
are using it incorrectly.
*****
>
>>
>>You declare a local variable in OnInitDialog called m_pButton. This is clearly a blunder.
>>The m_ prefix means it is a class member variable NOT A LOCAL VARIABLE. So what has
>>probably happened here is that you either overrode the class name with a local name, or
>>you are really confused about naming conventions. 
>
>	You didn't read the whole thread, did you? You'll see that I
>had no intension of making m_pButton local--or maybe you did read it,
>but couldn't relate to it, 'cuz you don't make mistakes, do you?
*****
You may have had no intention of doing it, but you did it. I saw the code. If you didn't
mean to do it, why did you put it in the code example? Then you ask a question whose
answer is clearly related to this mistake, and it gets answered.

I didn't make a mistake; I answered a question you asked about why a particular error
occurred, and it was obvious from the code why the error occurred. While you may not have
intended to make the variable local (Yes, I saw that, but the comment was irrelevant in
the light of the obvious bug), you most certainly did.
*****
>
>>Next, since there is only one button being created, there is no reason to create it at
>>runtime. Create it at design time. 
>
>	Actually, you're still looking at the experimental code. The
>release version will probably be initially supporting several dozen
>controls, so I'll probably need to learn about scroll bars as well.
>
>>The use of a CRect with fixed constant bounds is nonsensical. These values might work on
>>your installation, with the current display driver, resolution, display, and system font
>>selelction, but it will not work anywhere else, so forget, forever, the notion of
>>hardwired constants in this context.
>
>	The code is still just for experimental purposes.
******
If you post an example that says "I'm doing this way" we have no way to know that you are
not REALLY doing it the way you say you are doing it!
******
>
>>If you need to create a button, if there is only one button, create it at design time.
>>Period. No reason to create it dynamically. If you need to create buttons dynamically, you
>>should create a "prototype" button on the dialog at design time, assign it a control
>>variable, mark it as invisible, and use it to get GetWindowRect to get the correct size
>>for a button.Then, no matter what combination of video drivers, displays, resolution, and
>>fonts you encounter, you will always get a button of the right size. Sometimes I use only
>>the height and compute the width on the fly. I usually use a single-space or double-space
>>dimension on each side of the text width to compute the desired width.
>
>	Still experimental code.
>
>>AHA! I see you made the classic error! You used a HARDWIRED INTEGER VALUE for the button
>>ID. If you are creating buttons dynamically, you cannot use hardwired integer values. If
>
>	Persistently experimental
>
>>you are using hardwired integer values, you do not need to create them dynamically. And,
>>you chose the worst possible integer value, Your button looks like the OK button (IDOK is
>>1), so of course your dialog will close, because you ASKED IT TO!
>
>	But that wasn't supposed to be part of the experiment. Indeed,
>it was the resource id of 1 that caused OnOK() to be called.
*****
If I were doing this, I would not have used a hardwired constant, even in an experiment.
And I certainly would not have used 1. Even in an experiment. 
*****
>
>>If you had not overridden the name as a local name--and used the naming conventions
>>incorrectly--then you would not have had the memory leak. 
>
>	Well... if you knew that I had declared the variable as a
>member, you must have seen that it was not intended to be overriden
>and used as a local.
*****
But you DID override it in your code example! I quote from your actual posted source code:

>BOOL CADialog::OnInitDialog() {
>	CDialog::OnInitDialog();
>	CButton *m_pButton = new CButton();

Now tell me exactly what part of "You'll see that I had no intension of making m_pButton
local" that I missed? If you post completely incorrect code and ask "what's wrong with my
code", you will get an answer. You complained that m_pButton was NULL, and it is clear
that it must at that point be a member variable, then you show a piece of code that
guarantees it cannot be initialized, and wonder why it is not initialized,  you get an
answer. It is impossible to read your intentions when you clearly show incorrect code.
*****
>
>	But all your other advice was very useful. Thanks
>
>
>----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
>----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/25/2005 6:14:35 PM
Everyone seems to think that GetDC makes sense. You should not use GetDC in an MFC program
unless there is some compelling reason to do so. There is no such reason here.

CClientDC dc(this);
CFont SomeFont;
SomeFont.CreateFont(...);
CFont * old = dc.SelectObject(&SomeFont);
CSize TextSize = dc.GetTextExtent(label);
dc.SelectObject(old);

Note that you never need to worry about how to delete the DC; it happens automatically
when the CClientDC destructor is executed.
					joe

On Thu, 24 Feb 2005 19:24:08 -0600, "Bill Thompson" <billt61@rgv.rr.com> wrote:

>"Angus March" <angus@hamgate.concordia.ca> wrote in message
>news:juqs11hebabh7ir1ijmosak6pjbgo54i0s@4ax.com...
>> Now I have a different problem. I'm creating a control at run-time,
>> but I don't know how big to make the rectangle. FWIW, all these
>> controls will be checkboxes. So is there any easy way to calculate how
>> much room the text will take?
>>
>
>//Select a font into your dialog's device context (or any window, for that
>matter).
>
>CDC *dc = GetDC();
>
>CFont SomeFont;
>SomeFont.CreateFont(FontSize, 0, 0, 0, FW_NORMAL,
>    false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
>    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
>    DEFAULT_PITCH, FontFace);
>CFont *pOldFont = dc->SelectObject(&SomeFont);
>
>// then use GetTextExtent
>CSize TextSize = dc->GetTextExtent(TheLabel);
>
>dc->SelectObject(pOldFont);
>
>
>> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
>News==----
>> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
>Newsgroups
>> ----= East and West-Coast Server Farms - Total Privacy via Encryption
>=----
>

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/25/2005 6:45:59 PM
It was a dark and stormy night when Joseph M. Newcomer
<newcomer@flounder.com> wrote:

>See below...
>On Thu, 24 Feb 2005 22:04:37 -0500, Angus March <angus@hamgate.concordia.ca> wrote:
>
>>It was a dark and stormy night when Joseph M. Newcomer
>><newcomer@flounder.com> wrote:
>>
>>>If you don't know the number of buttons unitl runtime, how can you have a destructor that
>>>uses only a single variable?
>>
>>	Well, I can't, but at that stage I was performing experiments
>>to see how the code would perform, and was happy to use a single
>>variable, rather than risk several man-hours on something that
>>wouldn't work.
>>
>>>
>>>You don't need to do a NULL test because delete works on a NULL pointer.
>>>
>>>As usual, you are another person who is totally clueless about Hungarian Notation. If you
>>>don't know how to use it, DON'T USE IT!!!!! 
>>
>>	So who says I am using it? Actually, I was going to make the
>>same comparison between you and Canadian Notation.
>*****
>You are. m_ is part of Hungarian Notation. So you ARE using it. No question whatsoever.
>And the name of your variable was m_pButton, and the "p" prefix also is part of Hungarian
>Notation. So there is no question you are using it. You yourself, by the notation you have
>used, has said you are using it. And, by declaring a local name with m_ in the name, you
>are using it incorrectly.
>*****

	I think I see what you are saying. If it does but one or two
things like a duck, (such as breathing oxygen or basing its biology on
carbon) and nothing else like a duck, it's a duck. So... I guess that
implies that when I'm overseas, I'm an American because my accent is
the same? With very few subtleties, the accent that all English
Canadians (west of New Brunswick) use is indistinguishable from
Hollywood-American, so there's no question whatsoever that we are all
Americans.
	Boy is that ever going to be embarrassing when I show up at
customs as an American with a Canadian passport. But now that I think
about it, all the customs officers I've seen in every country I've
visited have been so dim as to assume that I'm probably Canadian since
I'm producing a Canadian passport--the fools.

>I didn't make a mistake; I answered a question you asked about why a particular error
>occurred, and it was obvious from the code why the error occurred. While you may not have

	Ah, you "didn't make a mistake"--so this IS about your
infallibility (if you are looking for a career change, the pope
position will be open soon). But this wasn't about my coding error at
first, this was about me being "clueless" for not using Hungarian
Notation correctly. As it turns out, I was using Hungarian Notation
correctly, since my mistake was not in chosing the notation, but in an
oversight while trying to change a local variable to member.
	But either way, I can understand why you'd see me as
"clueless", because the bottom line is: I made a mistake. It's just
that a fallible person would have understood that this is a likely
mistake for another fallible person to make when moving a variable
from local to member.

>intended to make the variable local (Yes, I saw that, but the comment was irrelevant in
>the light of the obvious bug), you most certainly did.
>*****
>>
>>>Next, since there is only one button being created, there is no reason to create it at
>>>runtime. Create it at design time. 
>>
>>	Actually, you're still looking at the experimental code. The
>>release version will probably be initially supporting several dozen
>>controls, so I'll probably need to learn about scroll bars as well.
>>
>>>The use of a CRect with fixed constant bounds is nonsensical. These values might work on
>>>your installation, with the current display driver, resolution, display, and system font
>>>selelction, but it will not work anywhere else, so forget, forever, the notion of
>>>hardwired constants in this context.
>>
>>	The code is still just for experimental purposes.
>******
>If you post an example that says "I'm doing this way" we have no way to know that you are
>not REALLY doing it the way you say you are doing it!
>******
>>
>>>If you need to create a button, if there is only one button, create it at design time.
>>>Period. No reason to create it dynamically. If you need to create buttons dynamically, you
>>>should create a "prototype" button on the dialog at design time, assign it a control
>>>variable, mark it as invisible, and use it to get GetWindowRect to get the correct size
>>>for a button.Then, no matter what combination of video drivers, displays, resolution, and
>>>fonts you encounter, you will always get a button of the right size. Sometimes I use only
>>>the height and compute the width on the fly. I usually use a single-space or double-space
>>>dimension on each side of the text width to compute the desired width.
>>
>>	Still experimental code.
>>
>>>AHA! I see you made the classic error! You used a HARDWIRED INTEGER VALUE for the button
>>>ID. If you are creating buttons dynamically, you cannot use hardwired integer values. If
>>
>>	Persistently experimental
>>
>>>you are using hardwired integer values, you do not need to create them dynamically. And,
>>>you chose the worst possible integer value, Your button looks like the OK button (IDOK is
>>>1), so of course your dialog will close, because you ASKED IT TO!
>>
>>	But that wasn't supposed to be part of the experiment. Indeed,
>>it was the resource id of 1 that caused OnOK() to be called.
>*****
>If I were doing this, I would not have used a hardwired constant, even in an experiment.
>And I certainly would not have used 1. Even in an experiment. 
>*****
>>
>>>If you had not overridden the name as a local name--and used the naming conventions
>>>incorrectly--then you would not have had the memory leak. 
>>
>>	Well... if you knew that I had declared the variable as a
>>member, you must have seen that it was not intended to be overriden
>>and used as a local.
>*****
>But you DID override it in your code example! I quote from your actual posted source code:
>
>>BOOL CADialog::OnInitDialog() {
>>	CDialog::OnInitDialog();
>>	CButton *m_pButton = new CButton();
>
>Now tell me exactly what part of "You'll see that I had no intension of making m_pButton
>local" that I missed? If you post completely incorrect code and ask "what's wrong with my
>code", you will get an answer. You complained that m_pButton was NULL, and it is clear
>that it must at that point be a member variable, then you show a piece of code that
>guarantees it cannot be initialized, and wonder why it is not initialized,  you get an
>answer. It is impossible to read your intentions when you clearly show incorrect code.
>*****
>>
>>	But all your other advice was very useful. Thanks
>>
>>
>>----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
>>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
>>----= East and West-Coast Server Farms - Total Privacy via Encryption =----
>
>Joseph M. Newcomer [MVP]
>email: newcomer@flounder.com
>Web: http://www.flounder.com
>MVP Tips: http://www.flounder.com/mvp_tips.htm


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
0
angus294 (13)
2/25/2005 7:42:04 PM
See below...
On Fri, 25 Feb 2005 14:42:04 -0500, Angus March <angus@hamgate.concordia.ca> wrote:

>It was a dark and stormy night when Joseph M. Newcomer
><newcomer@flounder.com> wrote:
>
>>See below...
>>On Thu, 24 Feb 2005 22:04:37 -0500, Angus March <angus@hamgate.concordia.ca> wrote:
>>
>>>It was a dark and stormy night when Joseph M. Newcomer
>>><newcomer@flounder.com> wrote:
>>>
>>>>If you don't know the number of buttons unitl runtime, how can you have a destructor that
>>>>uses only a single variable?
>>>
>>>	Well, I can't, but at that stage I was performing experiments
>>>to see how the code would perform, and was happy to use a single
>>>variable, rather than risk several man-hours on something that
>>>wouldn't work.
>>>
>>>>
>>>>You don't need to do a NULL test because delete works on a NULL pointer.
>>>>
>>>>As usual, you are another person who is totally clueless about Hungarian Notation. If you
>>>>don't know how to use it, DON'T USE IT!!!!! 
>>>
>>>	So who says I am using it? Actually, I was going to make the
>>>same comparison between you and Canadian Notation.
>>*****
>>You are. m_ is part of Hungarian Notation. So you ARE using it. No question whatsoever.
>>And the name of your variable was m_pButton, and the "p" prefix also is part of Hungarian
>>Notation. So there is no question you are using it. You yourself, by the notation you have
>>used, has said you are using it. And, by declaring a local name with m_ in the name, you
>>are using it incorrectly.
>>*****
>
>	I think I see what you are saying. If it does but one or two
>things like a duck, (such as breathing oxygen or basing its biology on
>carbon) and nothing else like a duck, it's a duck. So... I guess that
>implies that when I'm overseas, I'm an American because my accent is
>the same? With very few subtleties, the accent that all English
>Canadians (west of New Brunswick) use is indistinguishable from
>Hollywood-American, so there's no question whatsoever that we are all
>Americans.
>	Boy is that ever going to be embarrassing when I show up at
>customs as an American with a Canadian passport. But now that I think
>about it, all the customs officers I've seen in every country I've
>visited have been so dim as to assume that I'm probably Canadian since
>I'm producing a Canadian passport--the fools.
*****
I think there was a lot more here: if you see something that resembles a duck, has
feathers, a large orange bill, webbed feet, lays eggs, qucks, swims, and flies, there is a
very good chance it is a duck. I saw an example that violated just about every known rule
about writing robust code, including misuse of notation, declaring a local variable that
overrode a member variable name, using constants, etc., etc., and therefore I'm reasonably
safe in assuming it is a duck that wrote it. I didn't just see ONE thing wrong, I saw a
lot of significant things wrong, any one of which taken independently would cause the code
to malfunction in some serious way, and all of which in combination were a complete
disaster. If you are posting sample code, you say so. For example, I might say in a post

CRect r(10,20,30,40); // randomly chosen values for testing

and it is therefore clear that I know that I am choosing random values for testing. But I
regularly get pieces of code that "no longer work on high-resolution displays" that are
littered with absolute values of control sizes; why should I assume in the absence of any
indication of knowledge about how the values are derived that your choice of
implementation was any different than the kind of malfunctioning code I see quite
regularly?
*****
>
>>I didn't make a mistake; I answered a question you asked about why a particular error
>>occurred, and it was obvious from the code why the error occurred. While you may not have
>
>	Ah, you "didn't make a mistake"--so this IS about your
>infallibility (if you are looking for a career change, the pope
>position will be open soon). But this wasn't about my coding error at
>first, this was about me being "clueless" for not using Hungarian
>Notation correctly. As it turns out, I was using Hungarian Notation
>correctly, since my mistake was not in chosing the notation, but in an
>oversight while trying to change a local variable to member.
>	But either way, I can understand why you'd see me as
>"clueless", because the bottom line is: I made a mistake. It's just
>that a fallible person would have understood that this is a likely
>mistake for another fallible person to make when moving a variable
>from local to member.
*****
Actually, the pope is only considered infallible when speaking "ex cathedra", which is in
ruling on matters of faith. 

You're the one who said I made a mistake; yet I merely answered the question you asked,
given the information you gave. If you had some other context in mind, I can't guess that
by some ethereal vibrations; I can only answer questions and make observations based on
what you post. What you posted was erroneous in a huge number of ways. And I said so. I
can't guess that you were thinking of a member variable when you wrote a local variable.
The evidence is all I have to work on. And based solely on the evidence you presented, you
used it grossly incorrectly. Not just a little bit incorrectly. That's "clueless". The
number of times I see real code that looks like yours is frighteningly high. And the
people who write in are convinced they are writing Good Code because they use Hungarian
Notation. Why should I assume that your misuse of it is different from anyone else's
misuse of it? There are errors we all make, but it is worth noting that the incidence of
errors of people MISusing Hungarian Notation is far higher than the incidence of errors of
people who don't use it at all.
>
>>intended to make the variable local (Yes, I saw that, but the comment was irrelevant in
>>the light of the obvious bug), you most certainly did.
>>*****
>>>
>>>>Next, since there is only one button being created, there is no reason to create it at
>>>>runtime. Create it at design time. 
>>>
>>>	Actually, you're still looking at the experimental code. The
>>>release version will probably be initially supporting several dozen
>>>controls, so I'll probably need to learn about scroll bars as well.
>>>
>>>>The use of a CRect with fixed constant bounds is nonsensical. These values might work on
>>>>your installation, with the current display driver, resolution, display, and system font
>>>>selelction, but it will not work anywhere else, so forget, forever, the notion of
>>>>hardwired constants in this context.
>>>
>>>	The code is still just for experimental purposes.
>>******
>>If you post an example that says "I'm doing this way" we have no way to know that you are
>>not REALLY doing it the way you say you are doing it!
>>******
>>>
>>>>If you need to create a button, if there is only one button, create it at design time.
>>>>Period. No reason to create it dynamically. If you need to create buttons dynamically, you
>>>>should create a "prototype" button on the dialog at design time, assign it a control
>>>>variable, mark it as invisible, and use it to get GetWindowRect to get the correct size
>>>>for a button.Then, no matter what combination of video drivers, displays, resolution, and
>>>>fonts you encounter, you will always get a button of the right size. Sometimes I use only
>>>>the height and compute the width on the fly. I usually use a single-space or double-space
>>>>dimension on each side of the text width to compute the desired width.
>>>
>>>	Still experimental code.
>>>
>>>>AHA! I see you made the classic error! You used a HARDWIRED INTEGER VALUE for the button
>>>>ID. If you are creating buttons dynamically, you cannot use hardwired integer values. If
>>>
>>>	Persistently experimental
>>>
>>>>you are using hardwired integer values, you do not need to create them dynamically. And,
>>>>you chose the worst possible integer value, Your button looks like the OK button (IDOK is
>>>>1), so of course your dialog will close, because you ASKED IT TO!
>>>
>>>	But that wasn't supposed to be part of the experiment. Indeed,
>>>it was the resource id of 1 that caused OnOK() to be called.
>>*****
>>If I were doing this, I would not have used a hardwired constant, even in an experiment.
>>And I certainly would not have used 1. Even in an experiment. 
>>*****
>>>
>>>>If you had not overridden the name as a local name--and used the naming conventions
>>>>incorrectly--then you would not have had the memory leak. 
>>>
>>>	Well... if you knew that I had declared the variable as a
>>>member, you must have seen that it was not intended to be overriden
>>>and used as a local.
>>*****
>>But you DID override it in your code example! I quote from your actual posted source code:
>>
>>>BOOL CADialog::OnInitDialog() {
>>>	CDialog::OnInitDialog();
>>>	CButton *m_pButton = new CButton();
>>
>>Now tell me exactly what part of "You'll see that I had no intension of making m_pButton
>>local" that I missed? If you post completely incorrect code and ask "what's wrong with my
>>code", you will get an answer. You complained that m_pButton was NULL, and it is clear
>>that it must at that point be a member variable, then you show a piece of code that
>>guarantees it cannot be initialized, and wonder why it is not initialized,  you get an
>>answer. It is impossible to read your intentions when you clearly show incorrect code.
>>*****
>>>
>>>	But all your other advice was very useful. Thanks
>>>
>>>
>>>----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
>>>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
>>>----= East and West-Coast Server Farms - Total Privacy via Encryption =----
>>
>>Joseph M. Newcomer [MVP]
>>email: newcomer@flounder.com
>>Web: http://www.flounder.com
>>MVP Tips: http://www.flounder.com/mvp_tips.htm
>
>
>----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
>----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
2/27/2005 10:39:11 PM
Is this thread still going on? Geez! Angus, the man obviously knows
Hungary Notation. His only mistake was a trivial one about forgetting
to remove instances of a local variable. Now stop it with that clueless
talk, and take your head out of your ass.
   He's right, you do think you're pope *ahem*ahem*

Joseph M. Newcomer wrote:
> See below...
> On Fri, 25 Feb 2005 14:42:04 -0500, Angus March
<angus@hamgate.concordia.ca> wrote:
>
> >It was a dark and stormy night when Joseph M. Newcomer
> ><newcomer@flounder.com> wrote:
> >
> >>See below...
> >>On Thu, 24 Feb 2005 22:04:37 -0500, Angus March
<angus@hamgate.concordia.ca> wrote:
> >>
> >>>It was a dark and stormy night when Joseph M. Newcomer
> >>><newcomer@flounder.com> wrote:
> >>>
> >>>>If you don't know the number of buttons unitl runtime, how can
you have a destructor that
> >>>>uses only a single variable?
> >>>
> >>>	Well, I can't, but at that stage I was performing experiments
> >>>to see how the code would perform, and was happy to use a single
> >>>variable, rather than risk several man-hours on something that
> >>>wouldn't work.
> >>>
> >>>>
> >>>>You don't need to do a NULL test because delete works on a NULL
pointer.
> >>>>
> >>>>As usual, you are another person who is totally clueless about
Hungarian Notation. If you
> >>>>don't know how to use it, DON'T USE IT!!!!!
> >>>
> >>>	So who says I am using it? Actually, I was going to make the
> >>>same comparison between you and Canadian Notation.
> >>*****
> >>You are. m_ is part of Hungarian Notation. So you ARE using it. No
question whatsoever.
> >>And the name of your variable was m_pButton, and the "p" prefix
also is part of Hungarian
> >>Notation. So there is no question you are using it. You yourself,
by the notation you have
> >>used, has said you are using it. And, by declaring a local name
with m_ in the name, you
> >>are using it incorrectly.
> >>*****
> >
> >	I think I see what you are saying. If it does but one or two
> >things like a duck, (such as breathing oxygen or basing its biology
on
> >carbon) and nothing else like a duck, it's a duck. So... I guess
that
> >implies that when I'm overseas, I'm an American because my accent is
> >the same? With very few subtleties, the accent that all English
> >Canadians (west of New Brunswick) use is indistinguishable from
> >Hollywood-American, so there's no question whatsoever that we are
all
> >Americans.
> >	Boy is that ever going to be embarrassing when I show up at
> >customs as an American with a Canadian passport. But now that I
think
> >about it, all the customs officers I've seen in every country I've
> >visited have been so dim as to assume that I'm probably Canadian
since
> >I'm producing a Canadian passport--the fools.
> *****
> I think there was a lot more here: if you see something that
resembles a duck, has
> feathers, a large orange bill, webbed feet, lays eggs, qucks, swims,
and flies, there is a
> very good chance it is a duck. I saw an example that violated just
about every known rule
> about writing robust code, including misuse of notation, declaring a
local variable that
> overrode a member variable name, using constants, etc., etc., and
therefore I'm reasonably
> safe in assuming it is a duck that wrote it. I didn't just see ONE
thing wrong, I saw a
> lot of significant things wrong, any one of which taken independently
would cause the code
> to malfunction in some serious way, and all of which in combination
were a complete
> disaster. If you are posting sample code, you say so. For example, I
might say in a post
>
> CRect r(10,20,30,40); // randomly chosen values for testing
>
> and it is therefore clear that I know that I am choosing random
values for testing. But I
> regularly get pieces of code that "no longer work on high-resolution
displays" that are
> littered with absolute values of control sizes; why should I assume
in the absence of any
> indication of knowledge about how the values are derived that your
choice of
> implementation was any different than the kind of malfunctioning code
I see quite
> regularly?
> *****
> >
> >>I didn't make a mistake; I answered a question you asked about why
a particular error
> >>occurred, and it was obvious from the code why the error occurred.
While you may not have
> >
> >	Ah, you "didn't make a mistake"--so this IS about your
> >infallibility (if you are looking for a career change, the pope
> >position will be open soon). But this wasn't about my coding error
at
> >first, this was about me being "clueless" for not using Hungarian
> >Notation correctly. As it turns out, I was using Hungarian Notation
> >correctly, since my mistake was not in chosing the notation, but in
an
> >oversight while trying to change a local variable to member.
> >	But either way, I can understand why you'd see me as
> >"clueless", because the bottom line is: I made a mistake. It's just
> >that a fallible person would have understood that this is a likely
> >mistake for another fallible person to make when moving a variable
> >from local to member.
> *****
> Actually, the pope is only considered infallible when speaking "ex
cathedra", which is in
> ruling on matters of faith.
>
> You're the one who said I made a mistake; yet I merely answered the
question you asked,
> given the information you gave. If you had some other context in
mind, I can't guess that
> by some ethereal vibrations; I can only answer questions and make
observations based on
> what you post. What you posted was erroneous in a huge number of
ways. And I said so. I
> can't guess that you were thinking of a member variable when you
wrote a local variable.
> The evidence is all I have to work on. And based solely on the
evidence you presented, you
> used it grossly incorrectly. Not just a little bit incorrectly.
That's "clueless". The
> number of times I see real code that looks like yours is
frighteningly high. And the
> people who write in are convinced they are writing Good Code because
they use Hungarian
> Notation. Why should I assume that your misuse of it is different
from anyone else's
> misuse of it? There are errors we all make, but it is worth noting
that the incidence of
> errors of people MISusing Hungarian Notation is far higher than the
incidence of errors of
> people who don't use it at all.
> >
> >>intended to make the variable local (Yes, I saw that, but the
comment was irrelevant in
> >>the light of the obvious bug), you most certainly did.
> >>*****
> >>>
> >>>>Next, since there is only one button being created, there is no
reason to create it at
> >>>>runtime. Create it at design time.
> >>>
> >>>	Actually, you're still looking at the experimental code. The
> >>>release version will probably be initially supporting several
dozen
> >>>controls, so I'll probably need to learn about scroll bars as
well.
> >>>
> >>>>The use of a CRect with fixed constant bounds is nonsensical.
These values might work on
> >>>>your installation, with the current display driver, resolution,
display, and system font
> >>>>selelction, but it will not work anywhere else, so forget,
forever, the notion of
> >>>>hardwired constants in this context.
> >>>
> >>>	The code is still just for experimental purposes.
> >>******
> >>If you post an example that says "I'm doing this way" we have no
way to know that you are
> >>not REALLY doing it the way you say you are doing it!
> >>******
> >>>
> >>>>If you need to create a button, if there is only one button,
create it at design time.
> >>>>Period. No reason to create it dynamically. If you need to create
buttons dynamically, you
> >>>>should create a "prototype" button on the dialog at design time,
assign it a control
> >>>>variable, mark it as invisible, and use it to get GetWindowRect
to get the correct size
> >>>>for a button.Then, no matter what combination of video drivers,
displays, resolution, and
> >>>>fonts you encounter, you will always get a button of the right
size. Sometimes I use only
> >>>>the height and compute the width on the fly. I usually use a
single-space or double-space
> >>>>dimension on each side of the text width to compute the desired
width.
> >>>
> >>>	Still experimental code.
> >>>
> >>>>AHA! I see you made the classic error! You used a HARDWIRED
INTEGER VALUE for the button
> >>>>ID. If you are creating buttons dynamically, you cannot use
hardwired integer values. If
> >>>
> >>>	Persistently experimental
> >>>
> >>>>you are using hardwired integer values, you do not need to create
them dynamically. And,
> >>>>you chose the worst possible integer value, Your button looks
like the OK button (IDOK is
> >>>>1), so of course your dialog will close, because you ASKED IT TO!
> >>>
> >>>	But that wasn't supposed to be part of the experiment. Indeed,
> >>>it was the resource id of 1 that caused OnOK() to be called.
> >>*****
> >>If I were doing this, I would not have used a hardwired constant,
even in an experiment.
> >>And I certainly would not have used 1. Even in an experiment.
> >>*****
> >>>
> >>>>If you had not overridden the name as a local name--and used the
naming conventions
> >>>>incorrectly--then you would not have had the memory leak.
> >>>
> >>>	Well... if you knew that I had declared the variable as a
> >>>member, you must have seen that it was not intended to be
overriden
> >>>and used as a local.
> >>*****
> >>But you DID override it in your code example! I quote from your
actual posted source code:
> >>
> >>>BOOL CADialog::OnInitDialog() {
> >>>	CDialog::OnInitDialog();
> >>>	CButton *m_pButton = new CButton();
> >>
> >>Now tell me exactly what part of "You'll see that I had no
intension of making m_pButton
> >>local" that I missed? If you post completely incorrect code and ask
"what's wrong with my
> >>code", you will get an answer. You complained that m_pButton was
NULL, and it is clear
> >>that it must at that point be a member variable, then you show a
piece of code that
> >>guarantees it cannot be initialized, and wonder why it is not
initialized,  you get an
> >>answer. It is impossible to read your intentions when you clearly
show incorrect code.
> >>*****
> >>>
> >>>	But all your other advice was very useful. Thanks
> >>>
> >>>
> >>>----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure
Usenet News==----
> >>>http://www.newsfeeds.com The #1 Newsgroup Service in the World!
120,000+ Newsgroups
> >>>----= East and West-Coast Server Farms - Total Privacy via
Encryption =----
> >>
> >>Joseph M. Newcomer [MVP]
> >>email: newcomer@flounder.com
> >>Web: http://www.flounder.com
> >>MVP Tips: http://www.flounder.com/mvp_tips.htm
> >
> >
> >----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
> >http://www.newsfeeds.com The #1 Newsgroup Service in the World!
120,000+ Newsgroups
> >----= East and West-Coast Server Farms - Total Privacy via
Encryption =----
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm

0
mt97835 (1)
2/28/2005 5:08:30 PM
Reply:

Similar Artilces:

run an excel file remotely
Hi all i got an excel application that generates reports from underlying pivot tables. the reports are generated using excel 2003. but most of the clients donot have licenses for 2003 and some of the features of 2003 cannot be used when the file is opened from the client system. for example GETPIVOTDATA is not very flexible as it was in 2003 version. So is it possible to run the excel application from the server without being copied to the client system. This also helps in maintaing single version of the excel file rather than multiple versions on each client system. Thanks in adva...

Outlook Today ????? Sort out of control ?????
On the Outlook Today screen, my tasks are sorted solely by due date. Completed taks used to drop to the bottom of that day's group and push the uncompleted tasks to the top. Suddenly, most completed tasks are rising to the top of the list, pushing uncompleted tasks off my screen and out of view. And some completed taks don't move at all, remaining intermingled with the uncompleted tasks. What happened? How do I fix this? I would first check to see if the sorting for Task in Outlook Today was somehow changed. This is listed under Customize Outlook Today and there is a sec...

create a roster
How can you create a weekly roster in which functions can be assigned to more than 10 people. The roster should be updatable, so that when holidays and days off are marked on the weekly roster they will be taken account of it future rosters. ...

verify that a dialog box exists
I want to verify that a dialog box exists before I send it some message. I have a pointer to its object. Can someone remind me please? Thanks George > I want to verify that a dialog box exists before I send it some message. I > have a pointer to its object. > Can someone remind me please? > if(pDlg && pDlg->m_hWnd) { .... } --- Ajay > I want to verify that a dialog box exists before I send it some message. I > have a pointer to its object. > Can someone remind me please? > You can use ASSERT_VALID as well. It works in Debug only but its of great...

User prompted for password 5 times
One of my users is experiencing a very odd (at least to me) behavior. He is logged into his XP system which is joined to our Active Directory, no problems there. When he launches Outlook hs is prompted for his password for some reason. He has to enter his password and click OK, then repeat this step 5 times before it lets him in. Any thoughts? Thanks I'm having a similar problem. Also running XP and Outlook 2003. Did you get any answers? I haven't tried to authenticate 5 times but that should not be the answer! Right? >-----Original Message----- >One of my users is ex...

importing or creating reference footnotes
I am trying to import a word document into publisher and it has reference footnotes within the document. The reference footnotes are not coming into the publisher document with the reference footnotes. Correct, they will not up to Publisher 2003. In Publisher 2003 depending on which version of Word you are using if they will or not. -- "If you don't know where you are going, any road will take you there!" ...

Mailbox not created when AD account created
A couple of days ago I noticed that I created a user account but the 'Email Addresses' tab of the user properies did not list any email addresses. Subsequent new user accounts have all experienced the same. I researched the knowledge and tried the recommended solutions to either manaully start the recipient update service or rebuild te recipient update service. Neither recommendation has resulted in a mailbox being created for this particular user or any additional user that I have created since this error first showed up. I performed a Windows update last Thursday and so I bel...

Task Create - Status
I'm trying to make a simple task, when a user owner is assigned a task in CRM, it receives an email letting it know it has one. I have the following below, but it is not generating one when i assign one manually in the CRM. What to do? I've tried both the following: When task is created E-Mail to:[owner];Subject test As well as: When task is created if Task activity status = Open then E-Mail to:[owner];Subject test I've checked the mailserver many times over, and I can send emails manually from the CRM so you can rule that out Tested out ok on our end. Some ideas:...

Scrollable Dialog with the toolbar
Hi Folks , Someone please tell me how to create a scrollable dialog with a Toolbar. I have a CFormview and inside that I have placed a CTabctrl . I need the toolbar for the tabs and each tab should be scrollable I could create something similar but the scrollbr scrolls the toolbar too !! I want it to be fixed and the remainning part of the dialog should be allowed to scroll. Regards, JLD <ggurubasavaraja@gmail.com> wrote in message news:1191585195.063726.41740@k79g2000hse.googlegroups.com... > Hi Folks , > > Someone please tell me how to create a scrollable dialog with ...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

Controlling display of forms
Hi, I'm trying to control what parts of a form are visible or not depending on the user of the computer. I've managed to find and adapt some code to tell me who the user is and I have a table set up with user names and a permission level (1 or 0) I can manually alter the On_Load event of my form to hide the parts I want (tabs) Can anybody help me out with putting it all together so that the forms On_Load event looks at GetUserName function which looks at the UserPermissions table and sets Visible True or False accordingly. This is taking me so long and it looks like it ought ...

Create external database
Hi all. I need to create an external database (file). On a site I found this code: ------------------------------------------------------ Function CreateLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String) As String 'strTargetDB = Source Database Name 'strProviderString = Not used, currently hard coded 'strSourceTbl = Source Table name in the database we are linking too. 'strLinkTblName = Table name we would like to see in the Access Database. Dim catDB As ADOX.Catalog Dim tblLink As...

How to create pie chart with %
I have got a problem that I don't if excel could help me to calculate the % within a column and draw a pie chart. My case is I have a column containing a series of numbers. e.g. 1,4,8,1,3,9,11,2,4,5,6,.........etc I want to draw a pie chart that showing 1-3 , 4-6, 7-9, >9 with the corresponding % inside that column. Can anyone tell me how can I make it ? Ray - You need to calculate the frequencies in your data. Let's assume your data is in A1:A12. In B1:B3 enter these numbers, the upper limits on the groupings: 3 6 9 You can enter ">9" into B4 witho...

Run-time error 438?
Hello, I am trying to create an edit control for my form. I lock my textboxes in properties and then I created a command button with an event on onclick. My codes are working for most of them expect a few. When I click the button it gives me Run-time error 438. My code is based liked this. Me![Control].Locked=False Private Sub Edit_Record_Click() Me![Drago ID].Locked = False Me![Drago Claim Number].Locked = False Me![Dealer Claim Number].Locked = False Me![Dealer].Locked = False Me![Store].Locked = False Me![Machine Acres].Locked = False Me![Part Fail Date].Locked = False - NOT WORKING ...

Email address not created when a new user is created
All, This issue recently happened in my company. Upon creating a new user, the policy was set to create the smtp and X400 address automaticaly. Now when we create a user the smtp and x400 addresses are not created, and when attempting to setup the new user in outlook, the address cant be found. We are using exchange 2003 SP1 on Win2k3 servers. On Wed, 13 Jul 2005 06:49:07 -0700, "Bryan" <Bryan@discussions.microsoft.com> wrote: >All, >This issue recently happened in my company. Upon creating a new user, the >policy was set to create the smtp and X400 addres...

Exchange 2010 MRM, no log files being created
I'm hoping someone can help me with this issue....it has been driving me crazy for days. I have enabled MRM logging on our exchange server, and I can see that some of the policies are working when I run start-managedfolderassistant. We have a retention policy tag on the deleteditems folder, and this does work. The problem is I am not getting any files in the MRM log directory. C:\Program Files\Microsoft\Exchange Server\V14\Logging\Managed Folder Assistant Events 9021 and 9022 are logged in the Application log, but where are the files? Below is the output of my mai...

when form created
I have a form which was created by someone else (not a form template) which is like a questionnaire with empty boxes to be completed. When the boxes are typed in all the margins move to accommodate the words being typed. Is there a way to fix/lock the original form and then just fill in the blank boxes? I suspect this is set up as a table with auto resizing enabled. Displaying table gridlines (Table | Show Gridlines) will help you see what you're dealing with. Then select the table, go to the Table tab of Table Properties, click Options, and clear the check box for "A...

UnBound Control
i have an UnBound Control in a ContinousForm is there a way to make this control enabled in a certain record and be disabled in alll other records i mean i wan to customize this control from a record to another ...

Creating a Brochure
How do you create a 3-column brochure from scratch for Publisher 2002? I can only find the directions for the 2003 version. Quick help would be appreciated, project is due Monday. Create a three-panel or four-panel folded publication http://office.microsoft.com/en-us/assistance/HP011646681033.aspx Scroll down to the section that says "Build a three-panel or four-panel publications from scratch." -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Derek" <Derek@discussions.microsoft.com> wrote in message news...

How to create Access macro shortcut
I'm still using Access 97 and saw something the other day that I would like to use that was in Access 2000. In an Access 2000 database, there was a .mam file in a directory that launched the Access 2000 program and ran a macro. How do you set this up? Can it be done in Access 97? If so, how? Hi. > How do you set this up? Select the macro in the Database Window and right click with your mouse, then select "Create Shortcut..." in the pop-up menu. Follow the prompts for where to place the shortcut and what to name it. The default is: <PathToDeskTopDir>\Shortcut ...

send & receives runs continuously
One of our network PC's picked up a trojan which the user deleted without noticng the name. However, since then, Outlook continuously runs send & receive but fails to send or receive email. Thinking that it may be an Outlook only problem, I setup an Outlook Express email account and it also fails to send and receive mail. We have seven PC's sending and receiving email through the same POP server so I know the server is working. Not sure if this is an Outlook problem or soemting else!!?? Thanks RichC On Thu, 23 Mar 2006 13:30:28 -0500, "Rich Crawford" <dro...

Users mailboxes not created when user created
I have a problem that recently just started happening on my exchange 2003 server. When i create a new user account and create the mailbox for exchange, once im done, the mailbox isnt created, adn if you go into the properties of the user account adn go to the exchange email address tab, there isnt an smtp or an x.400 address listed. I am having to manually create and add these, adn then go delete the exchange mailbox and recreate it. This is really annoying and would love to know if anyone has any ideas of how to fix it. Thanks Jason In news:9F836A43-98BF-435A-AA43-AFF10124BE3F@micro...

CRM should let me create custom fields in batch
Hi, With MS CRM v3.0, when we have a group of fields to create, it would be faster to be able to enter the list and then submit the list for processing. Thank you. Felix. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/C...

Creating an ad book
How do I divide a page into equal sections (halves, qarters, eights)? I need to scan and type ads and coupons into this booklet. New at this. After managing to set up OE-QuoteFix on his new PC, Ed reads a message from FRSH <anonymous@discussions.microsoft.com>... > How do I divide a page into equal sections (halves, qarters, eights)? Arrange > Layout Guides > Grid Guides -- Ed Bennett - MVP Microsoft Publisher http://www.mvps.org/the_nerd/ Before reading this message, view the disclaimer: http://mvps.org/the_nerd/disclaim.htm ...

Access unable to create an MDE
I am getting this message when I try to make an MDE: "Access unable to create an MDE database" No error mesages or any other info is displayed. I haven't had this trouble before. Then I added a form, a couple reports, an create table query, modified a toolbar and added a module. Now I am getting this message. This database is a front end of a project with several linked table to a back end. Any suggestions? Thanks Jeff G Try compiling your application (under the Debug menu when you're in the VB Editor). Often an application will have some error that doesn't m...