How do you display a dialog on startup?

If you want to display a modal (or modeless) dialog when your MFC application 
first starts up, where do you put it?  (This would be a login or an 
informational dialog that appears on top of the main window.)

I tried putting it in the OnInitialUpdate() method in my CView-derived 
class, but I get asserts.


Thanks.
0
EdwardW1 (9)
3/2/2005 1:25:02 AM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
1103 Views

Similar Articles

[PageSpeed] 23

In InitInstance of your app(or OnCreate of your mainwindow), you could post
a custom message to your mainframe. In its handler, show the dialog.

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


"Edward W" <EdwardW@discussions.microsoft.com> wrote in message
news:79D08A83-1AFE-47F5-A6EC-63C9D9334130@microsoft.com...
> If you want to display a modal (or modeless) dialog when your MFC
application
> first starts up, where do you put it?  (This would be a login or an
> informational dialog that appears on top of the main window.)
>
> I tried putting it in the OnInitialUpdate() method in my CView-derived
> class, but I get asserts.
>
>
> Thanks.


0
ajaykalra (6842)
3/2/2005 1:35:53 AM
"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:eoIeVesHFHA.3208@TK2MSFTNGP10.phx.gbl...
>
> In InitInstance of your app(or OnCreate of your mainwindow), you could
post
> a custom message to your mainframe. In its handler, show the dialog.

Or, if you've already got a toolbar button or menu entry or whatever for
your login command that opens the login dialog just post the command
message, no need for a custom message:

CMyApp::GetApp().GetMainWnd()->PostMessage( WM_COMMAND, ID_LOGIN, 0 );

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
3/2/2005 9:47:19 AM

"Tim Ward" wrote:

> "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
> news:eoIeVesHFHA.3208@TK2MSFTNGP10.phx.gbl...
> >
> > In InitInstance of your app(or OnCreate of your mainwindow), you could post
> > a custom message to your mainframe. In its handler, show the dialog.
> 
> Or, if you've already got a toolbar button or menu entry or whatever for
> your login command that opens the login dialog just post the command
> message, no need for a custom message:
> 
> CMyApp::GetApp().GetMainWnd()->PostMessage( WM_COMMAND, ID_LOGIN, 0 );
> 
> --
> Tim Ward
> Brett Ward Limited - www.brettward.co.uk
> 
> 

Thanks.  Those hints are helpful.

Is it possible to post a message to the App class so one of its message 
handlers is called?  The App class isn't a CWnd-derived class, so I don't see 
how you can post a message to it.


Edwad Wang

0
EdwardW1 (9)
3/2/2005 9:35:14 PM
You can post a message to the app class as well. Since it is derived
from CWinThread, it can respond to PostThreadMessage. I have had no
problems using it, although others have raised issues with it.

---------
Ajay Kalra
ajaykalra@yahoo.com

Edward W wrote:
> "Tim Ward" wrote:
>
> > "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
> > news:eoIeVesHFHA.3208@TK2MSFTNGP10.phx.gbl...
> > >
> > > In InitInstance of your app(or OnCreate of your mainwindow), you
could post
> > > a custom message to your mainframe. In its handler, show the
dialog.
> >
> > Or, if you've already got a toolbar button or menu entry or
whatever for
> > your login command that opens the login dialog just post the
command
> > message, no need for a custom message:
> >
> > CMyApp::GetApp().GetMainWnd()->PostMessage( WM_COMMAND, ID_LOGIN, 0
);
> >
> > --
> > Tim Ward
> > Brett Ward Limited - www.brettward.co.uk
> >
> >
>
> Thanks.  Those hints are helpful.
>
> Is it possible to post a message to the App class so one of its
message
> handlers is called?  The App class isn't a CWnd-derived class, so I
don't see 
> how you can post a message to it.
> 
> 
> Edwad Wang

0
ajaykalra (6842)
3/2/2005 10:05:41 PM
Edward W wrote:
> 
> Thanks.  Those hints are helpful.
> 
> Is it possible to post a message to the App class so one of its message 
> handlers is called?  The App class isn't a CWnd-derived class, so I don't see 
> how you can post a message to it.
> 
> 
> Edwad Wang

If you post the WM_COMMAND message to the main window the app class can 
handle it.  MFC routes WM_COMMAND all over the place.  That is how the 
File menu commands work.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
3/2/2005 11:33:56 PM
> If you post the WM_COMMAND message to the main window the app class can
> handle it.  MFC routes WM_COMMAND all over the place.  That is how the
> File menu commands work.

This is a far better option than using PostThreadMessage if you want to
place the handler in application object.



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



