How to Make a Window (an Application)

Get a compiler., After installing DEV-CPP, open it., Get ready to write a program to display text in a textbox., In the main screen of DEV-CPP, go to File -> New -> Project., At the begin of your source, type "#include " (without the quotes)., Write...

28 Steps 4 min read Advanced

Step-by-Step Guide

  1. Step 1: Get a compiler.

    A compiler transforms your raw source code (which you will soon write) into an executable application.

    For the purpose of this tutorial, get DEV-CPP IDE.

    You can download it here.
  2. Step 2: After installing DEV-CPP

    You will be presented with a window with a text area where you will write your source code. , Before you begin writing the source, keep in mind that Win32 applications don't behave in the same way as other languages, such as JAVA. , You will be presented with another screen.

    Choose the little picture which says "Windows Application" and set the language as "C"

    not "C++." At the text box where it says "Name"

    enter "Simple Program." Now, DEV-CPP will ask you where you wish to save it.

    Save the file in any directory, but just be sure to remember it.

    As soon as you are done with that, you will be presented with a template on the source screen.

    Do Ctrl+A and then Backspace.

    The reason we are doing this is so that we can begin anew. , This includes the windows library so that you can make an application.

    Directly beneath that, write: #include "resource.h" And then type: const char g_szClassName[] = "myWindowClass"
  3. Step 3: open it.

    Don't worry if this is confusing.

    It will become clear later on.

    Now, save your source as SimpleProg.c.

    We will be leaving it as is for the moment. , A Resource Script is a piece of source code which defines all your controls (e.g:
    TextBox, Buttons, etc.) You will incorporate your Resource Script into your program and Voila! You will have a program.

    Writing the Resource Script isn't hard, but can be time consuming if you don't have a Visual Editor.

    This is because you will need to estimate the exact X and Y coordinates of the controls, etc.

    In your DEV-CPP main screen, go to File
    -> New
    -> Resource File.

    DEV-CPP will ask you "Add resource file to current Project?" Click YES.

    At the top of your resource script, type #include "resource.h"

    and also type #include <afxres.h> This takes care of all the controls. , Type:, You can call it whatever you want, however.

    The BEGIN part is self explanatory.

    The POPUP "&File" makes a new menu category called File.

    The & sign allows the user of your application to type Ctrl+F on the keyboard and quickly access your menu :) The MENUITEM "E&xit"

    ID_FILE_EXIT adds a menu item to the File category.

    You must, however, define the menu item by doing ID_FILE_EXIT. , Your button will be inside a dialog, so we must make the dialog first.

    Do this by typing:, The four numbers after the word "DIALOG" determine x-pos, y-pos, width, and height of the dialog.

    Don't worry too much about the Style part for now.

    The MENU IDR_THEMENU puts our old menu into the program.

    The CAPTION speaks for itself as does the font.

    The DEFPUSHBUTTON creates our button named "Hello!" and we define it by saying ID_HELLO and give it x-pos and y-pos and width and height coordinates. , We're done with our resource script.

    Only one more thing remains.

    We have to assign values to all the things we defined in our resource script (e.g.

    IDR_THEMENU, etc.) Save the resource file as SimpleProg.rc , Add the source file to the current project? Yes.

    You will be presented with a blank screen.

    To assign values to our defined controls, we give them numbers.

    It doesn't matter too much on which numbers you give your controls, but you should make them organized.

    For example, don't define a control by giving it a random number like 062491 or something.

    So type:, Well, this is why we did it.

    We needed to assign values. , Type:, Just know that this parts returns the dialog to our message handling procedure called Simple Program. ,"

    MB_OK)break; case ID_FILE_EXIT:
    EndDialog(hWndDlg, 0);break;}break;case WM_CLOSE:
    EndDialog(hWndDlg, 0); break; default: return FALSE;}return TRUE;} , For example in the case ID_HELLO (our button), we make a message box saying hello.

    Also, in the case where we go to File and Exit, we close the window in case ID_FILE_EXIT. , This is important if you want your program to work. ,
  4. Step 4: Get ready to write a program to display text in a textbox.

  5. Step 5: In the main screen of DEV-CPP

  6. Step 6: go to File -> New -> Project.

  7. Step 7: At the begin of your source

  8. Step 8: type "#include <windows.h>" (without the quotes).

  9. Step 9: Write one method to handle all the messages and write another method where we will handle the messages from the resources.

  10. Step 10: Make a Resource Script.

  11. Step 11: Make your first control: a simple menu.

  12. Step 12: The "IDR_THEMENU" part defines your menu as THEMENU.

  13. Step 13: Now for the button part.

  14. Step 14: The IDD_SIMPLECONTROL defines your dialog.

  15. Step 15: That's it!

  16. Step 16: Go to File -> New -> Source File.

  17. Step 17: Save this file as resource.h Do you remember we did "#include "resource.h""?

  18. Step 18: Get back to the source

  19. Step 19: our Simple Program.c or whatever you called it.

  20. Step 20: Don't worry too much with all the technical stuff here.

  21. Step 21: Type:BOOL CALLBACK SimpleProc(HWND hWndDlg

  22. Step 22: UINT Message

  23. Step 23: WPARAM wParam

  24. Step 24: LPARAM lParam){switch(Message){case WM_INITDIALOG:return TRUE;case WM_COMMAND:switch ( LOWORD (wParam) ) {case ID_HELLO:MessageBox(NULL

  25. Step 25: "Hallo!

  26. Step 26: This part handles the dialog messages.

  27. Step 27: Make sure that your SimpleProc comes before the int WINAPI WINMAIN part!

  28. Step 28: Press F9 to compile and run your program!

Detailed Guide

A compiler transforms your raw source code (which you will soon write) into an executable application.

For the purpose of this tutorial, get DEV-CPP IDE.

You can download it here.

You will be presented with a window with a text area where you will write your source code. , Before you begin writing the source, keep in mind that Win32 applications don't behave in the same way as other languages, such as JAVA. , You will be presented with another screen.

Choose the little picture which says "Windows Application" and set the language as "C"

not "C++." At the text box where it says "Name"

enter "Simple Program." Now, DEV-CPP will ask you where you wish to save it.

Save the file in any directory, but just be sure to remember it.

As soon as you are done with that, you will be presented with a template on the source screen.

Do Ctrl+A and then Backspace.

The reason we are doing this is so that we can begin anew. , This includes the windows library so that you can make an application.

Directly beneath that, write: #include "resource.h" And then type: const char g_szClassName[] = "myWindowClass"

Don't worry if this is confusing.

It will become clear later on.

Now, save your source as SimpleProg.c.

We will be leaving it as is for the moment. , A Resource Script is a piece of source code which defines all your controls (e.g:
TextBox, Buttons, etc.) You will incorporate your Resource Script into your program and Voila! You will have a program.

Writing the Resource Script isn't hard, but can be time consuming if you don't have a Visual Editor.

This is because you will need to estimate the exact X and Y coordinates of the controls, etc.

In your DEV-CPP main screen, go to File
-> New
-> Resource File.

DEV-CPP will ask you "Add resource file to current Project?" Click YES.

At the top of your resource script, type #include "resource.h"

and also type #include <afxres.h> This takes care of all the controls. , Type:, You can call it whatever you want, however.

The BEGIN part is self explanatory.

The POPUP "&File" makes a new menu category called File.

The & sign allows the user of your application to type Ctrl+F on the keyboard and quickly access your menu :) The MENUITEM "E&xit"

ID_FILE_EXIT adds a menu item to the File category.

You must, however, define the menu item by doing ID_FILE_EXIT. , Your button will be inside a dialog, so we must make the dialog first.

Do this by typing:, The four numbers after the word "DIALOG" determine x-pos, y-pos, width, and height of the dialog.

Don't worry too much about the Style part for now.

The MENU IDR_THEMENU puts our old menu into the program.

The CAPTION speaks for itself as does the font.

The DEFPUSHBUTTON creates our button named "Hello!" and we define it by saying ID_HELLO and give it x-pos and y-pos and width and height coordinates. , We're done with our resource script.

Only one more thing remains.

We have to assign values to all the things we defined in our resource script (e.g.

IDR_THEMENU, etc.) Save the resource file as SimpleProg.rc , Add the source file to the current project? Yes.

You will be presented with a blank screen.

To assign values to our defined controls, we give them numbers.

It doesn't matter too much on which numbers you give your controls, but you should make them organized.

For example, don't define a control by giving it a random number like 062491 or something.

So type:, Well, this is why we did it.

We needed to assign values. , Type:, Just know that this parts returns the dialog to our message handling procedure called Simple Program. ,"

MB_OK)break; case ID_FILE_EXIT:
EndDialog(hWndDlg, 0);break;}break;case WM_CLOSE:
EndDialog(hWndDlg, 0); break; default: return FALSE;}return TRUE;} , For example in the case ID_HELLO (our button), we make a message box saying hello.

Also, in the case where we go to File and Exit, we close the window in case ID_FILE_EXIT. , This is important if you want your program to work. ,

About the Author

L

Lori Taylor

Specializes in breaking down complex practical skills topics into simple steps.

40 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: