New student of C++ plz reply me

Friends I'm a student of C++. I want to ask that is it possible to write an windows application which opens by double click (other than DOS :/ ) and can give prompt (or dialog box) to the user etc. Hope you understand what I want to say :)
And pleaseeee show me any application written in C++. (or give me code of very simple app : )
Thanksssss a lot.
Please be a little more specific, you want to open an actual window like a win 32 window or open a program using c++? what compiler are you using? how simple do you want the code?
Last edited on
Good point. You need to be more specific.
Ok. I'm using Dev-C++ (bloodshed.net) editor and compiler.

Currently I have wrote programs like accounting etc that runs in DOS.

I just want to write an application for windows xp which opens like other applications, not in DOS. like windows Calculator etc.

Guide me please..
You need to learn Windows API. If your just starting out with C++ its better to learn the C++ basics before you get into doing things that are a bit more complicated such as Windows API
Ok. Thanks.

I was asking is it possible to write such programs using C++? Then I will have to learn more.

One thing more. Which compiler do you suggest??
Last edited on
You cant create windows with C++. I have learned C++ and have been learning Windows API for around a month now. It isnt all that difficult but its not that easy either. Win32 and C++ are 2 different languages just so you know.

Oh. Ok. Then by which language these applications are written??? I have to focus to them too.
But C++ is in my course : )

And compiler???
Things like windows, popup boxes, programs like notepad folders etc are all done with Windows API, You use C++ with Windows API to make a program such as the ones mentioned and more. I would suggest using Code blocks instead, as Dev C++ is very old, outdated, and not even updated anymore.

EDIT: Also, Code blocks has a win32 project type you can choose when setting up your project, its a simple window with 2 buttons. Play around with that, and learn all the syntax. Here is a list someone gave me, it describes all the keywords in the code blocks win32 project:

Hopefully im not overwhelming you withh all of this.


HWND = handle to the object(buttons, text boxes, text, etc..)

HINSTANCE = The window class name is not sufficient to identify the class uniquely so the hinstance is used to do that.

DialogProc = function name... In your case you translate messages in this function.

UINT = unsigned int

WPARAM and LPARAM = Whole win32 api is communicating trough messages. Sometimes these messages need to transfer some additional information about this message in order to understand it. So WPARAM and LPARAM holds that information.

WM_INITDIALOG = 0x0110(hex)

LOWORD and HIWORD = Like i said that all communication is done with messages and these messages sometimes need to transfer additional information. So the WPARAM and LPARAM can hold more then 2 values. This is done by splitting the WPARAM or LPARAM in to HIWORD and LOWORD. Its the same as you would split the unsigned integer(4 bytes) in to two unsigned short integers(size 2 bytes)

APIENTRY = __stdcall entry point. Most of programing languages have functions. And all these languages have their own function conversion types(in which order the parameters will be passes in this function), who will clean the mess after this function and so on. The entry point in other hand means location from where the program will start to execute. In c++ you find the main() function which does that. For example in .DLL's there are DLLMain() function which only initializes the .DLL and the rest of .DLL content can be executed trough entry points. One more example: The .DLL is a program without main() function. So you can not run it unless you tell from where to execute it. And .DLL's can be loaded(started to execute) with most of programing languages. But like i said that they treat functions differently, so these functions(entry points) in .DLL need to be in such a way that all programing languages could access it. __stdcall conversion is standard function conversion while in c/c++ standard is __cdecl. More about this : http://msdn.microsoft.com/en-us/library ... 58(v=vs.71).aspx

hPrevInstance = will always be NULL because this variable is left from windows 95...

LPSTR = char * (pointer character array)

lpCmdLine = something like char * _argv[] in your standard c++ application. The program can be called in different ways like double clicking the icon, from command line, etc... So if the program is called from console then the main can accept char ** array parameters, which then can be translated to numbers, constants etc.. Notice that its is meant to hold console parameters, not holding...
nShowCmd = The flags that specify how an application is to be displayed when it is opened. Minimized, maximized, tray, etc...

MAKEINTRESOURCE = converts integral value to resource type compatible.

DLG_MAIN = integral value. All your resources must have some kind of ID. In most cases it will be some kind of number. In this case this particular resource have its value : DLG_MAIN. Check out the resource files and header files. You should find the actual resource and where DLG_MAIN is defined and whats its value.

WinMain = main() in standard c++ (main entry point)



Here is a simple text editor i made, its nowhere near good or done, but it works and hopefully it will help you:

Main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include <fstream>
#include <string>

using namespace std;

HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG: //Initiates the window
            //Menu Initialization
            {
                HMENU hMenu = LoadMenu(GetModuleHandle(0), MAKEINTRESOURCE(Menuone));
                SetMenu(hwndDlg, hMenu);
            }
            return TRUE;

        case WM_CLOSE:

            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:


            switch(LOWORD(wParam))
            {
                case ID_Save:
                    {
                        ofstream file("save.txt");

                        char tmp[MAX_PATH+1] = {0};
                        GetDlgItemText(hwndDlg, 3, tmp, MAX_PATH);

                        file << tmp;
                        file.close();
                    }return TRUE;

                case ID_Exit:
                    {
                        EndDialog(hwndDlg, 0);
                    }return TRUE;

                case ID_Load:
                    {
                        MessageBox(hwndDlg, "This option is not functional yet", "Error", MB_ICONERROR);
                    }return TRUE;
            }
    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}


Resource.rc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "resource.h"

DLG_MAIN DIALOGEX 280, 170, 300, 162

CAPTION "TexEd V. 1.1.1 Alpha"

FONT 8, "Tahoma"

STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU


BEGIN
    EDITTEXT 3, 0, 0, 300, 150, ES_MULTILINE | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL
END

//The menu for the program

    Menuone MENU
    {
      POPUP "File"
      {
          MENUITEM "Save", ID_Save
          MENUITEM "Load", ID_Load
          MENUITEM "Exit", ID_Exit
      }

    }

//Reference
 /*
{
     MENUITEM "&Soup", 100
     MENUITEM "&Salad", 101
     POPUP "&Entree"
     {
          MENUITEM "&Fish", 200
          MENUITEM "&Chicken", 201
          POPUP "&Beef"
          {
               MENUITEM "&Steak", 301
               MENUITEM "&Prime Rib", 302
          }
     }
     MENUITEM "&Dessert", 103
}
*/

Icon ICON "Resources/Txt.ico"




Resource.h:

#include <windows.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <windows.h>

// ID of Main Dialog
#define DLG_MAIN 101

#define text 1
#define Icon 2
#define Menuone 3



//Menu Item ID's
#define ID_Save 6
#define ID_Load 7
#define ID_Exit 8 
Last edited on

You cant create windows with C++. I have learned C++ and have been learning Windows API for around a month now. It isnt all that difficult but its not that easy either. Win32 and C++ are 2 different languages just so you know.


That isn't really the best choice of words ch1156.

It would be more accurate to state that the functions to create GUI objects with the Windows operating system are not part of the C or C++ languages, nor are they part of the C or C++ Standard Libraries. Rather, they are part of the Windows Api. So yes, you can create windows with C++, but you have got to call the Windows Api functions to do so. I'm sure that is what you meant, but since the original poster appears new to all this, I didn't want him/her to misunderstand.

Opinion time.

C++ is one of the most difficult routes you could take to learn how to write Windows GUI programs. First you've got to learn C++ in a console mode setting. No small chore there. Next you've got to either learn an application development framework that sits on top of the Windows Api and hopefully shields you from it, or you've got to learn Win32 itself which is no small chore either. For both you're probably looking at a year to two years just to get yourself out of the absolute beginner category.

I'm really of the opinion that most folks would be better off learning .net in some form or other, especially when their main interests are business applications, LOB apps or something like that.

Now if the ultimate in speed and performance is an issue; well, that's something different.
I agree freddie1 thank you for clearing that up for both of us :). It took me 4 months to learn the basics of C++ and even now im not fully done, i just started Win32 a month ago and im making good progress but there is much more for me to learn. So Real Hyder Have you ever seen Bucky Roberts C++ Tutorials? thats how i learned and if you'd like i'll give you the link to his youtube page. If you dont already have it that is.
Last edited on
@Ch1156. Thanks for giving help.


@freddie1 @Ch1156
"a year to two years just to get yourself out of the absolute beginner category."

Oh. Ok. I want to say bla bla bla :(

Basically I'm studying MCS (Masters of Computer Sciences). Our course book (about C++ and programming) is based on the book of Deitel & Deitel "C++ How to Program".

I love to making software, progs, apps. But : ( I just learn C++ for pass my exam. I'm thinking to use C++ to develop applications. If C++ dosn't allow me at this stage then : )

I want to say you that I want to build an app for windows that runs on the taskbar and get mail from website mail box using Id and Password then prompt to the user.

I have to learn what you said above a number of techniques : ) I will try.

Is there are software that allows to built applications by drag and drop things/functions/buttons etc.

I told you my whole problem : ) Plz don't laugh at me :/
"Is there are software that allows to built applications by drag and drop things/functions/buttons etc."

Microsoft Visual studio allows this, you can build an entire full out GUI with everything you can ever want in like 5 or 10 minutes, minus some of the coding that needs to be done. The software isnt free but i think a freewre version does exist.
Last edited on
"Microsoft Visual studio"

Ok. Thank you so much.

I will back to get help in C++ from you, when ever I needed. Thanks again.
Your welcome glad to help :)
Topic archived. No new replies allowed.