![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 8
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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. |
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
try this
Quote:
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. |
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Apr 2005
Posts: 77
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Programmer
Join Date: May 2005
Posts: 41
Rep Power: 0
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|