views:

107

answers:

6

Can anyone tell me how I can create a basic usable Windows application in C (I have a little idea about C++ also) ?

A: 
#include <stdlib.h>
int main()
{
    printf("Hello World!");
}

Will compile and run as a windows application. If you want to do something specific, then please let us know. There is nothing that makes Windows applications any different than any other applications.

Billy ONeal
except maybe a Window :)
0A0D
@0A0D: You can be a windows application and not actually create a window.
Billy ONeal
@Billy: Wouldn't that technically be a service? Even a console application has a "window"
0A0D
@0A0D: Hmm.. I suppose that's true. But it wouldn't be a service because a service refers to a program started by the Service Control Manager.
Billy ONeal
@Billy: Right, but services are windows applications in a sense :) Aren't semantics fun?
0A0D
+3  A: 

Get Petzold's Programming Windows book; it's a classic and covers Win32 development from its core C roots.

quixoto
Downvoted? really?
quixoto
That's pretty hard to believe, as his book is more or less the standard text on the subject to the best of my knowledge.
dsolimano
I've noticed so many perfectly good answers getting uncommented downvotes that I'm beginning to suspect there are hoards of ignorant miscreants wandering these pages.
Amardeep
A: 

Perhaps the video at this link will help. If not there's TONS of other resources available on MSDN that will get you started.

Other than that "How to write a Windows Program" is just to broad and large a topic to really address here.

torak
A: 

Raymond Chen's scratch program is a minimally functional white box, and a good base to work through some of the other articles that he publishes.

You can compile this in Visual Studio. In VS2005, I created a new empty C++ project and added comctl32.lib to Configuration->Linker->Input->Additional Dependencies.

dsolimano
+1  A: 

The most minimal windows C program is this :-

#include <windows.h>
#include "resource.h"

int CALLBACK WinMain(HINSTANCE hApp, HINSTANCE, LPSTR pszCmdLine, int nCmdShow)
{
  return DialogBoxParam(hApp,MAKEINTRESOURCE(IDD_DIALOG1),NULL,NULL,NULL);
}

It assumes you have used the resource editor to create a dialog resource called IDD_DIALOG1. The dialog will display, and close if the Close button is clicked.

Chris Becke
+1. But how about this:`#include <windows.h>int main(){ MessageBox(NULL, "Hidey Ho", "Message", MB_OK); return 0;}`:-)
Amardeep
that IS really simple. The point with starting with a dialog resource is you can actually grow the program by adding a dialog proc and handling messages.
Chris Becke