Controls on SDI apps.

I've got a situation where I need to add dialog style controls (mostly
buttons) on an sdi application.  I physically know HOW to do it, but I'm
curious about technique.

For now, I instantiate a CButton object, followed by a Create() and a
ShowWindow(SW_SHOW).  Works just fine and dandy.  However, I'm suspicious my
implementation is somewhat, shall we say, a little belt and suspenders?

Let me explain.

I did a quick test  SDI app.  In the view header, I declared  a CButton and
a 'bool' called bSetControls.

I added a member function called SetControls().  IN the View constructor, I
set bSetControls to false.  Then, in the ondraw handler, I put:

if(!bSetControls){
    SetControls();
    bSetControls = true;
}

In the SetControls member function, I basically have:

void [view]::SetControls()
{
    RECT rect;
    myButton.Create([args]);
    myButton.ShowWindow(SW_SHOW);
}

Something tells me that this is an inelegant way to do this.  Any advice or
tips?

Paul



0
9/8/2003 6:32:09 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
628 Views

Similar Articles

[PageSpeed] 16

Typically you would create the controls in OnInitialUpdate for your view. It
can get called multiple times though. In addition, you may want to look at
CFormView which allows you to use a dialog template in a view.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Pablo" <jnaut_nospam@earthlink.net> wrote in message
news:vlpipvl5lv1720@corp.supernews.com...
>
> I've got a situation where I need to add dialog style controls (mostly
> buttons) on an sdi application.  I physically know HOW to do it, but I'm
> curious about technique.
>
> For now, I instantiate a CButton object, followed by a Create() and a
> ShowWindow(SW_SHOW).  Works just fine and dandy.  However, I'm suspicious
my
> implementation is somewhat, shall we say, a little belt and suspenders?
>
> Let me explain.
>
> I did a quick test  SDI app.  In the view header, I declared  a CButton
and
> a 'bool' called bSetControls.
>
> I added a member function called SetControls().  IN the View constructor,
I
> set bSetControls to false.  Then, in the ondraw handler, I put:
>
> if(!bSetControls){
>     SetControls();
>     bSetControls = true;
> }
>
> In the SetControls member function, I basically have:
>
> void [view]::SetControls()
> {
>     RECT rect;
>     myButton.Create([args]);
>     myButton.ShowWindow(SW_SHOW);
> }
>
> Something tells me that this is an inelegant way to do this.  Any advice
or
> tips?
>
> Paul
>
>
>


0
ajaykalra (6842)
9/8/2003 6:52:26 PM
If you're going to make your own controls, use OnInitDialog (as already
mentioned).

I prefer to use the dialog editor when possible.  When you create a New MFC
Application, on the last step -- change your View's base class to CFormView.
That's VS 6.0.   The .Net version may be a different.

-Kanon


"Pablo" <jnaut_nospam@earthlink.net> wrote in message
news:vlpipvl5lv1720@corp.supernews.com...
>
> I've got a situation where I need to add dialog style controls (mostly
> buttons) on an sdi application.  I physically know HOW to do it, but I'm
> curious about technique.
>
> For now, I instantiate a CButton object, followed by a Create() and a
> ShowWindow(SW_SHOW).  Works just fine and dandy.  However, I'm suspicious
my
> implementation is somewhat, shall we say, a little belt and suspenders?
>
> Let me explain.
>
> I did a quick test  SDI app.  In the view header, I declared  a CButton
and
> a 'bool' called bSetControls.
>
> I added a member function called SetControls().  IN the View constructor,
I
> set bSetControls to false.  Then, in the ondraw handler, I put:
>
> if(!bSetControls){
>     SetControls();
>     bSetControls = true;
> }
>
> In the SetControls member function, I basically have:
>
> void [view]::SetControls()
> {
>     RECT rect;
>     myButton.Create([args]);
>     myButton.ShowWindow(SW_SHOW);
> }
>
> Something tells me that this is an inelegant way to do this.  Any advice
or
> tips?
>
> Paul
>
>
>


0
Kanonw (36)
9/8/2003 7:27:43 PM
Thanks for the reply.  Actually, I like Ajay's answer better.  There is no
'oninitdialog()' in an SDI app.  I fully understand how to do stuff when the
app is based on a CDialog, but that's not my case.  However, we are
discussing the FormView based application, I just haven't decided whether I
really need a cformview yet.  There may be a combination of more free form
painting (like an SDI app) and a mix of physical controls such as buttons
and list/tree controls.  All that's up in the air.

