Passing character input from text-box to function

Im at college atm, second year and we are doing c++
On on the task to choose a program to make and complete within 4 weeks. and so far it been going well. But im stuck on this.
edit:
Its a till login screen. So im trying to get data

How do i pass the "ActualUsername" and "ActualPassword" to the getWnd function and get what the user actually entered.
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#if defined(UNICODE) && !defined(_UNICODE)
	#define _UNICODE
	#elif defined(_UNICODE) && !defined(UNICODE)
	#define UNICODE
	#endif

	#include <tchar.h>
	#include <windows.h>
	#include <string>
	#include "Main_Frame.cpp"
	#include <stdio.h>
	#include <io.h>
	#include <fcntl.h>


	/* This is the handle for our window */
	HWND hwnd; //Also shared between Source.cpp and Main_Frame.cpp. To be left global
			   /* This is the handle for our window */


			   //Declaring public variables
	HWND static_user; //static label (password)
	HWND static_p_word; //static label (password)
	HWND login_button, quit; //Buttons for loging in and quiting
	HWND input_P; //Actual text field input for password (_later will store in a string, only when user has entered)
	HWND input_US; //Actual text field inpur for user (same concept as the password


	char *ActualPassword[20];
	char *ActaulUsername[20];


	/*  Declare Windows procedure  */
	LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);

	/*  Make the class name into a global variable  */
	TCHAR szClassName[] = _T("MainFrame Application");
	INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

	int WINAPI WinMain(HINSTANCE hThisInstance,
		HINSTANCE hPrevInstance,
		LPSTR lpszArgument,
		int nCmdShow)
	{
		/*
		 * For debug purposes
		 *will be removed once done
		 */
		AllocConsole();

		HANDLE handle_out = GetStdHandle(STD_OUTPUT_HANDLE);
		int hCrt = _open_osfhandle((long)handle_out, _O_TEXT);
		FILE* hf_out = _fdopen(hCrt, "w");
		setvbuf(hf_out, NULL, _IONBF, 1);
		*stdout = *hf_out;

		HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
		hCrt = _open_osfhandle((long)handle_in, _O_TEXT);
		FILE* hf_in = _fdopen(hCrt, "r");
		setvbuf(hf_in, NULL, _IONBF, 128);
		*stdin = *hf_in;
		/*
		 * Concole end
		 */


		MSG messages;            /* Here messages to the application are saved */
		WNDCLASSEX wincl;        /* Data structure for the windowclass */

								 /* The Window structure */
		wincl.hInstance = hThisInstance;
		wincl.lpszClassName = szClassName;
		wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
		wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
		wincl.cbSize = sizeof(WNDCLASSEX);

		/* Use default icon and mouse-pointer */
		wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
		wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
		wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
		wincl.lpszMenuName = NULL;                 /* No menu */
		wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
		wincl.cbWndExtra = 0;                      /* structure or the window instance */
												   /* Use Windows's default colour as the background of the window */
		wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;

		/* Register the window class, and if it fails quit the program */
		RegisterClassEx(&wincl);

		/* The class is registered, let's create the program*/
		hwnd = CreateWindowEx(
			0,                   /* Extended possibilites for variation */
			szClassName,         /* Classname */
			_T("MainFrame Till"),       /* Title Text */
			WS_MINIMIZEBOX | WS_SYSMENU, /* default window */
			CW_USEDEFAULT,       /* Windows decides the position */
			CW_USEDEFAULT,       /* where the window ends up on the screen */
			490,                 /* The programs width */
			270,                 /* and height in pixels */
			HWND_DESKTOP,        /* The window is a child-window to desktop */
			NULL,                /* No menu */
			hThisInstance,       /* Program Instance handler */
			NULL                 /* No Window Creation data */
			);

		if (hwnd == 0)
		{
			MessageBox(0, "Failed to start", "Error 001", 0);
		}
		/* Make the window visible on the screen */
		ShowWindow(hwnd, nCmdShow);

		/* Run the message loop. It will run until GetMessage() returns 0 */
		while (GetMessage(&messages, NULL, 0, 0))
		{
			/* Translate virtual-key messages into character messages */
			TranslateMessage(&messages);
			/* Send message to WindowProcedure */
			DispatchMessage(&messages);
		}

		/* The program return-value is 0 - The value that PostQuitMessage() gave */
		return messages.wParam;
	}


	/*  This function is called by the Windows function DispatchMessage()  */


	LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		int gwtstat = 0;

		switch (message)                  /* handle the messages */
		{
		case WM_CREATE:
			/*
			* Creating all the log-in screen buttons and actions. Then will pass user input to a function afer user has pressed enter of "Login"
			*/

			//Static Username text
			static_user = CreateWindow("STATIC", "User Name", WS_VISIBLE | WS_CHILD, 20, 20, 100, 22, hwnd, NULL, NULL, NULL, NULL);

			//Static Password Text
			static_p_word = CreateWindow("STATIC", "Password", WS_VISIBLE | WS_CHILD, 20, 50, 100, 22, hwnd, NULL, NULL, NULL, NULL);

			//Username input.
			input_US = CreateWindow("EDIT", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 140, 20, 150, 22, hwnd, NULL, NULL, NULL, NULL);

			//Password input
			input_P = CreateWindow("EDIT", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 140, 50, 150, 22, hwnd, NULL, NULL, NULL, NULL);

			//Creating logging button
			login_button = CreateWindow("BUTTON", "Login", WS_VISIBLE | WS_CHILD | WS_BORDER, 140, 90, 95, 25, hwnd, (HMENU)1, NULL, NULL);

			//quit button
			quit = CreateWindow("BUTTON", "QUIT", WS_VISIBLE | WS_CHILD, 350, 150, 95, 25, hwnd, (HMENU)2, NULL, NULL);

			/*
			*Price enquiery processs
			*/
			HWND price; //Handle to window for asking for price
			HWND price_text; //edit windows where user enters item(s)

							 //static window.
			price = CreateWindow("STATIC", "Price enquiry", WS_VISIBLE | WS_CHILD, 50, 150, 95, 20, hwnd, NULL, NULL, NULL);

			//Actual textbox
			price_text = CreateWindow("EDIT", "02", WS_VISIBLE | WS_CHILD, 50, 190, 115, 25, hwnd, NULL, NULL, NULL);
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
			case 1:

				gwtstat = GetWindowText(input_US, ActaulUsername[0], 15); //Get the text input in username;

				gwtstat = GetWindowText(input_P, ActualPassword[0], 15); //pgets text input in password

				getWnd(*ActaulUsername, *ActualPassword);
				

				break;
			case 2:
				PostQuitMessage(0);
			}

			break;
		case WM_DESTROY:
			PostQuitMessage(0);       /* send a WM_QUIT to the message queue */
			break;
		default:                      /* for messages that we don't deal with */
			return DefWindowProc(hwnd, message, wParam, lParam);
		}

		return 0;
	}



function
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

#include "Main_Frame.h"
#include <tchar.h>
#include <iostream>
#include <sstream>
#include <Windows.h>
#include <stdlib.h>
/*
 * Sharing data from Source file
 */
extern HWND hwnd;

void getWnd(char *hah1, char *har2)
{
	if (har2 == "kevo")
	{
		::MessageBox(hwnd, hah1, har2, MB_OK);
		printf("success");
	}
	else
	{
		::MessageBox(hwnd, "ops", "ops", MB_OK);
		printf("%s \n", "A no Data passed(atleast known data");
	}
}

Last edited on
 
	if (har2 == "kevo")


You can't compare char* with == , you need to use strcmp or stricmp.

It also would be a good idea to output the parameters hah1 and har2 to the console to see what input you get. I also would use assert statements like.

1
2
3
4
void getWnd(char *hah1, char *har2)
{
  assert(hah1 != NULL);
 assert(hah2 != NULL);




Topic archived. No new replies allowed.