-
Need a little help
I'm just trying to get the Hello World program to display in a Win32 App (I think that's what I picked:p )
Code:
// New Test1.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "stdio.h"
#include "iostream.h"
#include "conio.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
cout<<"Hello World!";
getch();
return 0;
}
It compiles fine, but when I try and run the program it does do anything.
MSVC++ Intro Version
-
If you want a console in a win32 application (as oposed to a console application) you'll have to make your own -
Code:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPCSTR output= "Hello World!";
LPCSTR terminate = "Press any key to continue...";
DWORD written;
DWORD read;
INPUT_RECORD ir;
AllocConsole();
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
output,strlen(output),&written,NULL);
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
"\n",1,&written,NULL);
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
terminate,strlen(terminate),&written,NULL);
for(;; )
{
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE),&ir,1,&read);
if (ir.EventType==KEY_EVENT)
break;
}
FreeConsole();
return 0;
}
Alternatively, select console app from the menu.
-
Well that's what MSVC++ started me with. Then it had a spot that said code here, so I did and it won't do anything when I want it to run.
-
Replace
cout<<"Hello World!";
getch();
with
MessageBox(NULL, "Hello World!", "My Program", MB_OK | MB_ICONINFORMATION);
you can't use functions like cout or getch(); in a windows program!
-
Really!?! LOL, I never knew that.
Thanks man, that really helps!;)
-
So what kind of Windows thing was that? A Win32 App? Here's the code for anyone who wants to answer the question;)
Code:
// New Test1.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "stdio.h"
#include "iostream.h"
#include "conio.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MessageBox(NULL, "Hello World!", "My Program", MB_OK | MB_ICONINFORMATION);
}