|
73
|
Programación / Programación C/C++ / Re: ingresar char
|
en: 7 Abril 2012, 20:45 pm
|
claro es cierto, si tu programa tiene un sólo hilo por así decirlo, no puede hacer más de una cosa al mismo tiempo, osea es secuencial. si necesitás esperar a que se ingrese algo entonces tu programa se detiene a esperar.
en cambio si agregás más hilos, podés hacer cosas simultáneamente en cada hilo.
CreateThread es la función que necesitás. no te confundás con CreateRemoteThread que tiene una funcionalidad extra, aunque puede servirte también si le pasás el primer parámetro el handle de tu proceso.
|
|
|
74
|
Programación / Programación C/C++ / Re: ayuda con este codigo
|
en: 7 Abril 2012, 20:40 pm
|
yo te lo optimizo aún más sin decir "dulces lunas" weee XD mejor dicho, otra propuesta de como hacerlo #include<stdio.h> int main(){ int a,b,c; while(true){ a=0; printf("Dame el nuemro de contenedores: "); scanf("%d", &a); if(a>0)break; } while(true){ b=0; printf("Dame los litros del contenedor: "); scanf("%d",&b); if(b>0)break; } while(true){ c=0; printf("Dame el número de casas: "); scanf("%d",&c); if(c>0)break; }
printf( "La cantidad de litros por casa es %f\n", (float)((a*b)/c) ); while(getchar()!='\n'); return 0; }
|
|
|
77
|
Programación / Programación C/C++ / Re: Programacion c++
|
en: 7 Abril 2012, 19:39 pm
|
para no estar haciendo continuamente PI/180 mejor pongan 0.17 que es constante tmb, aunque sin demasiada precisión algo así #define PI 3.1415 #define pisobre180 0.17
para no tener que estar haciendo una divisón continuamente cada vez que se usa 0.17 EDIT: quise poner
|
|
|
78
|
Programación / Programación C/C++ / Re: Duda funcion incrementar
|
en: 7 Abril 2012, 19:34 pm
|
otra forma, también comprueba que sea una cadena terminada en 0 bool incrementar(const char *pv) { if(pv[9]!=0)return false; for(unsigned int i=0; (pv[i]>='0'&&pv[i]<='9');i++); if(i<9)return false; char *d; long n = strtol(pv,&d,10); while(n<999999999)n++; char *x; x=ltoa(n,d,10); printf("%s\n",x); return true; }
int main() { char n[]={ '1','2','3','4','5','6','7','8','9',0 }; incrementar(n); cin.get(); return 0; }
|
|
|
79
|
Programación / Programación C/C++ / Re: atoi + itoa personalizadas
|
en: 7 Abril 2012, 10:40 am
|
muy bueno XD ahora que veo que pusiste la opción para números negativos, yo solamente estaba preocupado por los binarios para un convertidor a binario. en otro momento voy a hacer lo de los negativos porque estaría bueno que ingreses un entero negativo y lo convierta a string con signo y todo
|
|
|
80
|
Programación / Programación C/C++ / Ejemplo WinApi32 GUI - conversor decimal a binario
|
en: 7 Abril 2012, 06:45 am
|
Hola, estaba probando mis funciones atol e ltoa personalizadas, y las puse a prueba con un programa win32 con GUI que es un convertidor básico de decimal a binario y viceversa. Voy a dejar el código del proyecto en MSVC++ 6.0 que incluye el .h con las funciones que dije. Proyectoy dejo el winmain.cpp a la vista para notar los cambios con mi anterior publicación para winapi32 GUI //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// // UTN FRGP // 2012 // David Riedel // EMAIL: david_bs@live.com //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#define WINVER 0x0500 //WINVER as 0x0500 enables features specific to Win 98 and 2000 //#define VC_EXTRALEAN
#include <windows.h> #include <stdio.h> //gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
#include "ansii_conversions.h" #include "convertir.h"
///////////////////////// // Globales
HWND EditControl1; //HWND EditControl2; //HWND EditControl3; HWND ListControl1; HWND ListControl2; HWND StaticControl1; HWND CheckBoxControl1; HWND CheckBoxControl2;
const int ID_EDIT1=1, ID_LIST1=2, ID_CHECK1=3, ID_CHECK2=4; const int ID_OK = 6; const int ID_CANCEL = 7; const int ID_LABEL1 = 0;
/////////////////////////////
void getCentradoGlobal(int vXY[2], int h, int w);
/////////////// // Controles de ventana
void RegistrarControlesDeVentanaPrincipal(HWND hWin) { static char* t1 = TEXT("Ingrese 1 número"); unsigned long EstiloHijo1 = WS_VISIBLE | WS_CHILD; unsigned long EstiloHijo2 = WS_CHILD | WS_VISIBLE | WS_BORDER; unsigned long EstiloHijo3 = WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON; unsigned long EstiloHijo4 = WS_CHILD | WS_VISIBLE | LBS_NOTIFY | LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP;
unsigned long editstyle =WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP; unsigned long liststyle =WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP| LBS_NOTIFY;
int offs = 30; int X=20; int Y=10; int W=200; int H=25;
StaticControl1 = CreateWindow( TEXT("static"), t1, EstiloHijo1, 20,10,180,20, hWin, (HMENU)ID_LABEL1, NULL, NULL);
EditControl1 = CreateWindow( TEXT("Edit"), NULL, editstyle, X, Y+20, W+63, H, hWin, (HMENU)ID_EDIT1, NULL, NULL);
ListControl1 = CreateWindow( TEXT("listbox"), NULL, liststyle, X, Y+20+(offs*1), W+63, H-5, hWin, (HMENU)ID_LIST1, NULL, NULL);
CheckBoxControl1 = CreateWindow( TEXT("button"), "BinToDec", WS_VISIBLE | WS_CHILD | BS_CHECKBOX |BS_AUTOCHECKBOX, X+160,90,84,20, hWin, (HMENU)ID_CHECK1, NULL, NULL);
CreateWindow( TEXT("button"), TEXT("Convertir"), EstiloHijo1, X,90,80,H, hWin, (HMENU) ID_OK, NULL, NULL);
CreateWindow( TEXT("button"), TEXT("Salir"), EstiloHijo1, X+100,90,50,H, hWin, (HMENU)ID_CANCEL, NULL, NULL); }
////////// // CallBack
INT_PTR CALLBACK WinProc(HWND hWin, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CREATE: { RegistrarControlesDeVentanaPrincipal(hWin);
SetFocus(EditControl1); } break;
case WM_COMMAND: { switch(LOWORD(wParam)) { case ID_OK: { char chBuffer1[128]; memset(chBuffer1,0,sizeof(chBuffer1)); GetDlgItemText( hWin,ID_EDIT1, chBuffer1, sizeof( chBuffer1 ) ); BOOL checked = IsDlgButtonChecked(hWin, ID_CHECK1); int l=strlen(chBuffer1); if( (checked&&!EsBin(chBuffer1)) || (!checked&&!EsDec(chBuffer1))) { MessageBox(0,"Errores de ingreso!","Convertidor",0); return FALSE; } if(l<1){ MessageBox(0,"Ingrese algo!","Convertidor",0); return FALSE; } long l_res_pre; l_res_pre = mi_atoi(chBuffer1); long l_res; if(!checked) l_res = Bin(l_res_pre,2,10);//dec a bin else l_res = Bin(l_res_pre,10,2);//bin a dec char* ch_res = mi_ltoa(l_res,ch_res); SendDlgItemMessage(hWin, ID_LIST1, LB_RESETCONTENT, 0, 0); int nNum=0; char* buf1 = (char*)GlobalAlloc(GPTR,strlen(ch_res)+1); strcpy(buf1, ch_res); free(ch_res); int index1 = SendDlgItemMessage(hWin, ID_LIST1, LB_ADDSTRING, 0, (LPARAM)buf1); SendDlgItemMessage(hWin, ID_LIST1, LB_SETITEMDATA, (WPARAM)index1, (LPARAM)nNum); GlobalFree((HANDLE)buf1); } break;
case ID_CANCEL: { SendMessage(hWin, WM_CLOSE, 0, 0); return TRUE; } break; } } break;
case WM_CLOSE: { DestroyWindow(hWin); return TRUE; } ///////////////////////////// case WM_DESTROY: { PostQuitMessage(0); return TRUE; }
default: return DefWindowProc(hWin,uMsg,wParam,lParam);
}
return 0; //return DefWindowProc(hWin,uMsg,wParam,lParam); }
//////////// // Clase de ventana
void RegistrarClaseVentana(WNDCLASS* wc) { // HICON hIconImg = (HICON)LoadImage(NULL, "BS.ico", IMAGE_ICON, 542, 449, LR_LOADFROMFILE); wc->lpszClassName = TEXT("Window"); wc->hInstance = GetModuleHandle(NULL); //wc->hbrBackground = GetSysColorBrush(COLOR_3DFACE); wc->hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wc->lpfnWndProc = (WNDPROC)WinProc; wc->style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc->cbClsExtra = 0; wc->cbWndExtra = 0; wc->hIcon = LoadIcon(NULL,"IDI_ICON1"); // wc->hIcon = LoadIcon(NULL,"IDI_WINLOGO"); wc->hCursor = LoadCursor(NULL,IDC_ARROW); wc->lpszMenuName = NULL; RegisterClass((struct tagWNDCLASSA *)wc); }
////////////// // Punto de entrada ('WinMain' : must be '__stdcall')
int mb=0; int WINAPI WinMain(HINSTANCE hInst, HINSTANCE h0, LPSTR lpCmdLine, int nCmdShow){
HWND hWin; WNDCLASS wc = {0};
RegistrarClaseVentana(&wc);
int ancho=300; int alto=156; int dim[2]; getCentradoGlobal(dim, ancho, alto);
unsigned long Estilo1 = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
hWin = CreateWindow( wc.lpszClassName, "Convertidor a Binario", Estilo1, dim[0], dim[1], ancho, alto, NULL, NULL, hInst, NULL);
// ShowWindow(hWin,nCmdShow); ShowWindow(hWin, SW_SHOWDEFAULT);
//UpdateWindow(hWin);
MSG msg; while(GetMessage(&msg, NULL, 0, 0)>0) { if(!mb) { MessageBox(hWin, "By BS","Convertidor a Binario",MB_OK); mb=1; } if (!IsDialogMessage(hWin, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg);
} }
return msg.wParam; }
//===
void getCentradoGlobal(int vXY[2], int h, int w) { RECT rcP; GetWindowRect(GetDesktopWindow(), &rcP); int centerX = (rcP.right/2)-(w/2)-(w/4); int centerY = (rcP.bottom/2)-(h/2)+(h/6); vXY[0]=centerX; vXY[1]=centerY; }
//===
Prueben el convertidor XD aver si anda bien. La meta es hacerlo un convertidor de otros sistemas también, por ejemplo hexadecimal y octal. pero como se trata de algo didáctico para mi, me da lo mismo por cierto la función conversora es esta, creo que en google aparece enseguida.. unsigned long Bin(unsigned long n1,int base1,int base2) { unsigned long alg,mult=1,n2=0; while(n1 > 0) { alg = n1 % base1; n1 /= base1; n2 += (alg*mult); mult *= base2; } return n2; }
Salu2
|
|
|
|
|
|
|