Question about c++

Is it possible to import c++ file(that opens in cmd) to GUI c++ project. like to assign it to a button or something like that.
import c++ file(that opens in cmd)
What do you have? Source file, object file, compiled executable?
source file and compiled executable
source file
If you have sources, it is simple. Just add them to your program project and use other program features like it was a simple library.
here is the source code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main()
{
   float x,y;

   cout << "Enter an event/s" << endl;
   cin >> x;
   cout << "Enter a number of outcomes" << endl;
   cin >> y;
   float a = x / y;
   float b = a * 100;

   cout << "probability is " << b << "%" << endl;

   system("pause");

   return 0;
}


i was wondering if you can help me a bit more cause im new to gui programming
Compiled with GCC g++ 4.8 Series Compiler on Windows 7 x64 as x64 binary. Came in 39 k...

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Main.cpp
#ifndef UNICODE
   #define UNICODE
#endif
#ifndef _UNICODE
   #define _UNICODE
#endif
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#define  IDC_X_TEXT             2000
#define  IDC_Y_TEXT             2005
#define  IDC_PROBABILITY_TEXT   2010
#define  IDC_CMD_BTN            2015


LRESULT CALLBACK WndProc(HWND hWnd, unsigned int wMsg, WPARAM wParam, LPARAM lParam)
{
 switch(wMsg)
 {
   case WM_CREATE:
     {
        HINSTANCE hIns=((LPCREATESTRUCT)lParam)->hInstance;
        CreateWindowEx(0,L"static",L"Enter x",WS_CHILD|WS_VISIBLE,20,40,80,24,hWnd,(HMENU)-1,hIns,0);
        CreateWindowEx(0,L"static",L"Enter y",WS_CHILD|WS_VISIBLE,20,70,80,24,hWnd,(HMENU)-1,hIns,0);
        CreateWindowEx(0,L"static",L"Probability",WS_CHILD|WS_VISIBLE,20,100,80,24,hWnd,(HMENU)-1,hIns,0);
        CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_CHILD|WS_VISIBLE,120,40,100,24,hWnd,(HMENU)IDC_X_TEXT,hIns,0);
        CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_CHILD|WS_VISIBLE,120,70,100,24,hWnd,(HMENU)IDC_Y_TEXT,hIns,0);
        CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_CHILD|WS_VISIBLE,120,100,100,24,hWnd,(HMENU)IDC_PROBABILITY_TEXT,hIns,0);
        CreateWindowEx(0,L"button",L"Calculate",WS_CHILD|WS_VISIBLE,235,55,75,50,hWnd,(HMENU)IDC_CMD_BTN,hIns,0);
        return 0;
     }
   case WM_COMMAND:
     {
        if(LOWORD(wParam)==IDC_CMD_BTN && HIWORD(wParam)==BN_CLICKED)
        {
           wchar_t szBuffer[32];
           GetWindowText(GetDlgItem(hWnd,IDC_X_TEXT),szBuffer,32);
           double x=_wtof(szBuffer);
           GetWindowText(GetDlgItem(hWnd,IDC_Y_TEXT),szBuffer,32);
           double y=_wtof(szBuffer);
           double a = x / y;
           double b = a * 100;
           swprintf(szBuffer,L"%12.8f",b);
           SetWindowText(GetDlgItem(hWnd,IDC_PROBABILITY_TEXT),szBuffer);
        }
        return 0;
     }
   case WM_DESTROY:
     {
        PostQuitMessage(0);
        return 0;
     }
 }

 return (DefWindowProc(hWnd, wMsg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 wchar_t szClassName[]=L"Zenga";
 WNDCLASSEX wc;
 HWND hWnd;
 MSG msg;

 memset(&wc,0,sizeof(WNDCLASSEX));
 wc.lpszClassName = szClassName;                wc.lpfnWndProc = WndProc;
 wc.cbSize        = sizeof (WNDCLASSEX);        wc.hInstance   = hInstance;
 wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,350,205,HWND_DESKTOP,0,hInstance,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&msg,NULL,0,0))
 {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
 }

 return msg.wParam;
}
Last edited on
woah!! im just gonna stay away from GUI.
Heh!

You should start small with a GUI library like Qt (http://qt-project.org) which is compatable with C++. See the examples and tutorials to get started.

After you figure out the basics of GUI programming in C++ you can graduate to using pure Windows API calls.
That's exactly what I said when trying to start with c++ GUI.
thanks.
Topic archived. No new replies allowed.