#include <windows.h>
#include "Resource.h"

HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_Main), hWnd, reinterpret_cast<DLGPROC>(DlgProc));
	return FALSE;
}

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_INITDIALOG:
		return TRUE;

	case WM_COMMAND:
		HWND edit = GetDlgItem(hWndDlg,IDC_Window);
		HWND input = GetDlgItem(hWndDlg,IDC_Input);
		HWND inputB = GetDlgItem(hWndDlg,(GetWindowText(input,NULL,NULL)));
		switch(wParam)
		{
			case ID_Close:
				EndDialog(hWndDlg, 0);
				return TRUE;
			case IDC_Submit:
				SetWindowText(edit,(const char *)inputB);
				return TRUE;
		}
		break;
	}

	return FALSE;
}

no error but it doesnt take the text from IDC_Input and display it in IDC_Window when i pressed the IDC_Submit button.

im just starting Gui's so bare with me :(

You probably guessed this but its using DialogBox Resources and what not but im guessing you can see that already,

I have to ask you, what is the following line supposed to do? HWND inputB = GetDlgItem(hWndDlg,(GetWindowText(input,NULL,NULL))); The following will not work, 'inputB' is a window handle, not a pointer to a char array. SetWindowText(edit,(const char *)inputB); You need ...

char text[SOME_SIZE] = {0};
// ... code that sets the content of text[] ...
// try setting the edit control's text
if(FALSE == SetWindowText(edit, text))
{
    // error ...
}

well i was trying to get the buffer or text in the Input box and then when the button Submit is pressed it displays it into the Output window.

well i was trying to get the buffer or text in the Input box and then when the button Submit is pressed it displays it into the Output window.

Maybe you can devise something out of the following ...

switch(wParam)
{
	...

	case IDC_Submit:
	{
		#define MAXTEXT 1024
		char text[MAXTEXT] = {0};		  

		// try getting the needed window handles
		HWND input	= GetDlgItem(hWndDlg,IDC_Input);
		HWND edit	= GetDlgItem(hWndDlg,IDC_Window);

		if(input && edit)
		{
			// try getting the text of the IDC_Input control
			if(GetWindowText(input, text, MAXTEXT))
			{
				// try setting the text of the 
                                // IDC_Window control
				if(FALSE == SetWindowText(edit,text))
				{
					// error
				}
			}
			else
			{
				// error or no text avail
			}
		}
		else
		{
			// error
		}
	}		
	return TRUE;		
}
break;
This article has been dead for over six months. Start a new discussion instead.