al final lo logre o casi todo todavía me queda un ultimo inconveniente, y es este, para mostrar el progreso del programa uso una wxgauge, hasta ahi todo bien, el problema surge cuando por algun motivo el formulario pierde el foco, al pasar eso el programa sigue y al terminar recupera el foco y todo anda bien, pero hasta que termina la barra de progreso deja de actualizar, es mas pienso que como se queda en los bucles mucho tiempo, impido que el programa procese los eventos y es eso lo que lleva a la falla, recuerdo que en visual basic se agregaba un comando que lo resolvia pero no me acuerdo como se llamaba, habra algun comando similar. aca les dejo el main del programa
/*************************************************************** * Name: exploradorMain.cpp * Purpose: Code for Application Frame * Author: () * Created: 2024-06-15 * Copyright: () * License: **************************************************************/
#include "exploradorMain.h" #include <wx/msgdlg.h> #include <wx/dir.h> #include <wx/file.h> #include <wx/volume.h> #include <Windowsx.h> #include <wx/msw/winundef.h> #include "cifrado.h" #include <string> #include <wx/msgdlg.h> #include <wx/filedlg.h> #include "mydialog.h" #include <ctime> #include "supercifrado.h"
//(*InternalHeaders(exploradorFrame) #include <wx/bitmap.h> #include <wx/font.h> #include <wx/icon.h> #include <wx/image.h> #include <wx/intl.h> #include <wx/settings.h> #include <wx/string.h> //*)
//helper functions enum wxbuildinfoformat { short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format) { wxString wxbuild(wxVERSION_STRING);
if (format == long_f ) { #if defined(__WXMSW__) wxbuild << _T("-Windows"); #elif defined(__UNIX__) wxbuild << _T("-Linux"); #endif
#if wxUSE_UNICODE wxbuild << _T("-Unicode build"); #else wxbuild << _T("-ANSI build"); #endif // wxUSE_UNICODE }
return wxbuild; }
//(*IdInit(exploradorFrame) const long exploradorFrame::ID_LISTBOX1 = wxNewId(); const long exploradorFrame::ID_COMBOBOX1 = wxNewId(); const long exploradorFrame::ID_GENERICDIRCTRL1 = wxNewId(); const long exploradorFrame::ID_STATICTEXT1 = wxNewId(); const long exploradorFrame::ID_GAUGE1 = wxNewId(); const long exploradorFrame::ID_PROGRESSDIALOG1 = wxNewId(); //*)
BEGIN_EVENT_TABLE(exploradorFrame,wxFrame) //(*EventTable(exploradorFrame) //*) END_EVENT_TABLE()
exploradorFrame::exploradorFrame(wxWindow* parent,wxWindowID id) { wxArrayString Lista; Lista = wxFSVolume::GetVolumes();
//(*Initialize(exploradorFrame) Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY")); SetClientSize(wxSize(600,320)); SetBackgroundColour(wxColour(0,128,192)); { wxIcon FrameIcon; FrameIcon.CopyFromBitmap(wxBitmap(wxImage(_T("C:\\Users\\tca15\\Downloads\\keys_security_private_lock_1739.ico")))); SetIcon(FrameIcon); } ListBox1 = new wxListBox(this, ID_LISTBOX1, wxPoint(260,40), wxSize(335,255), 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1")); wxFont ListBox1Font(10,wxFONTFAMILY_MODERN,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Terminal"),wxFONTENCODING_DEFAULT); ListBox1->SetFont(ListBox1Font); ComboBox1 = new wxComboBox(this, ID_COMBOBOX1, wxEmptyString, wxPoint(16,176), wxSize(192,32), 0, 0, wxCB_READONLY|wxTE_PROCESS_ENTER|wxBORDER_DOUBLE|wxBORDER_SUNKEN|wxBORDER_STATIC, wxDefaultValidator, _T("ID_COMBOBOX1")); ComboBox1->Hide(); wxFont ComboBox1Font(12,wxFONTFAMILY_MODERN,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Terminal"),wxFONTENCODING_DEFAULT); ComboBox1->SetFont(ComboBox1Font); DirCtrl1 = new wxGenericDirCtrl(this, ID_GENERICDIRCTRL1, wxEmptyString, wxPoint(5,40), wxSize(250,255), wxDIRCTRL_DIR_ONLY, wxEmptyString, 0, _T("ID_GENERICDIRCTRL1")); Statico = new wxStaticText(this, ID_STATICTEXT1, wxEmptyString, wxPoint(5,5), wxSize(590,30), wxBORDER_SIMPLE, _T("ID_STATICTEXT1")); Statico->SetForegroundColour(wxColour(255,0,128)); Statico->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); wxFont StaticoFont(14,wxFONTFAMILY_MODERN,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_BOLD,false,_T("Terminal"),wxFONTENCODING_DEFAULT); Statico->SetFont(StaticoFont); Gauge = new wxGauge(this, ID_GAUGE1, 100, wxPoint(5,300), wxSize(590,15), wxGA_HORIZONTAL|wxGA_SMOOTH|wxGA_PROGRESS, wxDefaultValidator, _T("ID_GAUGE1")); Gauge->Hide();
Connect(ID_GENERICDIRCTRL1,wxEVT_DIRCTRL_SELECTIONCHANGED,(wxObjectEventFunction)&exploradorFrame::OnGenericDirCtrl1SelectionChanged); //*) Connect(ID_LISTBOX1,wxEVT_LISTBOX_DCLICK,(wxObjectEventFunction)&exploradorFrame::OnListBox1DClick); DirCtrl1->ShowHidden(true); DirCtrl1->ExpandPath(wxGetCwd()); explorar(wxGetCwd()); }
exploradorFrame::~exploradorFrame() { //(*Destroy(exploradorFrame) //*) }
void exploradorFrame::explorar(wxString Ruta) { wxSetWorkingDirectory (Ruta); wxDir dir(wxGetCwd()); wxArrayString Lista; wxString filename; unsigned int i=0; bool cont; HWND hctrl = (HWND)ListBox1->GetHandle(); //de aca consigo el handler del listbox
SendMessageW(hctrl, LB_RESETCONTENT, 0, 0); // y enviando esto logro borrar el listbox if ( !dir.IsOpened() ) { Lista.Add("No Existe",1); ListBox1->InsertItems(Lista,0); dir.Close(); return; } Statico->SetLabel(dir.GetNameWithSep()); cont = dir.GetFirst(&filename, "", wxDIR_DIRS|wxDIR_DOTDOT); while ( cont ) { if(filename!=".") { Lista.Add(filename.MakeUpper()); i++; } cont = dir.GetNext(&filename); } cont = dir.GetFirst(&filename, "", wxDIR_FILES|wxDIR_HIDDEN); while ( cont ) { if(filename!=".") { Lista.Add(filename); i++; } cont = dir.GetNext(&filename); } ListBox1->InsertItems(Lista,0); dir.Close(); }
void exploradorFrame::OnClose(wxCommandEvent& event) { Destroy(); }
void exploradorFrame::OnListBox1DClick(wxCommandEvent& event) { wxDir dir; MyDialog Password(this,-1,_("Ingrese la Clave")); int Boton; if(!wxDirExists(ListBox1->GetString(ListBox1->GetSelection()))) { Boton = Password.ShowModal(); if(Boton != wxID_CANCEL) cifrar(Password.GetPassWord(), Boton); explorar(Statico->GetLabel()); } else { DirCtrl1->CollapseTree(); explorar(ListBox1->GetString(ListBox1->GetSelection())); DirCtrl1->ExpandPath(wxGetCwd()); } }
void exploradorFrame::cifrar(wxString Clave, int Boton) { SuperCifrado code; unsigned char TPlano[2048],Salida[2048]; wxString aux; wxFile plano, cifrado; std::string paso; unsigned long long bucle, resto, i; wxFileDialog saveFileDialog;
if(Boton == 9001 || Boton == 9003) saveFileDialog.Create(this, _ ( "Guardar archivo ngm" ), wxEmptyString, wxEmptyString, "Archivos ngm (*.ngm)|*.ngm", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if(Boton == 9002 || Boton == 9002) saveFileDialog.Create(this, _ ( "Guardar archivo" ), wxEmptyString, wxEmptyString, "Archivos (*.*)|*.*", wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if(saveFileDialog.ShowModal()== wxID_CANCEL) return;
aux=Statico->GetLabel() + ListBox1->GetString(ListBox1->GetSelection()); plano.Open(aux,wxFile::read);
if(!plano.IsOpened()) { wxMessageBox (_("No se puede abrir"),_("ERROR") , wxOK | wxCENTRE | wxICON_ERROR , this); return; }
if(!cifrado.Create(saveFileDialog.GetPath())) { wxMessageBox (_("No se puede crear"),_("ERROR") , wxOK | wxCENTRE | wxICON_ERROR , this); return; }
wxString p; paso=Clave; code.Init(paso); Gauge->Show(true);
resto = plano.Length() & 0x7ff; //lenght es un tipo longlong bucle = plano.Length() >> 11; Gauge->SetRange((int)bucle); DirCtrl1->Enable(false); DirCtrl1->Update();
int y0=clock(); switch (Boton) { case 9001: { for (i=0;i<bucle;i++) { plano.Read(TPlano,2048); code.DesOrden(TPlano); code.Codec(2048,TPlano,Salida); cifrado.Write(Salida,2048); Gauge->SetFocus(); Gauge->SetValue(i); } if(resto) { plano.Read(TPlano,resto); code.Codec(resto,TPlano,Salida); cifrado.Write(Salida,resto); } Gauge->Hide(); int y1=clock(); double t=(double(y1-y0)/CLOCKS_PER_SEC);
p.Printf("%f",t); wxMessageBox (_("rclick"), p, wxOK | wxCENTRE , this); DirCtrl1->Enable(true); plano.Close(); cifrado.Close(); return; } case 9002: { for (i=0;i<bucle;i++) { plano.Read(TPlano,2048); code.Codec(2048,TPlano,Salida); code.Orden(Salida); cifrado.Write(Salida,2048); Gauge->SetFocus(); Gauge->SetValue(i); } if(resto) { plano.Read(TPlano,resto); code.Codec(resto,TPlano,Salida); cifrado.Write(Salida,resto); } Gauge->Hide(); int y1=clock(); double t=(double(y1-y0)/CLOCKS_PER_SEC); wxString p; p.Printf("%f",t); wxMessageBox (_("rclick"), p, wxOK | wxCENTRE , this); DirCtrl1->Enable(true); plano.Close(); cifrado.Close(); return; } case 9003: { for (i=0;i<bucle;i++) { plano.Read(TPlano,2048); code.SuperDesOrden(TPlano,2048); code.Codec(2048,TPlano,Salida); cifrado.Write(Salida,2048); Gauge->SetFocus(); Gauge->SetValue(i); } if(resto) { plano.Read(TPlano,resto); code.Codec(resto,TPlano,Salida); cifrado.Write(Salida,resto); } Gauge->Hide(); int y1=clock(); double t=(double(y1-y0)/CLOCKS_PER_SEC); wxString p; p.Printf("%f",t); wxMessageBox (_("rclick"), p, wxOK | wxCENTRE , this); DirCtrl1->Enable(true); plano.Close(); cifrado.Close(); return; } case 9004: { for (i=0;i<bucle;i++) { plano.Read(TPlano,2048); code.Codec(2048,TPlano,Salida); code.SuperOrden(Salida,2048); cifrado.Write(Salida,2048); Gauge->SetFocus(); Gauge->SetValue(i); } if(resto) { plano.Read(TPlano,resto); code.Codec(resto,TPlano,Salida); cifrado.Write(Salida,resto); } Gauge->Hide(); int y1=clock(); double t=(double(y1-y0)/CLOCKS_PER_SEC); wxString p; p.Printf("%f",t); wxMessageBox (_("rclick"), p, wxOK | wxCENTRE , this); DirCtrl1->Enable(true); plano.Close(); cifrado.Close(); return; } } }
void exploradorFrame::OnGenericDirCtrl1SelectionChanged(wxTreeEvent& event) { wxString ruta;
ruta=DirCtrl1->GetPath(); if(!ruta.ends_with("\\")) ruta.append("\\"); explorar(ruta); }
|