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 <windows.h>
#include <string.h>
#define ID_DYANNAME 100
#define ID_EPOCHNUMBER 101
#define ID_GROUPBUTTONS 102
#define ID_HAPTIC 103
#define ID_VISUOHAPTIC 104
#define ID_PROCESS 200
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);
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_WINDOWEDGE,
"BUTTON",
"Visuo-haptic",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
130, 125,
200, 20,
hwnd,
(HMENU) ID_VISUOHAPTIC,
0, NULL);
SendMessage(Button, BM_SETCHECK, BST_CHECKED, TRUE);
CreateWindowEx(0, "BUTTON", "PROCESS ENTRY",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
150, 165, 200, 50,
hwnd, (HMENU) ID_PROCESS, 0, 0);
}
break;
case WM_COMMAND:
switch LOWORD(wParam){
case ID_PROCESS: {
GetWindowText(GetDlgItem(hwnd, ID_DYANNAME), &FName[0], sizeof(FName));
char Temp[256];
GetWindowText(GetDlgItem(hwnd, ID_EPOCHNUMBER), &Temp[0], sizeof(Temp));
epoch = atoi(Temp);
if (SendMessage(GetDlgItem(hwnd, ID_HAPTIC), BM_GETCHECK, 0, 0)){
strcpy_s(prefix, sizeof(prefix), "haptic");
}
if (SendMessage(GetDlgItem(hwnd, ID_VISUOHAPTIC), BM_GETCHECK, 0, 0)){
strcpy_s(prefix, sizeof(prefix), "visuohaptic");
}
MessageBox(0, "You will process you data now", "ENTRY DONE", MB_OK);
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
break;
}
break;
case WM_DESTROY: {
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
MSG msg;
HWND hwnd;
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(wc);
wc.lpszClassName = "DemoDialog";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
RegisterClassEx(&wc);
hwnd = CreateWindow (wc.lpszClassName, "Demo Window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
200, 200, 500, 280, NULL, NULL, hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
In vino veritas
modified 24-Apr-16 23:42pm.
|