Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 1st, 2005, 6:51 PM   #1
JJProductions
Newbie
 
Join Date: May 2005
Posts: 8
Rep Power: 0 JJProductions is on a distinguished road
Cout and Messagebox Functions Together

For some reason, when I try to use cout functions and messagebox functions, it does not work; instead it closes immediately before doing anything

The Code:
#include <windows.h>
#include <iostream>

using namespace std;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
  MessageBox(NULL, "Testing...", "This is a test...", MB_OK | MB_ICONWARNING);
}

int main()
{
    cout<<"Testing...";
    cin.ignore();
    return 0;
}

What it does is display the text, but not the messagebox :o
JJProductions is offline   Reply With Quote
Old Aug 1st, 2005, 7:09 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You have to decide if you are making a "console" app or a GUI ("Windows") app. Cout is a console function (that's what the "c" stands for). MessageBox is normally a GUI function, although one can invoke it from a console application. WinMain is normally the entry point for a GUI app, main is normally the entry point for a console app. You don't mention how you are generating the programs (pure text editing with command line compiling and linking, via some IDE, whatever). Apparently the build process is using main, so there's actually nothing going on to invoke the message box.

cin.ignore () is doing nothing useful in your program as it stands, incidentally.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers

Last edited by DaWei; Aug 1st, 2005 at 7:26 PM.
DaWei is offline   Reply With Quote
Old Aug 2nd, 2005, 9:55 AM   #3
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
try this

Quote:
Originally Posted by JJProductions
What it does is display the text, but not the messagebox
try this...
make a console app and put the following code in it.
#include <windows.h>
#include <iostream>

using namespace std;

int main()
{
    cout<<"Testing...";
    MessageBox(NULL, "Testing...", "This is a test...", MB_OK | MB_ICONWARNING);

    return 0;
}
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Aug 2nd, 2005, 11:57 AM   #4
Josef_Stalin
Programmer
 
Join Date: Apr 2005
Posts: 77
Rep Power: 4 Josef_Stalin is on a distinguished road
Yeah it is a pain that you train yourself to use cin and cout and then you get to Windows programming and all of a sudden you drop these to use messageboxes and dialogboxes for input.
Josef_Stalin is offline   Reply With Quote
Old Aug 2nd, 2005, 12:04 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Training for more than one thing is not an unusual life incident. Hell, I trained my dog to use newspaper, then to go outside, then to use the commode AND PUT THE SEAT BACK DOWN!
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 4th, 2005, 12:12 PM   #6
MrSmiley
Programmer
 
MrSmiley's Avatar
 
Join Date: May 2005
Posts: 41
Rep Power: 0 MrSmiley is on a distinguished road
DaWei, you crazy man, you. Yup, I can write in 4 differnt forms of GUI programming... Qt, GTK (Qt > GTK), MFC, and wxWindows for c++. C++ is not the only language I know also. Now that is a pain ;P, nah, not really. I'm sure 95% of the users on this board know more than 1 language.
When I refer to language, I do mean programming languages not verbose languages.
MrSmiley is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC