2

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

7
  • 3
    I feel it's worth stating that if you're talking about developing a windowed application in C, then you're opening a whole world of hurt for yourself. If you're doing this because you know C and are wary of the learning curve involved in getting up to speed on C# or Java, then you're worrying about the wrong thing. You'll develop your app faster in C# including the C#/.Net/OOP learning curve than you will a useful windows app in C. I realise this advice may not apply to you, but feel it's better said than not. Jul 30, 2010 at 15:36
  • 1
    P.S. When Rocket Scientists & Brain Surgeons want a metaphor in place of "At least it's not Rocket Science/Brian Surgery" they say "At least it's not developing a Windows App in C". Jul 30, 2010 at 15:45
  • @Ankit: It would be helpful if you gave more detail around what constitutes "usable" for you. Is the thrust of your question that you're looking to get into Windows programming in general, but ideally with C? Are you already a Windows programmer at a higher level looking to understand lower-level stuff? Etc.
    – Ben Zotto
    Jul 31, 2010 at 0:17
  • @Binary Worrier I just want to move ahead from being able to just write pieces of code which are actually useless.I think I'll take your advice about this. I'll go for C#. I am choosing C# over Java as I think I'll find it easier to grasp having a understanding of C. Is that correct?
    – Ankit
    Jul 31, 2010 at 14:32

5 Answers 5

6

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

2
  • 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
    Jul 30, 2010 at 16:52
  • 1
    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. Jul 30, 2010 at 23:34
3

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.

2
  • 1
    +1. But how about this: #include <windows.h> int main() { MessageBox(NULL, "Hidey Ho", "Message", MB_OK); return 0; } :-) Jul 30, 2010 at 23:39
  • 1
    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. Jul 31, 2010 at 6:59
1
#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.

4
  • 1
    @0A0D: You can be a windows application and not actually create a window. Jul 30, 2010 at 16:39
  • Wouldn't that technically be a service? Even a console application has a "window"
    – user195488
    Jul 30, 2010 at 17:40
  • @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. Jul 30, 2010 at 18:02
  • Right, but services are windows applications in a sense :) Aren't semantics fun?
    – user195488
    Jul 30, 2010 at 19:20
1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.