Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help using Message Boxes in VC

0 views
Skip to first unread message

Rubber Ducky

unread,
Jun 17, 2001, 10:15:24 AM6/17/01
to
Can anyone point me to an example of a simple proggie that shows a message
box, and then then finds out which button the user pressed.
I have this code, but it seems not to work:

#define STRICT
#include <windows.h>
#include "StdAfx.h"

int i;

i = AfxMessageBox("Simple message box\n", MB_YESNOCANCEL||MB_ICONSTOP);
return 0;

I get error:
C:\Project\msgbox.cpp(45) : error C2065: 'AfxMessageBox' : undeclared
identifier

--
Thanks
Rubber Ducky

Please reply to group or to email
To reply to email remove NOSPAM

Richard Norman

unread,
Jun 17, 2001, 10:43:55 AM6/17/01
to
"Rubber Ducky" <ne...@ayliffe.comNOSPAM> wrote in message
news:0Y2X6.30246$J25.4...@news1.cableinet.net...

> Can anyone point me to an example of a simple proggie that shows a message
> box, and then then finds out which button the user pressed.
> I have this code, but it seems not to work:
>
> #define STRICT
> #include <windows.h>
> #include "StdAfx.h"
>
>
>
> int i;
>
> i = AfxMessageBox("Simple message box\n", MB_YESNOCANCEL||MB_ICONSTOP);
> return 0;
>
> I get error:
> C:\Project\msgbox.cpp(45) : error C2065: 'AfxMessageBox' : undeclared
> identifier
>
> --
> Thanks
> Rubber Ducky
>

Always put #include "stdafx.h" on the VERY FIRST LINE of your code.
The compiler ignores anything it finds before that.

Scott McPhillips

unread,
Jun 17, 2001, 11:02:46 AM6/17/01
to
Rubber Ducky wrote:
>
> Can anyone point me to an example of a simple proggie that shows a message
> box, and then then finds out which button the user pressed.
> I have this code, but it seems not to work:
>
> #define STRICT
> #include <windows.h>
> #include "StdAfx.h"
>
> int i;
>
> i = AfxMessageBox("Simple message box\n", MB_YESNOCANCEL||MB_ICONSTOP);
> return 0;
>
> I get error:
> C:\Project\msgbox.cpp(45) : error C2065: 'AfxMessageBox' : undeclared
> identifier
>
> --
> Thanks
> Rubber Ducky

The Afx... family of calls are in the MFC library but you haven't
#included the MFC definitions. You can build a Win32 API program or you
can build an MFC program, but you've got a mixed-up bit of each in your
#include's here. Whichever way you are trying to go, first build a
skeletal program using the wizard (File, New, Project,...) to get
started on the right foot.

--
Scott McPhillips [VC++ MVP]

Ari Lukumies

unread,
Jun 19, 2001, 7:21:14 AM6/19/01
to
Rubber Ducky wrote:

> Can anyone point me to an example of a simple proggie that shows a message
> box, and then then finds out which button the user pressed.
> I have this code, but it seems not to work:

#include <windows.h>

int main(void)
{
rc = MessageBox(0, "Test", "Testing", MB_YESNOCANCEL);
if (rc == IDYES)
; yes pressed
else if (rc == IDNO)
; no pressed
else if (rc == IDCANCEL)
; cancel pressed
return 0;
}

HTH,
AriL

0 new messages