0
ajaykalra (6842)
3/3/2005 2:04:56 AM
"Edward W" <EdwardW@discussions.microsoft.com> wrote in message 
news:79D08A83-1AFE-47F5-A6EC-63C9D9334130@microsoft.com...
> If you want to display a modal (or modeless) dialog when your MFC 
> application
> first starts up, where do you put it?  (This would be a login or an
> informational dialog that appears on top of the main window.)
>
> I tried putting it in the OnInitialUpdate() method in my CView-derived
> class, but I get asserts.
>

What I do is:


MAINFRM.CPP:

#define WM_INIT_DONE        (WM_APP)


  BEGIN_MESSAGE_MAP
    ON_MESSAGE (WM_INIT_DONE, OnInitDone)
  END_MESSAGE_MAP


  CMainFrame::OnCreate()
  {
     ...
    PostMessage (WM_INIT_DONE);
  }



  CMainFrame::OnInitDone()
  {
     // Show modal dialog
  }

The posted WM_INIT_DONE message will be pumped after all the necessary 
initialization takes place, so when OnInitDone() is called, it should be 
safe to show your modal dialog.

-- David
http://www.dcsoft.com


0
dc2983 (3206)
3/6/2005 12:11:25 AM
Reply:

Similar Artilces:

Opportunity needs to display Account and Contact
We are using opportunities to track our forecasted sales. There are multiple contacts with an account, so Opportunities are linked to the contact person. However, when viewed from a list of all opportunities, it just diplays the Contact Name - not the underlying acount the contact is associated with. We need to have the company name on the account also displayed. Any ideas how to do that? I thought about mapping accountid on the contact records to the opportunity and then displaying that field...but it is a system field with a data type that cannot be added (Lookup). Any other ideas, abs...

Resolution of secondary display
Hi, Can anyone please tell me how to determine the resolution of the display on a secondary monitor? I have an inkling GetDeviceCaps would do it if I could get a handle to the correct device context. I am using WinXP, Visual Studio 7.1, C++ with MFC Any help appreciated, Steph You need to use EnumDisplayDevices to find the devices, and then EnumDisplaySettings (using the ENUM_CURRENT_SETTINGS) to get the settings. You can also change any devices settings using ChangeDisplaySettingsEx AliR. <sm_sharp@lycos.co.uk> wrote in message news:1125408910.009549.88040@g14g2000cwa.googlegrou...

outlook 2003 memory leak? /messages display as"none" and eats up memory
Hi there; When a certian user opens outlook, and clicks on sort by size, half of her e-mails disappear, and "none" is displayed. She said this happened to her at home, except she was on her normal view which is sort by date. The only way that I can recreate the problem is to click on sort by size. If you click on one of the "none's" or even hover the mouse over it, the memory will spike up! I had the performance tab open while I was doing this, and the memory being used was read at 1.46 GB! And if I close outlook the memory drops down to normal. I took ...

OWA Inbox Subfolders no longer display? (Solved)
Outlook Web Access 2003 I have a strange issue occurring with OWA (Exchange Server 2003). When a user logs in and attempts to click on the + next to their INBOX to open the subfolders the hour glass animation starts and continues without any error or the display of the expected subfolders. I have tried multiple workstations and they all exhibit the same behavior. These are internal users so there is no firewall. This just started to happen last week. Possibly due to an Exchange update I installed last week. http://support.microsoft.com/?kbid=883543 Anyone have a clue? Solution: While...

Problems with Window in Dialog Owner Draw? #4
I Skin the CDialog based windows,in the window,the Minbox and MaxBox and CloseBox are exist,the title bar are Owner drawed of cause and the three "button",They show well,but the button in the task bar that stand for the Dialog ,does not work well, when the dialog is active,you click the button in task bar the dialog can not hide(Or as we say the dialog in min state.). thanks, Tylor ...

Object displays in reverse
I am using Office XP. I was sent a spreadsheet created in an earlier version of Excel. The spreadsheet includes 2 embedded objects originally created in Word. The first of the 2 objects displays and prints correctly. The second object displays and prints as a mirror image of itself. If I go into edit mode it displays correctly but I can find no way to "reverse" the reverse. If the same file is pulled up in Office 2000 Excel all displays and prints as it should. My fixes and Service packs are up to date. What can I do? Could this be it: OFFXP: Pictures in Earlier Of...

Use an If statement to display a picture
Hello, I want to use an If statement to display a picture i.e. if B1 = 1, the display a picture of a cat, if not display a picture of a dog. or The other way I thought of doing it was if I had a series of numbers then depending on which number the user clicked, a different pictur would be displayed. for info: it's actually for a chemistry lesson on carbon chains, so want pupils to either click on the number of carbons or type a numbe in, then the sheet will name the molecule (I can do this bit) and sho a picture of its structure (that's what I can't do) -- veci ----------...