Thanks for your help.

Paul


Kanon Wood <Kanonw@yahoo.com> wrote in message
news:uYlZ91jdDHA.1128@tk2msftngp13.phx.gbl...
> If you're going to make your own controls, use OnInitDialog (as already
> mentioned).
>
> I prefer to use the dialog editor when possible.  When you create a New
MFC
> Application, on the last step -- change your View's base class to
CFormView.
> That's VS 6.0.   The .Net version may be a different.
>
> -Kanon
>
>
> "Pablo" <jnaut_nospam@earthlink.net> wrote in message
> news:vlpipvl5lv1720@corp.supernews.com...
> >
> > I've got a situation where I need to add dialog style controls (mostly
> > buttons) on an sdi application.  I physically know HOW to do it, but I'm
> > curious about technique.
> >
> > For now, I instantiate a CButton object, followed by a Create() and a
> > ShowWindow(SW_SHOW).  Works just fine and dandy.  However, I'm
suspicious
> my
> > implementation is somewhat, shall we say, a little belt and suspenders?
> >
> > Let me explain.
> >
> > I did a quick test  SDI app.  In the view header, I declared  a CButton
> and
> > a 'bool' called bSetControls.
> >
> > I added a member function called SetControls().  IN the View
constructor,
> I
> > set bSetControls to false.  Then, in the ondraw handler, I put:
> >
> > if(!bSetControls){
> >     SetControls();
> >     bSetControls = true;
> > }
> >
> > In the SetControls member function, I basically have:
> >
> > void [view]::SetControls()
> > {
> >     RECT rect;
> >     myButton.Create([args]);
> >     myButton.ShowWindow(SW_SHOW);
> > }
> >
> > Something tells me that this is an inelegant way to do this.  Any advice
> or
> > tips?
> >
> > Paul
> >
> >
> >
>
>


0
9/8/2003 8:03:31 PM
Pablo wrote:
> 
> Thanks for the reply.  Actually, I like Ajay's answer better.  There is no
> 'oninitdialog()' in an SDI app.  

Check his answer again.  A view function has OnInitialUpdate(), which
Ajay suggested.  This is where you should be doing initialization.  It
is quite inelegant to be creating controls in OnDraw().

--
Scott McPhillips [VC++ MVP]
0
scottmcp (342)
9/9/2003 2:28:26 AM
Yes, I know, which is what I'll be using.  The second poster, Kanon
suggested OnInitDialog()-- I was simply pointing out that OnInitDialog() was
not a view member.  However, Ajay noted that OnInitialUpdate() could be
called several times by the framework.  In my tests, I have only found it
executed once upon startup of the application.  Are there circumstances
where this member would be called again by the framework?

Paul

"Scott McPhillips" <scottmcp@mvps.org> wrote in message
news:3F5D3ACA.10E4CC20@mvps.org...
> Pablo wrote:
> >
> > Thanks for the reply.  Actually, I like Ajay's answer better.  There is
no
> > 'oninitdialog()' in an SDI app.
>
> Check his answer again.  A view function has OnInitialUpdate(), which
> Ajay suggested.  This is where you should be doing initialization.  It
> is quite inelegant to be creating controls in OnDraw().
>
> --
> Scott McPhillips [VC++ MVP]


0
9/9/2003 3:55:54 AM
Pablo,

OnInitDialog can be called multiple times - but would not necessarily be
called multiple times.

In an SDI app, the OnInitDialog method of the View class is called
indirectly through the CSingleDocTemplate::InitialUpdateFrame using the
private MFC message WM_INITIALUPDATE.

The InitialUpdateFrame is called EVERY time the File|New or File|Open
sequence executed - and that is why you see it called once - through the
frameworks implicit File|New processing in the call to
ProcessShellCommand in your CWinApp derived InitInstance method.

If you have taken care of the File|New and File|Open handlers for your
CWinApp derived class, then you have nothing to worry about.

regards
roy fine


