1manik 0 Newbie Poster

Hi, I have two problems. I have this program:
But I dont know how can I do:

1 that I finish this program and save text to .txt by press of ENTER

2 that window, in which will be field to write text, will be illustrated in main window, but I want to write this text in moment when program will be started, so I must use WS_CLIPSIBLINGS

Thanks for advices.

#include "main.h"
#include "resource.h"

#define _MainClassName TEXT("WinAPIMainClass")
#define _AppName TEXT("Do")

FILE *cielovazlozka;
HINSTANCE g_hInstance;
HWND g_hwndMain;
HWND g_hwndButton1;
HWND g_hwndEdit;


LRESULT CALLBACK WindowProcMain(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	TCHAR chText[200];
	switch ( message )
	{
		case WM_CLOSE:
		if ( MessageBox(hwnd, TEXT("Really finish?"), _AppName,
				MB_YESNO | MB_ICONQUESTION) != IDYES )
				return 0; 

			break;
		case WM_COMMAND:
			if ( lParam == (LPARAM)g_hwndButton1 )
			{	
				cielovazlozka = fopen("idcislo.txt", "w");
				fprintf(cielovazlozka, "%i\t", chText);
				return 0;	
			}
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			break;
	}
return DefWindowProc(hwnd, message, wParam, lParam);
}

TCHAR ch[20];

BOOL InitApp()
{
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
	wc.hCursor = NULL;
	wc.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDR_MAIN));
	wc.hIconSm = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDR_MAIN));
	wc.hInstance = g_hInstance;
	wc.lpfnWndProc = WindowProcMain;
	wc.lpszClassName = _MainClassName;
//	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	if ( !RegisterClassEx(&wc) )
		return FALSE;

	g_hwndMain = CreateWindowEx(0, _MainClassName,
		_AppName,
		WS_OVERLAPPEDWINDOW | WS_VISIBLE,
		100, 100, 350, 250,
		NULL, 
		NULL,
		g_hInstance, NULL);
	if ( g_hwndMain == NULL )
		return FALSE;

// vytvoření dětských oken
	g_hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
		TEXT("EDIT"),
		TEXT(""),
		WS_CLIPSIBLINGS | WS_VISIBLE,
		10, 15, 200, 25,
		g_hwndMain,
		(HMENU)NULL,
		g_hInstance,
		NULL);
	if ( g_hwndEdit == NULL )
		return FALSE;

	g_hwndButton1 = CreateWindowEx(0,
		TEXT("BUTTON"),
		TEXT("Text"),
		WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
		10, 50, 75, 25,
		g_hwndMain,
		(HMENU)NULL,
		g_hInstance,
		NULL);
	if ( g_hwndButton1 == NULL )
		return FALSE;
	

	HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
	SendMessage(g_hwndEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);
	SendMessage(g_hwndButton1, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);


	return TRUE;
}

MSG msg;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShow)
{
	g_hInstance = hInstance;
	if ( !InitApp() )
		return FALSE;
	while ( GetMessage(&msg, NULL, 0, 0) )
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}