My Startup is not functioning correctly
Everything I setup the Startup screen and open it up the database again, my selection is changed. And I have to do the set up all over again. What is going on here? Thanks for the help. Hi Ayo, Are you saying that settings you specify under Tools | Startup... are not "sticking"? For example, the settings for Application Title, Display Form/Page, Display Database Window option, etc? If so, I cannot say that I've ever experienced this, but I have experienced user-entered settings under File | Database Properties not sticking (for example the Title, Subject, Author, etc. ...

How to set print dialog to only come up once
How do you set the Print Dialog box to only show up once for the multiple reports that print? -- TC GP considers each set of reports different, reason why the print dialog comes up each time the report changes. However, you can avoid the print dialog altogether if you change your posting settings (Tools > Setup > Posting > Posting) to Printer and uncheck the Ask Each Time checkmark. Be sure to select the correct series and the proper origin for the transaction you are interested in. Best regards, -- MG.- Mariano Gomez, MIS, MCP, PMP Maximum Global Business, LLC http://www.m...

Dialog Box Opening Problem
When I open Excel, I get an error box telling me "Excel cannot open Access MDB files directly. ......... If I hit OK, I go into the program, but how do I prevent this error dialog from appearing every time I open Excel? Excel opens workbooks that are in you XLStart folder and workbooks (addins) that are checked in Tools|Addins. I'm gonna bet that you have a .mdb file in you XLStart folder. You could use windows|Find to search for xlstart. (You might have to tell Find to search for hidden files/folders, too.) If that doesn't work, (I've been wrong before!), Chip Pearson...

Play sound in dialog box
The subject talk by itself. How can I play a sound (wav) in a dialog box ? Check the PlaySound() or the sndPlaySound() -- Elias http://lgwm.org/ "shagshag" <shagplusplus@caramail.com> wrote in message news:07a501c38538$9c4caf80$a101280a@phx.gbl... > The subject talk by itself. How can I play a sound (wav) > in a dialog box ? ...

Hiding or Displaying Series In a Chart
Greetings, I have a XY Line chart that contains 9 Series, ploted at the same time. Due to visual clutter in this chart, I would like to have the option to enable or disable these lines by using a check box for each of the series. Is this possible? and how can this be done programatically?. Thank you in advance for your prompt response. Jon Peltier has instructions for using a check box to hide/show a series: http://www.peltiertech.com/Excel/Charts/ChartByControl.html SPYREN wrote: > I have a XY Line chart that contains 9 Series, ploted at the same time. Due > to visual clutter ...

Protecting/locking individual cells? + not displaying #N/A on cel
HI, My spreadsheet is using Vookup formulas and I would like to protect the cells with the formulas from others changing them but still alow the oter cells to be free . Such C1 free to place a number that will allow the protected B1 (which has the look up formulae) to have the resulting detail from the look up -locked/protected. ALSO- I have then copied the formulae down to the page and some cells will not have all the time an item in them so now they are showing the #N/A - can this be not displayed? Ta Mike On Sep 10, 8:47=A0am, MikeR-Oz <Mike...@discussions.microsoft.com> w...

How do you turn off "Save a copy/Overwrite changes" dialog box
Hello Guys, I have created a (password to open) workbook using Excel 2003 SP1 on a shared network drive which when I try to save by using Ctrl S or clicking the Save icon gives me an irritating dialog box which asks: "The file 'filename.xls' may have been changed by another user since you last saved it. In that case what do you want to do?" -Save a copy -Overwrite changes Please can someone tell me how to deactivate this annoying dialog box as I have been unsuccesful so far in my efforts :confused: Many thanks in advance Nick -- Nicko -----------------------------...

add screen rotation to Wince500 display driver of MISPII BSP
Hi: i want to add rotation display function to my display driver in Ce500,MIPSII BSP. the main code i add for rotation is: ///// m_iRotate=DMDO_90; if (FAILED(sc = AllocSurface(&m_pPrimarySurface, m_nScreenWidth,m_nScreenHeight, m_pMode->format, GPE_REQUIRE_VIDEO_MEMORY))) {..} ((GPESurfRotate *)m_pPrimarySurface)->SetRotation(m_nScreenWidth,m_nScreenHeight,m_iRotate);///m_iRotate==DMDO_90); ///// Display result: the main screen has been rotated to 90 degree. but the width , hight as the original. (not cross as w_90<...