"Pablo" <jnaut_nospam@earthlink.net> wrote in message
news:ebc7b.4153$PE6.1682@newsread3.news.pas.earthlink.net...
> Yes, I know, which is what I'll be using.  The second poster, Kanon
> suggested OnInitDialog()-- I was simply pointing out that
OnInitDialog() was
> not a view member.  However, Ajay noted that OnInitialUpdate() could
be
> called several times by the framework.  In my tests, I have only found
it
> executed once upon startup of the application.  Are there
circumstances
> where this member would be called again by the framework?
>
> Paul
>
> "Scott McPhillips" <scottmcp@mvps.org> wrote in message
> news:3F5D3ACA.10E4CC20@mvps.org...
> > Pablo wrote:
> > >
> > > Thanks for the reply.  Actually, I like Ajay's answer better.
There is
> no
> > > 'oninitdialog()' in an SDI app.
> >
> > Check his answer again.  A view function has OnInitialUpdate(),
which
> > Ajay suggested.  This is where you should be doing initialization.
It
> > is quite inelegant to be creating controls in OnDraw().
> >
> > --
> > Scott McPhillips [VC++ MVP]
>
>


0
rlfine5330 (47)
9/9/2003 4:47:04 AM
Reply:

Similar Artilces:

Creating an app that runs as admin
Im attempting to rewrite a vb6 app to be more compatible with current data and runtime folder assignments and access rights. Im puting runtime files in the programfiles folder and data files in an appdata folder. When I run the program after install...I get errors until I manually set the program rights to "run as administrator". Id like to set these rights on install. I tried a manifest file without success. Can someone point me to a tutorial or writeup on how to create an application with admin privledges. Maybe there is no easy answer to this...so maybe I sho...

Can I control what the recipient sees in a distribution list email
I'll need to restate the question, since I'm unsure of the terminology - actually it's a two-part question. Here goes. Part 1) Say I have one hundred people in a distribution list, that I want to send a boiler-plate email to. For confidentiality purposes, I don't want one person knowing who the other persons are. Can I set the email transmission to show (at the recipient's end) only the recipients email address and name (and noone else's). Part 2) if the answer is yes, then can I customize each email to show the person's name (in the same fashion as I ...

