Re: Altert boxes in MFC

Tech-Archive recommends: Fix windows errors by optimizing your registry



But it is generally a Really Bad Idea to do so. First, it requires having access to a
parent window (AfxMessageBox takes care of this for you). It requires supplying caption
text, which then causes confusion because the Microsoft recommended practice is to put the
name of the app as the caption (AfxMessageBox takes care of this for you). It requires
actual strings, while there is an overloaded form of AfxMessageBox that allows you to
specify the numeric ID of a STRINTTABLE resource and AfxMessageBox takes care of loading
the string.

You can supply the various icons and options to any form of message box creation calls,
including AfxMessageBox. See my MessageBox Explorer on my MVP Tips site.

Note also the code below is rather dated because it does not include the strings inside
_T(), which means that the strings must be 8-bit strings and you can't recompile this as
Unicode. It is important to develop good programming habits early in the MFC experience,
and there are several good rules to follow
1. Never put a local-language literal string in your program. If someone who does
not speak your language would need to see that string, then placing
it in your program is a design error. Use STRINGTABLE resources
2. When you need string or character literals, always enclose them in _T()
3. char does not exist except in very rare and exotic circumstances, and
if you do not have those, forget it exists as a data type
4. Use CString for all strings except in rare and exotic circumstances
5. strcpy and strcat no longer exist as usable functions. Prior to VS2005,
use StringCch... functions. VS2005 allows the use of strcpy_s and
strcat_s, but avoid ANY 'str'-named function; instead use the
Unicode-aware _tcs... functions
6. sprintf no long exists. See above point
7. new of arrays of objects should be avoided. Use CArray<type> or
std::vector<type> for arrays of objects
8. If the lifetime of the array is limited to a single scope, do not use 'new'
at all. Use a construct that is automatically deleted at the end
of the scope, e.g.,
LPBYTE data = new BYTE[n]; // bad style
...
delete [] data;
===================================
CByteArray data; // good style
data.SetSize(n);
9. If you use a global variable, you are wrong. If you think about it carefully,
and still decide to use one, you are still wrong. If you think about
it very hard, and it actually still makes sense, you might be right.
Exception (sometimes): global variables that start with 'const'.
10. Avoid putting anything in your CWinApp-derived class that can be used
by any other class anywhere else in your program. If you ever
write ((CMyApp*)AfxGetApp())-> you have a serious design error
in your program.
11. There is exactly one place your CWinApp-derived header file should appear
in your source files: in the CWinApp-derived .cpp file. In all other
files its appearance should be deleted. In most cases, simply replace it
by #include "resource.h". In some cases, such as subclassed
control classes, it can often be simply deleted with no replacement.
Alas, the VS tools throw this in everywhere, requiring constant vigilance
to see that it is deleted.
12. Never put anything in stdafx.h that belongs to your project. Until you have
enough experience to know the implications of doing this, you can
generally consider that any #define of constants, other than
build-configuration issues, is a mistake, inclusion of any variable
reference is a mistake, and including any header file via #include ""
is a mistake. If it isn't a #include<> of some standard library file,
assume it does not belong there.
13. Never edit stdafx.cpp. Ever.
This is just a start, but you might want to also check out my essay about "The n Habits of
Highly Unsuccessful Windows Programs" on my MVP Tips site.
joe

On Thu, 24 May 2007 02:13:03 -0700, rodream <rodream@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

You can use this function in any language.

MessageBox ( HWND, MessageText, CaptionText, ICONINFORMATION );

e.g.

::MessageBox( m_hWnd, "Message to Show", "Title of Message Box",
MB_ICONINFORMATION|MB_OK);

(*in C++, :: means use the global namespace)
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Damn you, FEDEX! or Nikon D40 lost in Springfield, MO blackhole.
    ... the 2 mp Mavica he had been using with a Nikon D40. ... After shopping around, he got me to order one for him. ... The shipper had it insured, but from what I have read it could take weeks to sort this crap out. ... You may get your insurance from FedEx and a couple weeks later they find it and deliver it. ...
    (alt.photography)
  • Formatierte MessageBox
    ... Darin waren RTF formatierte strings sodass man ... einzufügen, hat auch geklappt, jedoch kriege ich keine message in die ... Ich weiss nicht ob jemand von euch dieses TcxMessageBox schon zum ... MessageBox helfen könntet. ...
    (microsoft.public.de.vc)
  • Re: I suck
    ... its case or out of sight means you've less chance of picking it up for a ... Anyway,i took the strings off,cleaned the fretboard thoroughly and then ... Basically,if you're getting disheartened then give your guitar a bit of care ... Take care of your guitar,and it will take care of you. ...
    (alt.guitar.beginner)
  • Re: Question regarding strange intonation/chorusing
    ... > He took care of everything (mainly I had taken it in to do a fret ... How do you know it needed a "fret dressing"? ... The strings I have on there now are only 26.5 hours old ... > the string change history based on playing hours). ...
    (rec.music.makers.guitar)
  • Re: lazyweb request for reusable menu code
    ... when I decided life was too short and there must be a heap of ... What I'm after is something that takes as input a table of strings ... I don't really care how the display and navigation works (e.g. whether ...
    (comp.sys.apple2.programmer)