How to make something like a calculator in windows.h?

So, I have made millions of calculators in C++ console applications, but not in <windows.h>. How do you make input in windows.h do something? Right now (maybe a retarded idea), I think you do it like this or another variation of it? Am I right?

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
//at the top of the page with all the szClass and LRESULT stuff
HWND button;
int a, b;

//at the bottom with the switch(message)

switch(message)
{
      case WM_CREATE: 
            button = CreateWindow("BUTTON",
                                  "1",
                                  WS_VISIBLE | WS_BORDER | WS_CHILD,
                                  50, 20, 40, 40,
                                  hwnd, (HMENU) 1, NULL, NULL);
            button = CreateWindow("BUTTON",
                                  "2",
                                  WS_VISIBLE | WS_BORDER | WS_CHILD,
                                  50, 60, 40, 40,
                                  hwnd, (HMENU) 2, NULL, NULL);
            textbox = CreateWindow("EDIT",
                                   a + b,
                                   WS_VISIBLE | WS_BORDER | WS_CHILD,
                                   50, 100, 100, 40,
                                   hwnd, (HMENU) 3, NULL, NULL);

            break;
        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case 1:
                a = 1;
                break;
            case 2:
                b = 2;
                break;
            case 3:
                a+b;
            }
            break;
        case WM_DESTROY:  /* send a WM_QUIT to the message queue */
            PostQuitMessage(0);
            break;


Now, this is probably never ever gonna work, but how can I make it work? Like, what do I do?
Am I right?

Well, you're heading in the right kind of direction... (see PS)

How do you make input in windows.h do something?

Have a look at

GetDlgItemInt
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645485%28v=vs.85%29.aspx

SetDlgItemInt
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645518%28v=vs.85%29.aspx

GetDlgItemText
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645489%28v=vs.85%29.aspx

SetDlgItemText
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645521%28v=vs.85%29.aspx

Andy

PS

line 2 : you're reusing the variable button for both your buttons?

line 21 : you need a string for the control to display, so use "+" rather than a + b (which makes no sense here)

line 14, 19, 24 : control IDs should avoid the lower number, which are used for standard controls (e.g. IDOK = 1, IDCANCEL = 2). Instead, offset the values (e.g.) 100 + 1, 100 + 2, ... And define others for the operations IDC_ADD = 200, IDC_SUBTRACT = 201, etc. as needed.

Why do dialog editors start assigning control IDs with 100?
http://blogs.msdn.com/b/oldnewthing/archive/2004/12/14/300204.aspx
Last edited on
Alright thanks I was looking at the msdn site but that site is so terribly set up I can hardly use it (meaning its hard to find anything I am looking for on it), so I am glad there are SOME people out there that can.
Topic archived. No new replies allowed.