How to Set/Change Transparency to CEdit control?
Hi, How to set/change Transparency to Custom Edit control. Can I use SetLayeredWindowAttributes() to set alpha factor for CEdit control? Can I use WS_EX_LAYERED style to child (CEdit) controls? Or should I use GDI+ library feature (Gdiplus::SolidBrush(Gdiplus::Color()). At present both ways are not working for me. Since the edit control is drawn with GDI, invoking a GDI+ mechanism is not going to be terribly successful. While you might consider subclassing the edit control and returning a NULL_BRUSH, this will not produce satisfactory results because edit controls are drawn with SetBkMode(OP...

Viewing Control Characters
Hi, I want to view and edit control characters such as <tab> and <LF> in text files that I import into Excel 2007 on a Windows XP laptop. I'm not able to view or edit them even though I can verify their presence using LEN and CODE functions. It works on Excel 2007 on an XP desktop at work. The control characters show up as boxes or boxes around symbols. Is there a setup option on XP, Office, or Excel that I need to select? Thanks, Paul Try the Terminal font. For example: =CHAR(1) should display a smilelyface. -- Gary''s Student - gsnu201001 ...

how do I control how embedded objects are updated
I have an Excel file that I have embedded into my WORD 2007 doc. I have only pasted a portion of the Excel file, since it is large, but users can open the doc to see the whole file, since it is embedded. However, if they double click the object, and do any scrolling, the object changes. I want the default to be Open, not Edit when the object is double clicked. How do I do that? You can protect the embedded sheet (or workbook) with a password, so that it cannot be edited. -- Stefan Blom Microsoft Word MVP "tsoesh" <tsoesh@discussions.microsoft.com>...

Error when Opening Control Panel
I'm working on an XP Home system, which in general, works fine. The requested work is done, but there's one leftover error I can't quite track down. When opening Control Panel (or when Explorer is pointing to a DVD drive and the disc is removed, or switching between category or Classic view), the search icon appears, and then a small error window appears that has to be cleared to proceed. The window title reads "Registry Error", and the text is "The system cannot find the file specified". On Clicking OK, the window closes and Control Pan...

SetWindowPos in tabbed control
Hi all, I am trying to include a tab control in my dialog based application. Here is what i am doing BOOL Cgui::OnInitDialog() { dlg1.Create (Cdialog1::IDD,this);//dlg1 is the object of the dialog box which i need as first tab dlg2.Create (Cdialog2::IDD,this););//dlg2 is the object of the dialog box which i need as second tab m_wndtab.InsertItem(TCIF_TEXT, 0,"Results", 0,0,0,0); m_wndtab.InsertItem(TCIF_TEXT, 1,"My Task", 0,0,0,0); Up...

Displaying text on a controls
Hi, I want to display a text on a button control and static control from a my program. I tried doing SetButtonText() API , but it is not displaying it on a button control. Is their any API's to display a text on a" Button" and "Static" controls. Hi, Use SetWindowText(if the parent is a window) or SetDlgItemText(if the parent is dialog). Thanx, Ch.T.Gopi Kumar. "lucky" wrote: > Hi, > > I want to display a text on a button control and static control from a > my program. > I tried doing SetButtonText() API , but it is not displaying it o...

Re: Launching Internet Explorer from my MFC App
Hi All Would anyone out there know how to launch Internet Explorer with a specific URL from an MFC App. I would like to have a menu item that when selected launches Internet Explorer. Thanks in advance Hi, You can use ShellExecute(Ex) passing the url as the file, this will automatically start the associated application which is in the case of a url would be your default browser. ShellExecute(handle, NULL, "http://www.google.com", NULL, NULL, SW_SHOWNORMAL); Hope this helps Chris Taylor "LarryM" <larryman.nospam@bigpond.net.au> wrote in message news:XDKcb.12...

Date Time Control
Hi, I'm using Date Time Pickers in my VC6 Application. In the resource editor, for the controls, I am using the "Show None" style which places a check box within the control. I would like all of the controls to default to unchecked. I have derived a class from CDateTimeCtrl called CMyDateCtrl. My Date Time Picker Ctrl m_dt is of type CMyDateCtrl. In the constructor I have CMyDateCtrl::CMyDateCtrl() { SYSTEMTIME SysTime; DateTime_SetSystemtime(this->m_hWnd, GDT_NONE, &SysTime ); } However, this doesn't uncheck the control. This code does work if the dialog box is...

Tree Control Problem
Hi, I am trying to show some icons in tree control with the following code, but it does not seem to work, can anyone help me with this piece of code. hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_INDEX_YES)); ImageList.Add(hIcon); SendDlgItemMessage(IDC_TREC_DIRECTORIES, TVM_SETIMAGELIST, 0, (LPARAM)ImageList.m_hImageList); //this->SetIcon(hIcon, TRUE); tvinsert.hParent=Parent; tvinsert.hInsertAfter=TVI_ROOT; tvinsert.item.mask=TVIF_IMAGE | TVIF_TEXT ; tvinsert.item.iImage = 0; tvinsert.item.iSelectedImage = 0; ...

Control Arrays #2
I have a project where I want to use some customized controls. I will have to create a number of them, the number depends on the number of results that a function returns. How can I do this without crashing the prog? What's the best/most effiecient way to create an array of controls? Can CObArray be used for this? TIA b If you are getting the program to crash and arnt creating hundreds of them, then there is something wrong with your code elsewhere. If the number is so great that you are eating resource handles, consider using a virtual control approach -- - Mark Randall http...

Tab control grows spontaneously
Hope this is the appropriate newsgroup. If not, please advise (.. and it may be a Windows or video adapter problem) Client pointed out a problem that has existed with several forms for several years, but never bothered to inform me. Only a recent on-site visit revealed the problem. Application is developed in A97, and only recently updated to A2003 (problem exists in both versions). The problem is not present on my primary development machine (notebook) or checking machine (CRT display). It *is* present on two of the customer's desktop computers (LCD panel), but not on another desktop co...

Creating Server Controls
Okay, I'm stuck. I have a stack of ASP.NET books, the Internet, and a bunch of time I've spent. I've tried dozens of code samples, all of which either didn't have any effect or wouldn't compile. Can someone please let me know the secret cantation. I'm creating a server control and I want to improve the editor functionality. For example, if I have a URL property, I'd like to use the same editor that is used to edit URLs in the standard server controls (the ones that come with VS). Surely, there must be some straight forward syntax for this, and pe...

Change multple controls based on option change
I have a situation where I need to display 10 to 20 questions with three response fields (approx 6 different forms). I'd like to create a single form and populate it with the 'maximum question count' worth of controls. Then use an option button to select which questions get loaded and load the controls with the appropriate values. This way I only have one set of 'question controls' to deal with and can create a function to call with the information to populate. My big question is -- what is the best way to iterate through the 'question controls' rather then...

how to use common control like cedit,ctoolbar ... in mfc activex?
how to use common control like cedit,ctoolbar ... in mfc activex? ...

checkbox control greyed out on some records
I have a table with a series of checkboxes. In datasheet view, some of the checkboxes are greyed out....can anyone tell me why? If you check you will find they have a Null value. I imagine the field was added after those records were added or those records were appended as Null. -- Build a little, test a little. "Marge" wrote: > I have a table with a series of checkboxes. In datasheet view, some of the > checkboxes are greyed out....can anyone tell me why? ...

Combo Boxes and Controls
I have an application that has 6 combo boxes in a groupbox. When one combo box is selected and it's text properties are displayed, I want to be able to reset the other combo boxes text property. How can this be achieved?? On 1/30/2010 7:58 AM, syslock wrote: > I have an application that has 6 combo boxes in a groupbox. When one > combo box is selected and it's text properties are displayed, I want to > be able to reset the other combo boxes text property. How can this be > achieved?? The fact that they are all in one group box, to the best of my knowledge,...

How to learn Teleric controls
Dear Friends, I have to use teleric controls in my asp.net pages. I dont know how to start it? What I have to use any dll for it? If yes where Can I find it necessary requirements to work with teleric controls? Thanks & Regards Vinod Kumar Hi! Just go to www.telerik.com and download the trial version. The site is also loaded with examples. Hth, Martin "Deep" <vinodkus@gmail.com> wrote in message news:e14d57af-72a9-4ac1-8919-44073ea9d65b@q16g2000prf.googlegroups.com... > Dear Friends, > > I have to use teleric controls in my as...

Set Height Property of image control
I've tried to set the image height of an image control in the OnOpen code: Me.ctlImage.Height = 1.193 * Me.ctlImage.Width such that it will conform to the aspect ratio of images to be displayed. The assignment statement didn't have any affect. With a debug stop after the statement, neither the height or width show any value. What do I need to do here to set the Height property of the image control? Thanks, Bill I see I need to do two things. One is that the width needs to be obtained with the ImageWidth property. And two, that I need to deal with these quantities being in twi...

S/MIME Control
Hi All, After I installed the OWA (Exchange 2003) S/MIME Control, sending attachments with total size more than 1 MB will fail. Not sure have anyone come across this problem? Thanks, Alex S/MIME control does not have size limitations. Try removing the ActiveX, testing, reinstall it again and test. Can you replicate the problem? Can you replicate it on another computer? Any other users having a similar issue? -- Bharat Suneja MCSE, MCT -------------------------------- "Alex" <Yukon@nospam.nospam> wrote in message news:OVFSOwExFHA.1028@TK2MSFTNGP12.phx.gbl... > Hi...

Date controlled formula
Hello I would like some help on a excel formula. I have a worksheet with dates in one row and figures in other and want the totals to be shown @ another area. Example Date 01/02/2004 02/02/2004 03/02/2004 04/02/2004 05/02/2004 Amount 10 20 30 40 50 If I Input date here >>> 02/02/2004 Auto amount selected by formula in this cell = 20 & if I change the date to 03/02/2004 the amount would come up as 30 Any help would be appreciated. Thank you Zarir silverambler@rogers.com Hi Zarir, =HLOOKUP(A5,A1:E2,2,FALSE) -- Kind Regards, Niek Ot...

Control Source Property
Hi Group, I'm using the control source property in VBA to link a form text box to a worksheet cell. Although this works I have found that the worksheet cell is overwritten by the form textbox (even if not updated within the form, I set the locked property to true) when the form closes. The problem being that the worksheet cell data is a lookup formula and not just plain text! So each time it closes I lose my formula! Can someone point me in the right direction please. Thanks in anticipation DonH If you want to retrieve the value from the cell for use in the userform, then use co...

WPF Style and control access via code
Hi all! I've a problem/curiosity about WPF... I'd like to define a common style for all the windows of my application. The style should define: - background of the Window - a logo on the top-left corner - a toolbar with all the common functions for all Windows I've already defined the style in a Resource Dictionary, linked in the XAML code with Style="{StaticResource WindowStyle}". The question is: can I access the controls defined in the style directly from C# code? Actually, I'd like to add some buttons to the toolbar if the active Window allow...

Control Field Validation
I am trying to put some VB code in as a form of validation on an Access form. What I am looking for is essentially the ability to check 5 different controls for data contained within. The controls are for dates that are tied to a table that records the training completion dates. In an effort to avoid out-of-sequence training or edits to the data after the initial entry, I am wanting to put in this code. It essentially enables the field for putting in data but disables subsequent fields to maintain the training sequence. This is what I have so far (and it is *long* down below). At ...