Closing a dialog box
I have an application that calls MyDialog.DoModal(). When the box closes (via OK) it minimizes the application behind it. Why is this and how can I keep the application maximized? Thanks, where you are calling this DoModal from ? "John Garcia" <jggarcia@controlgaging.com> wrote in message news:eHQ20U5MEHA.2704@TK2MSFTNGP10.phx.gbl... > I have an application that calls MyDialog.DoModal(). When the box closes > (via OK) it minimizes the application behind it. Why is this and how can I > keep the application maximized? > > Thanks, > > I am calling it f...

Unable display folder
Hi, My system can not receive email. I upgrade it from Office 2000 to Office XP. Screen has message: Unable to display the folder. Microsoft outlook could not access the specified folder location. The .DLL file for the information service could not be found. MAPI was unable to load the information service PSTRX.DLL. Be sure the service is correcty installed and configured. I need help. Please email me cchen@glbtecx.com or call 949 450 8725. Thank you. .. ...

Child Dialog no mouse active
Hi all... I�ve develovep a MFC, SDI project application. The SDI is based on CFormView, this form calls a new dialog which is set to "child", this new dialog has button controls and edit controls...the thing is, when i create and show the child dialog i can click on the buttons and it triggers the code associated with it, but i can�t access the edit controls via mouse click, it seems to be disabled...but i can access the edit control via keyboard when the dialog has the focus... Can anybody help me? why is this happening? I�ve tried to set the dialog to modeless,when i do every...

display cell value in msgbox formatted as %
Hi I have been trying to come up with a way to display a cell value in a msgbox so that it formats properly as a percent. I have tried: Productivity = Format(Range("A1").Value, "###,# %") Msgbox Productivity This always gives me a leading 0 (e.g 015%) and I want it to display 15.0%. So I tried this: Productivity = Format(CStr(Range("A1").Value) * 100, "#,###.0") & "%" and it works ok but... I want to use the value of productivity in computations - which I can't formatted as a string ... Am I missing something - or is it as simple...

Getting my chart to display dates
i have two different values that i am charting on a scatter plot; projected value and actual value for each month. I want my X axis to be the months. For some reason when I go to format the axis it is showing the dates as the number code and is givng me no option to show each month. i can use the number code and set a maximum and minimum date but when i set a 30 day increment it duplicates a month over a long period of time. How do I get the axis to recognize that those are days and chart th value for each month? I want all the months to be displayed on the x axis. I hope this ma...

The form required to view this message cannot be displayed. conta
I am using Outlook 2003. I am just now encountering an error when trying to schedule to new calendar entries. Message: "The form required to view this message cannot be displayed. Contact your administrator". One change made to system today, I sync'd my I Phone that had calendar entries to this computer. My computer that I have been using since 2002 is dead. Right click on the contact folder and choose properties. What form is set as default? It should be ipm.contact. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook &...

Input Dialog for Image Overlay and Auto Duplication of Certain Obj
I am fairly new to Publisher so I am sure there is a way to accomplish the following, I just have not figured it out yet. I work as an Imagery analyst looking at overhead commercial satellite imagery. These images are used to create annotated products that have an overlay with basic information like date and time of image, coordinates of the image that is being displayed, copyright information etc. To help automate the process of creating these products, I would like to add an input dialog that asks for several key peices of information that will be inserted into Textboxes at certa...

Display DateTimePicker Calendar Through Code
I have a Date Time Picker control on my dialog (C++ 6.0) and a CDateTimeCtrl member variable mapped to that dialog item. I want to know how to make the calendar popup through code, say, if an invalid date was selected. I want to post a message box and then popup the calendar. Any ideas? MarcS SetFocus to the datetimepicker control, then call SendInput to send the key combination <Alt>+<downarrow> In article <1119470479.493281.64250@z14g2000cwz.googlegroups.com>, mscirri@osmose.com says... > I have a Date Time Picker control on my dialog (C++ 6.0) and a > CDateTim...

no option to add display name
I am running outlook xp on a both win98 and xp machines. In neither case can I find or set a display name for my email account (ie so others will see my display name). I have seen various suggestions about going to email accounts/change but there is just no option there for 'display name'. Is it something to do with the 'mode' of install? any advice appreciated david marcus David Marcus <dmarcus@netspeed.NO-SPAM.com.au> wrote: > I am running outlook xp on a both win98 and xp machines. In neither > case can I find or set a display name for my email account ...

Can multiple cell results be displayed in a single cell?
Is it possible to display the contents of multiple separate cells in another single cell? If the results of several cells say B1, B2, and B3 are the amounts $10, $15 and $20, I would like to display them in cell A1 as follows: $10 $15 $20 I could do this statically by using text and the 'Alt|Enter' function within the cell. However, these amounts will change from time to time so I'd like a link. Is this possible or not? Thanks for any help. Brett Brett One way: In A1: ="$"&B1&CHAR(10)&"$"&B2&CHAR(10)&"$"&B3&am...