Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello World Tutorial 2

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I'm fine programming C, C++ & a myriad of other languages, but this is my first forray into VC++ since 1994, and even then I didn't do that much.

I've opened up VS2005, created a new Win32 project (cause of what I'm doing I want to avoid .NET & such.), and wow, do I feel like I'm looking at greek.

Maybe I'm starting with the wrong kind of project since my goal is actually to be an invisible executable (I'm going to be sending signals to another executable is all) but I'm not sure.

Anyone point me to a Hello World style tutorial just to get my feet wet?
 
I don't know of any tutorials off the top of my head, but this code should work. If it doesn't, then you should create a new project with different settings.

Make a Win32 Console Application, and be sure to click Empty Project on the Application Settings page of the wizard. Then right-click on Source Files in the Solution Explorer and add a new item. Select cpp file and give it a name. Then when it opens, paste the following code:
Code:
#include <iostream>

int main()
{
    std::cout << "Hello World!\n";
}
Add an extra line at the bottom and save the file.

Press F7 to build it and Ctrl-F5 to execute it. If it shows a console window that says Hello World!, then you've got your hello world running and you can use the same technique to run other regular C++ code.
 
Yeah, I mean that's the kind of C++ I know.

What's throwing me for a loop is stuff like

Code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_XXXX, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_XXXX));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}
 
Select Win32 Console Application, not a simple Win32 Application (GUI based on native Win32 API).
 
Console application will open a console window, skiflyer mentioned he wants windowless application. Also you cann't think about "Hello world" if there is no window to output messages. Lets following code snippet be compiled:
Code:
#include "windows.h"

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
MSG msg;
bool endfl=FALSE;

   do
   {
      GetMessage(&msg, NULL, 0, 0);
      TranslateMessage(&msg);

      switch(msg.message)
      {
      case WM_QUIT:
         endfl=TRUE;
         break;
      }

   } while(!endfl);

return(0);
}
 
There's a "Hello World" program in Petzold's book.

Before he progresses to the difficult stuff.
 
Exactly the kind of snippit and reference I needed... thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top