Exemple #1
0
void DoFileSave(HWND hwnd)
{
	OPENFILENAME ofn;
	char szFileName[MAX_PATH] = "";

	ZeroMemory(&ofn, sizeof(ofn));

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = hwnd;
	ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
	ofn.lpstrFile = szFileName;
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrDefExt = "txt";
	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	if (GetSaveFileName(&ofn))
	{
		HWND hEdit = GetDlgItem(hwnd, IDC_CHILD_EDIT);
		if (SaveTextFileFromEdit(hEdit, szFileName))
		{
			SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)"Saved...");
			SendDlgItemMessage(g_hMainWindow, IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);

			SetWindowText(hwnd, szFileName);
		}
	}
}
ERRSAVE DoFileSave(MyEditor* ed)
{
  ERRSAVE didSave = ERRSAVE_NONE;
  OPENFILENAME ofn;
  char szFileName[MAX_PATH] = "";
  
  if( !ed )
    return didSave;

  ZeroMemory(&ofn, sizeof(ofn));

  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = ed->getWindow();
  ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
  ofn.lpstrFile = szFileName;
  ofn.nMaxFile = MAX_PATH;
  ofn.lpstrDefExt = "txt";
  ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

  if(GetSaveFileName(&ofn))
  {
    HWND hEdit = ed->getEditor();
    didSave = SaveTextFileFromEdit(hEdit, szFileName);
    if( didSave == ERRSAVE_NONE )
    {
      MyEditorHandlerWin* meh = (MyEditorHandlerWin*)MyEditorHandlerWin::getInstance();
      ed->setFile(szFileName);
    }
  }else
  {
    didSave = ERRSAVE_CANCEL;
  }

  return didSave;
}
Exemple #3
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static int ok = 0;
	static int nr_fis_intrare = 0;
	static int nr_fis_iesire = 0;

	switch (msg)
	{
	case WM_CREATE:
	{


					  //text static 1
					  HWND statik = CreateWindowEx(0,
						  "STATIC",
						  NULL,
						  WS_CHILD | WS_VISIBLE|SS_CENTER,
						  60, 10, 300, 200,
						  hwnd,
						  NULL,
						  NULL,
						  NULL);

					  SetWindowText(
						  statik,
						  "Introduceti textul pentru prelucrare!!"
						  );
					  //
					  //text static nr2
					  HWND statik2 = CreateWindowEx(0,
						  "STATIC",
						  NULL,
						  WS_CHILD | WS_VISIBLE|SS_CENTER,
						  60, 260, 300, 200,
						  hwnd,
						  NULL,
						  NULL,
						  NULL);

					  SetWindowText(
						  statik2,
						  "Arborele radix corespunzator este:"
						  );

					  //caseta text nr 1
					  HFONT hfDefault;
					  	  hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
						  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						  0, 40, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL);
					  if (hEdit == NULL)
						  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);

					  //caseta text nr 2
					  HFONT hfDefault2;
					  hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
						  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						  0, 280, 400, 200, hwnd, NULL, GetModuleHandle(NULL), NULL);
					  if (hEdit == NULL)
						  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
					  //caseta taext 3
					  HFONT hfDefault3;
					  hEdit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
						  WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
						  410, 350, 200, 100, hwnd, NULL, GetModuleHandle(NULL), NULL);
					  if (hEdit == NULL)
						  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);


					  //buton 1
					  CreateWindow("BUTTON",
						  "Afisare arbore",
						  WS_BORDER | WS_CHILD | WS_VISIBLE,
						  410, 300, 250, 50,
						  hwnd, (HMENU)Buton_Afisare, NULL, NULL);
					  //
					  //buton 2
					  CreateWindow("BUTTON",
						  "Apasati pentru a prelucra textul!",
						  WS_BORDER | WS_CHILD | WS_VISIBLE,
						  410, 50, 250, 50,
						  hwnd, (HMENU)Buton_prelucrare, NULL, NULL);
					  LoadTextFileToEdit(hEdit,"f.txt");
	}
		break;




	case WM_COMMAND:

		switch (LOWORD(wParam))
		{

		case ID_FILE_OPEN:
		{
							 OPENFILENAME ofn;
							 char szFileName[MAX_PATH] = "";

							 ZeroMemory(&ofn, sizeof(ofn));

							 ofn.lStructSize = sizeof(ofn); 
							 ofn.hwndOwner = hwnd;
							 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
							 ofn.lpstrFile = szFileName;
							 ofn.nMaxFile = MAX_PATH;
							 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
							 ofn.lpstrDefExt = "txt";

							 if (GetOpenFileName(&ofn))
							 {
								 // Do something usefull with the filename stored in szFileName
								 MessageBox(hwnd, szFileName, "Ati ales",
									 MB_OK | MB_ICONEXCLAMATION);
								static char text[100];

								LoadTextFileToEdit(hEdit, szFileName);
							 }

		}
			break;
		case ID_FILE_SAVE:
		{
							 int val=0;
							 val = GetWindowText(hEdit, &textSaved[0], 20000);
							 MessageBox(hwnd, textSaved, "Salvati urmatorul text:",
								 MB_OK | MB_ICONEXCLAMATION);

							 OPENFILENAME ofn;
							 char szFileName[MAX_PATH] = "";

							 ZeroMemory(&ofn, sizeof(ofn));

							 ofn.lStructSize = sizeof(ofn);
							 ofn.hwndOwner = hwnd;
							 ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
							 ofn.lpstrFile = szFileName;
							 ofn.nMaxFile = MAX_PATH;
							 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
							 ofn.lpstrDefExt = "txt";

							 if (GetOpenFileName(&ofn))
							 {
								 // Do something usefull with the filename stored in szFileName
								 MessageBox(hwnd, szFileName, "Text Salvat in:",
									 MB_OK | MB_ICONEXCLAMATION);
								
							 }
							 SaveTextFileFromEdit(hEdit, szFileName);

		}
			break;

		case ID_START:
		{	
		
		}
			break;
		case Buton_prelucrare:
		{
								 int k = 1;
								 SetWindowText(hEdit2, "");
								 if (SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0) == 0) // then field is empty
								 {
									 MessageBox(hwnd, "Nu ati introdus text!", "Atentionare!",
										 MB_OK | MB_ICONERROR);
									 SetWindowText(hEdit3, "");   //golire textbox3
									 FILE*f = fopen("f.txt", "wt");

									 fputs("Introduceti text!", f);
									 LoadTextFileToEdit(hEdit, "fis.txt");
									 fclose(f);
								 }
								 else
								 {
									 SaveTextFileFromEdit(hEdit, "fis.txt");
									 char cuv[100];
									 inserare(rad, '*');
									 FILE*fis = fopen("fis.txt", "rt");
									 FILE*fis2;
									 while (!feof(fis))
									 {
										 fscanf(fis, "%s", cuv);
										 functie(cuv, rad);
									 }
									 fseek(fis, 0, 0);

									 nr_fis_intrare = nr_caractere(fis);

									 fclose(fis);
									 fis2 = fopen("f.txt", "wt");
									 afisare(fis2, 0, rad);
									 fclose(fis2);
									 fis2 = fopen("f.txt", "rt");
									 fseek(fis, 0, 0);
									 nr_fis_iesire = nr_caractere(fis2); 
									 fclose(fis2);
									 stergere(rad);

									 rad = NULL;
									 ok = 1;
									 MessageBox(hwnd, "Textul a fost prelucrat cu succes!", "Atentionare!",
										 MB_OK | MB_ICONINFORMATION);
								 }
		}
			break;
		case Buton_Afisare:
		{
							  if (ok == 1)
							  {
								  ok = 0;
								  MessageBox(hwnd, "Textul a fost transformat cu succes!!", "Atentionare!",
									  MB_OK | MB_ICONINFORMATION);
								  LoadTextFileToEdit(hEdit2, "f.txt");   //
								
								  FILE*fis = fopen("f.txt", "wt");
								  fprintf(fis, "Numar initial:%d\n", nr_fis_intrare);
								  fprintf(fis, "Numar comprimat:%d\n", nr_fis_iesire);
								  int x = 100 - ((nr_fis_iesire*100/nr_fis_intrare));
								  fprintf(fis, "Procentul de eficienta: %d", x);
								  fprintf(fis,"%c", '%');

								  fclose(fis);
								 LoadTextFileToEdit(hEdit3,"f.txt");

								 fis = fopen("f.txt", "wt");
								 fclose(fis);
								
							  }
							  else
							  {
								  MessageBox(hwnd, "Textul nu a fost prelucrat anterior!!", "Atentionare!",
									  MB_OK | MB_ICONSTOP);
								  SetWindowText(hEdit3, "");
							  }
							  FILE*fis = fopen("f.txt", "wt");
							  fputs("Introduceti text!", fis);
							  LoadTextFileToEdit(hEdit, "fis.txt");
							  fclose(fis);

							  fis = fopen("fis.txt", "wt");
							  fclose(fis);
		}
			break;
		case ID_CLEAR:
		{
						 SetWindowText(hEdit,"");
						 SetWindowText(hEdit2, "");
						 SetWindowText(hEdit3, "");
		}
			break;
		}
		break;
	
	case WM_SIZE:
	{
					HWND hEdit;
					RECT rcClient;
					GetClientRect(hwnd, &rcClient);
					hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
					SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER);
	}
		break;


	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}