Click here to Skip to main content
15,889,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionExchanging data using CSocket Pin
manoharbalu22-Apr-16 22:30
manoharbalu22-Apr-16 22:30 
AnswerRe: Exchanging data using CSocket Pin
Jochen Arndt22-Apr-16 23:30
professionalJochen Arndt22-Apr-16 23:30 
GeneralRe: Exchanging data using CSocket Pin
manoharbalu24-Apr-16 20:23
manoharbalu24-Apr-16 20:23 
GeneralRe: Exchanging data using CSocket Pin
Jochen Arndt24-Apr-16 20:53
professionalJochen Arndt24-Apr-16 20:53 
QuestionAdding UI to an existing console project using windows form Pin
Member 935023722-Apr-16 6:05
Member 935023722-Apr-16 6:05 
AnswerRe: Adding UI to an existing console project using windows form Pin
Richard MacCutchan22-Apr-16 6:47
mveRichard MacCutchan22-Apr-16 6:47 
GeneralRe: Adding UI to an existing console project using windows form Pin
Member 935023725-Apr-16 21:51
Member 935023725-Apr-16 21:51 
AnswerRe: Adding UI to an existing console project using windows form Pin
leon de boer24-Apr-16 15:49
leon de boer24-Apr-16 15:49 
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

// 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_WINDOWEDGE,
					"BUTTON",
					"Visuo-haptic",
					WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
					130, 125,
					200, 20,
					hwnd,
					(HMENU) ID_VISUOHAPTIC,
					0, NULL);

				// Set the Haptic checkbox
				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: {
					// Fetch FName
					GetWindowText(GetDlgItem(hwnd, ID_DYANNAME), &FName[0], sizeof(FName));

					// Fetch NEPOCHS its in text format the convert it
					char Temp[256];
					GetWindowText(GetDlgItem(hwnd, ID_EPOCHNUMBER), &Temp[0], sizeof(Temp));
					epoch = atoi(Temp);

					// Fetch buttons
					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");
					}

					// You data is ready to process ... we will just tell you and exit program
					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.

GeneralRe: Adding UI to an existing console project using windows form Pin
Member 935023725-Apr-16 21:55
Member 935023725-Apr-16 21:55 
QuestionCode Blocks giving fatal error of not finding header file when there are seperate class files Pin
Mur250122-Apr-16 3:07
Mur250122-Apr-16 3:07 
SuggestionRe: Code Blocks giving fatal error of not finding header file when there are seperate class files Pin
Richard MacCutchan22-Apr-16 4:15
mveRichard MacCutchan22-Apr-16 4:15 
QuestionRe: Code Blocks giving fatal error of not finding header file when there are seperate class files Pin
David Crow22-Apr-16 17:58
David Crow22-Apr-16 17:58 
QuestionCan DDX_Text be used with CTEXT resource item Pin
ForNow21-Apr-16 16:58
ForNow21-Apr-16 16:58 
QuestionRe: Can DDX_Text be used with CTEXT resource item Pin
Richard MacCutchan21-Apr-16 20:48
mveRichard MacCutchan21-Apr-16 20:48 
AnswerRe: Can DDX_Text be used with CTEXT resource item Pin
ForNow22-Apr-16 3:26
ForNow22-Apr-16 3:26 
AnswerRe: Can DDX_Text be used with CTEXT resource item Pin
Victor Nijegorodov22-Apr-16 0:39
Victor Nijegorodov22-Apr-16 0:39 
GeneralRe: Can DDX_Text be used with CTEXT resource item Pin
ForNow22-Apr-16 3:25
ForNow22-Apr-16 3:25 
Questioncode path for DoModal Pin
ForNow17-Apr-16 6:21
ForNow17-Apr-16 6:21 
AnswerRe: code path for DoModal Pin
Victor Nijegorodov17-Apr-16 6:58
Victor Nijegorodov17-Apr-16 6:58 
GeneralRe: code path for DoModal Pin
ForNow17-Apr-16 7:07
ForNow17-Apr-16 7:07 
GeneralRe: code path for DoModal Pin
leon de boer17-Apr-16 7:54
leon de boer17-Apr-16 7:54 
QuestionRe: code path for DoModal Pin
David Crow18-Apr-16 4:04
David Crow18-Apr-16 4:04 
AnswerRe: code path for DoModal Pin
leon de boer18-Apr-16 4:20
leon de boer18-Apr-16 4:20 
GeneralRe: code path for DoModal Pin
David Crow18-Apr-16 12:06
David Crow18-Apr-16 12:06 
QuestionWaitForSingleObject not signaled Pin
ForNow14-Apr-16 15:54
ForNow14-Apr-16 15:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.