Nuclear Dawn Visual C++ Tutorial 1

Author:
Norse (
norse@swipnet.se, www.cryogen.com/nucdawn)

This is the first tutorial in my Visual C++ Programming Series. I have recently discovered exactly how groovie windows programming is! With several cool libraries like DirectX, Glide and OpenGL you can do a lot of neat things. I will be using Visual C++ 6 from Microsoft and everything should compile without errors with it and I do not recommend using other Compilators (though they will most probably work with only slight modifciations. Well here goes nothing...

PURPOSE: To Create a Windows Dialog Box that says something and then lets you press the OK button.
Compiler: Visual C++ 6

First off, create a new application (New->Win32 Application) and name it Tut1OK or something. Choose a blank/empty application and it ought to say, well then I won't create any files for you. Fine. Now create a new Source file (.cpp). All right, you're ready! Here, without further bs comes the source code (WITH COMMENTS! WOW! :)

 

/* Nuclear Dawns Visual C++ Programming Tutorial #1 */

//Includes a bunch of neat stuff
#include <windows.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>

//This is the Application's name which will be called at differnt
//times, for instance in the top-border of it, in the ctrl+alt+del
//box and so forth.
char szAppName[]="ND-Visual Tutorial 1";

//Main Program Segment. It is from here everything is executed.
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int CmdShow) {

//Reads Current Local Desktop to check if it possible to create
//the box. It also focuses on the desktop alone.
  SetFocus(GetDesktopWindow());

//Here's the fun part, it's the box itself.
  MessageBox(
    GetDesktopWindow(), //Create the window/box
    "       Congratulations!\n" //Text
    "You have written your first\n" //Text
    "     Windows Program!", //Text
	  szAppName, //The appname is fetched
    MB_OK //The OK Button
  );

//If something goes wrong, send it to the hell! :)
  if(!LockWindowUpdate(GetDesktopWindow())) {
    MessageBox(NULL,szAppName,szAppName,MB_OK|MB_ICONEXCLAMATION);
    return FALSE;
  }
  LockWindowUpdate(NULL); //Unlock windows (DO NOT REMOVE!)
  return TRUE; //Returns, ok the program worked and ends.
}
Downloads: Source Code+This Html Page.