Adding UI to an existing console project using windows form
-
Hi all!, I'm planning to create a windows form based UI to my existing console project. Would be great if someone can give a detailed step-wise procedure for the same. Here is the part of my code shows what all parameters I need to get through console:
printf ("\n");
printf ("-----------------------------------\n");
printf ("\n\n");printf ("Dyad name:"); scanf("%s",fname); printf ("\\n\\n"); printf ("Epoch number \[1-%d\]:",NEPOCHS); scanf("%d",&epoch); printf ("\\n\\n"); printf("Group: Haptic (0) or Visuo-haptic (1):"); scanf("%d",&lineEnable); printf ("\\n\\n"); switch(lineEnable){ case 0: // Haptic strcpy(prefix,"haptic"); break; case 1: // Visuo-Haptic strcpy(prefix,"visuohaptic"); } printf ("\\n\\n"); printf ("\[x\] - Exit application\\n"); printf ("\\n\\n");
Thank you!
-
Hi all!, I'm planning to create a windows form based UI to my existing console project. Would be great if someone can give a detailed step-wise procedure for the same. Here is the part of my code shows what all parameters I need to get through console:
printf ("\n");
printf ("-----------------------------------\n");
printf ("\n\n");printf ("Dyad name:"); scanf("%s",fname); printf ("\\n\\n"); printf ("Epoch number \[1-%d\]:",NEPOCHS); scanf("%d",&epoch); printf ("\\n\\n"); printf("Group: Haptic (0) or Visuo-haptic (1):"); scanf("%d",&lineEnable); printf ("\\n\\n"); switch(lineEnable){ case 0: // Haptic strcpy(prefix,"haptic"); break; case 1: // Visuo-Haptic strcpy(prefix,"visuohaptic"); } printf ("\\n\\n"); printf ("\[x\] - Exit application\\n"); printf ("\\n\\n");
Thank you!
Windows forms applications and console applications are quite different. If you want a full GUI then create a Forms application from scratch. However, since this is C++ you may like to investigate the Windows API or MFC. [edit] This looks much the same as your question of last June[^]. [/edit]
-
Hi all!, I'm planning to create a windows form based UI to my existing console project. Would be great if someone can give a detailed step-wise procedure for the same. Here is the part of my code shows what all parameters I need to get through console:
printf ("\n");
printf ("-----------------------------------\n");
printf ("\n\n");printf ("Dyad name:"); scanf("%s",fname); printf ("\\n\\n"); printf ("Epoch number \[1-%d\]:",NEPOCHS); scanf("%d",&epoch); printf ("\\n\\n"); printf("Group: Haptic (0) or Visuo-haptic (1):"); scanf("%d",&lineEnable); printf ("\\n\\n"); switch(lineEnable){ case 0: // Haptic strcpy(prefix,"haptic"); break; case 1: // Visuo-Haptic strcpy(prefix,"visuohaptic"); } printf ("\\n\\n"); printf ("\[x\] - Exit application\\n"); printf ("\\n\\n");
Thank you!
There is nothing very difficult you just need to deal with the console input/outpur code and put it into a window or dialog. The "Main" function becomes "WinMain" and you change the compilation from console to Win GUI. Normally its fairly trivial as everything but the user input/output elements will compile as is. Generally you just look at your console input/output and sketch out a couple of screens on paper then build that and start replacing the console calls into those screens. In that example above it would just be a dialog or window with the entry boxes. When the user has entered them you would press a button .. Ok/Continue etc ... check the entries are valid .. do what you want with them and continue on. It isn't really that hard. The start point is as always build the GUI screen skeleton to move you program into it. Here is a 5min mock up of your code you posted. I would probably use more advanced entry for epoch but I limited myself to 5min
#define _WIN32_WINNT 0x0500
#include
#include#define ID_DYANNAME 100
#define ID_EPOCHNUMBER 101
#define ID_GROUPBUTTONS 102
#define ID_HAPTIC 103
#define ID_VISUOHAPTIC 104
#define ID_PROCESS 200// This is your Data you want
char FName[256] = { 0 };
int epoch = 0;
char prefix[256] = { 0 };LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) { case WM\_CREATE: { CreateWindowEx(0, "STATIC", "Dyad name:", WS\_VISIBLE | WS\_CHILD | SS\_RIGHT, 20, 20, 300, 20, hwnd, 0, 0, 0); CreateWindowEx(0, "EDIT", "", WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT, 330, 20, 100, 20, hwnd, (HMENU) ID\_DYANNAME, 0, 0); CreateWindowEx(0, "STATIC", "Epoch number \[1-%d\]:", WS\_VISIBLE | WS\_CHILD | SS\_RIGHT, 20, 50, 300, 20, hwnd, 0, 0, 0); CreateWindowEx(0, "EDIT", "", WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT, 330, 50, 100, 20, hwnd, (HMENU) ID\_EPOCHNUMBER, 0, 0); /\*Group for Radio button for haptic or visuo-haptic \*/ CreateWindowEx(WS\_EX\_WINDOWEDGE, "BUTTON", "Select Mode:", WS\_VISIBLE | WS\_CHILD | BS\_GROUPBOX, 120, 80, 320, 70, hwnd, (HMENU) ID\_GROUPBUTTONS, 0, NULL); HWND Button = CreateWindowEx(WS\_EX\_WINDOWEDGE, "BUTTON", "Haptic", WS\_VISIBLE | WS\_CHILD | BS\_AUTORADIOBUTTON | WS\_GROUP, 130, 100, 200, 20, hwnd, (HMENU) ID\_HAPTIC, 0, NULL); CreateWindowEx(WS\_EX\_WINDOWEDG
-
Windows forms applications and console applications are quite different. If you want a full GUI then create a Forms application from scratch. However, since this is C++ you may like to investigate the Windows API or MFC. [edit] This looks much the same as your question of last June[^]. [/edit]
Thank you very much for the information
-
There is nothing very difficult you just need to deal with the console input/outpur code and put it into a window or dialog. The "Main" function becomes "WinMain" and you change the compilation from console to Win GUI. Normally its fairly trivial as everything but the user input/output elements will compile as is. Generally you just look at your console input/output and sketch out a couple of screens on paper then build that and start replacing the console calls into those screens. In that example above it would just be a dialog or window with the entry boxes. When the user has entered them you would press a button .. Ok/Continue etc ... check the entries are valid .. do what you want with them and continue on. It isn't really that hard. The start point is as always build the GUI screen skeleton to move you program into it. Here is a 5min mock up of your code you posted. I would probably use more advanced entry for epoch but I limited myself to 5min
#define _WIN32_WINNT 0x0500
#include
#include#define ID_DYANNAME 100
#define ID_EPOCHNUMBER 101
#define ID_GROUPBUTTONS 102
#define ID_HAPTIC 103
#define ID_VISUOHAPTIC 104
#define ID_PROCESS 200// This is your Data you want
char FName[256] = { 0 };
int epoch = 0;
char prefix[256] = { 0 };LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) { case WM\_CREATE: { CreateWindowEx(0, "STATIC", "Dyad name:", WS\_VISIBLE | WS\_CHILD | SS\_RIGHT, 20, 20, 300, 20, hwnd, 0, 0, 0); CreateWindowEx(0, "EDIT", "", WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT, 330, 20, 100, 20, hwnd, (HMENU) ID\_DYANNAME, 0, 0); CreateWindowEx(0, "STATIC", "Epoch number \[1-%d\]:", WS\_VISIBLE | WS\_CHILD | SS\_RIGHT, 20, 50, 300, 20, hwnd, 0, 0, 0); CreateWindowEx(0, "EDIT", "", WS\_VISIBLE | WS\_CHILD | WS\_BORDER | ES\_LEFT, 330, 50, 100, 20, hwnd, (HMENU) ID\_EPOCHNUMBER, 0, 0); /\*Group for Radio button for haptic or visuo-haptic \*/ CreateWindowEx(WS\_EX\_WINDOWEDGE, "BUTTON", "Select Mode:", WS\_VISIBLE | WS\_CHILD | BS\_GROUPBOX, 120, 80, 320, 70, hwnd, (HMENU) ID\_GROUPBUTTONS, 0, NULL); HWND Button = CreateWindowEx(WS\_EX\_WINDOWEDGE, "BUTTON", "Haptic", WS\_VISIBLE | WS\_CHILD | BS\_AUTORADIOBUTTON | WS\_GROUP, 130, 100, 200, 20, hwnd, (HMENU) ID\_HAPTIC, 0, NULL); CreateWindowEx(WS\_EX\_WINDOWEDG
Thank you so much for the information