elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: 1 [2] 3 4 5 6 7 8 9
11  Programación / Java / Interfaces en Java en: 6 Enero 2016, 23:45 pm
Hola, me preguntaba cual es el uso real y práctico de las interfaces en java, es decir, únicamente se utilizan para hacer una "esquemilla" de las clases en java?. No comprendo el sentido que tienen, no es más rápido y cómodo definir los métodos directamente en la clase en lugar de declararlos (no definirlos) previamente en una interfaz?

Espero que alguien pudiera resolverme esta dudilla tonta.

Un saludo.
12  Programación / Programación C/C++ / Re: Mas problemas con Win32 en: 11 Septiembre 2015, 22:04 pm
Oh gracias, que fallo mas tonto  :rolleyes:
13  Programación / Programación C/C++ / Mas problemas con Win32 en: 11 Septiembre 2015, 19:54 pm
Bueno, siento ser tan pesado con este tema pero es que ahora no se que me falla...

He hecho una librería con una clase para agilizar el proceso de creación de la ventana, aquí dejo los códigos:

Win32Lib.h
Código
  1. #include <Windows.h>
  2.  
  3. namespace Win32
  4. {
  5. class Window
  6. {
  7. public:
  8. HWND hWnd;
  9.  
  10. Window();
  11.  
  12. bool center();
  13.  
  14. void create(int height, int width, int x, int y,
  15. DWORD dwStyle, HBRUSH color, HCURSOR cursor, HICON icon, HINSTANCE hInstance, HWND hwnd, HWND hwndParent,
  16. LPCWSTR CLASS_NAME, LPCWSTR menu, LPCWSTR windowName, WNDPROC winProc);
  17. void show(int nCmdShow);
  18.  
  19. };
  20. }
  21.  

Win32Lib.cpp

Código
  1. #include "Win32Lib.h"
  2.  
  3. namespace Win32
  4. {
  5. Window::Window() {};
  6.  
  7. bool Window::center()
  8. {
  9. int x, y;
  10. RECT rc;
  11.  
  12. GetWindowRect(hWnd, &rc);
  13. x = (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2;
  14. y = (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2;
  15.  
  16. return SetWindowPos(hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  17. }
  18.  
  19. void Window::create(int height, int width, int x, int y,
  20. DWORD dwStyle, HBRUSH color, HCURSOR cursor, HICON icon, HINSTANCE hInstance, HWND hwnd, HWND hwndParent,
  21. LPCWSTR CLASS_NAME, LPCWSTR menu, LPCWSTR windowName, WNDPROC winProc)
  22. {
  23. WNDCLASS wc;
  24.  
  25. hWnd = hwnd;
  26. wc.hbrBackground = color;
  27. wc.hCursor = cursor;
  28. wc.hIcon = icon;
  29. wc.hInstance = hInstance;
  30. wc.lpfnWndProc = winProc;
  31. wc.lpszClassName = CLASS_NAME;
  32. wc.lpszMenuName = menu;
  33. RegisterClass(&wc);
  34.  
  35. hwnd = CreateWindowEx(0, CLASS_NAME, windowName, dwStyle, x, y, width, height, hwndParent, NULL, hInstance, NULL);
  36. }
  37.  
  38. void Window::show(int nCmdShow)
  39. {
  40. ShowWindow(hWnd, nCmdShow);
  41. }
  42. }
  43.  

Y bueno, aquí esta el código de la aplicación, el caso es que en cuanto declaro la clase con un constructor vacio me dice: "Error (activo) no existe ningún constructor adecuado para convertir de "Win32::Window *" a "Win32::Window"   Win32Testing   d:\Documentos\Programacion\C++\Proyectos\Win32Testing\Win32Testing\Main.cpp   19"

Código
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4.  
  5. #include <Windows.h>
  6. #include <Win32Lib.h>
  7.  
  8. using namespace Win32;
  9.  
  10. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  11.  
  12. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
  13. {
  14. HWND hwnd = NULL;
  15. LPCWSTR CLASS_NAME = L"MainWindow";
  16. Window mainWindow = new Window();
  17.  
  18. MSG msg = {};
  19.  
  20. mainWindow.show(nCmdShow);
  21.  
  22. while (GetMessage(&msg, NULL, 0, 0))
  23. {
  24. TranslateMessage(&msg);
  25. DispatchMessage(&msg);
  26. }
  27. return 0;
  28. }
  29.  
  30. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  31. {
  32. switch (uMsg)
  33. {
  34. case WM_DESTROY:
  35. PostQuitMessage(0);
  36. return 0;
  37. }
  38.  
  39. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  40. }
  41.  
  42.  

A que se puede deber? =S
14  Programación / Programación C/C++ / Re: [DUDA] Manejo de varias ventanas Win32 en: 11 Septiembre 2015, 13:10 pm
Si, creo que más o menos era eso jajaja. Gracias por las respuestas.

Un saludo.
15  Programación / Programación C/C++ / Re: [DUDA] Manejo de varias ventanas Win32 en: 11 Septiembre 2015, 02:31 am
Bien una duda menos jajajajja y otra cosilla.
Si en el WindowProc de la ventana principal quiero utilizar la funcion ShowWindow, de donde saco el hwnd? Deberia declararlo como funcion global? Esque como parametro no puedo pasarlo...
16  Programación / Programación C/C++ / Re: [DUDA] Manejo de varias ventanas Win32 en: 10 Septiembre 2015, 23:40 pm
Si, algo de eso sabía pero como podría crear la ventana secundaria accesible a través del menu? Y en CreateWindowEx tendri que darle el valor la ventana principal en lugar de NULL?
17  Programación / Programación C/C++ / [DUDA] Manejo de varias ventanas Win32 en: 10 Septiembre 2015, 22:55 pm
Buenas, mi duda consiste en como puedo crear varias ventanas utilizando la API de windows. Por ejemplo, creo las dos ventanas, y una llama a la otra desde un menu. He intentado hacer algo pero ni si quiera compila (si compila, pero en realidad no me compila nada por lo que no se cual es error...). Agradecería muchísimo que alguien "veterano" en el tema me pueda ayudar...

Código
  1. // Main File
  2. // Build Date: 10-09-2015
  3.  
  4. #ifndef UNICODE
  5. #define UNICODE
  6. #endif
  7.  
  8. #include <Windows.h>
  9.  
  10. LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM);
  11. LRESULT CALLBACK ParentWindowProc(HWND, UINT, WPARAM, LPARAM);
  12.  
  13. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
  14. {
  15. const wchar_t MAIN_CLASS_NAME[] = L"MainWindow";
  16. const wchar_t PARENT_CLASS_NAME[] = L"ParentWindow";
  17. HWND mainHwnd, parentHwnd;
  18. WNDCLASS mainWc = {}, parentWc = {};
  19. MSG msg = {};
  20.  
  21. //MainHwnd
  22. mainWc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  23. mainWc.hInstance = hInstance;
  24. mainWc.lpfnWndProc = MainWindowProc;
  25. mainWc.lpszClassName = MAIN_CLASS_NAME;
  26. RegisterClass(&mainWc);
  27.  
  28. mainHwnd = CreateWindowEx(0, MAIN_CLASS_NAME, L"Ventana principal", WS_OVERLAPPEDWINDOW, 100, 100, 800, 600, NULL, NULL, hInstance, NULL);
  29. if (!mainHwnd) return 1;
  30. //ParentHwnd
  31. parentWc.hbrBackground = (HBRUSH)COLOR_WINDOWTEXT;
  32. parentWc.hInstance = hInstance;
  33. parentWc.lpfnWndProc = ParentWindowProc;
  34. parentWc.lpszClassName = PARENT_CLASS_NAME;
  35. RegisterClass(&parentWc);
  36.  
  37. parentHwnd = CreateWindowEx(0, PARENT_CLASS_NAME, L"Ventana secundaria", WS_OVERLAPPEDWINDOW, 300, 300, 800, 600, NULL, NULL, hInstance, NULL);
  38. if (!parentHwnd) return 2;
  39.  
  40. ShowWindow(mainHwnd, nCmdShow);
  41.  
  42. while (GetMessage(&msg, NULL, 0, 0))
  43. {
  44. TranslateMessage(&msg);
  45. DispatchMessage(&msg);
  46. }
  47.  
  48. return 0;
  49. }
  50.  
  51. LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  52. {
  53. switch (uMsg)
  54. {
  55. case WM_DESTROY:
  56. PostQuitMessage(0);
  57.  
  58. return 0;
  59. }
  60.  
  61. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  62. }
  63.  
  64. LRESULT CALLBACK ParentWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  65. {
  66. switch (uMsg)
  67. {
  68. case WM_DESTROY:
  69. PostQuitMessage(0);
  70.  
  71. return 0;
  72. }
  73.  
  74. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  75. }
  76.  

Si compilo esto me pone "Compilación correcta" en VS 2015 pero luego no me encuentra el archivo ejecutable lo que indica que no se compiló...

Un saludo y gracias de antemano.
18  Programación / Programación C/C++ / Re: Cambiar de String a natural en: 8 Septiembre 2015, 23:20 pm
Bueno, puedes crear tu propia función para comprobar si es digito o no, comprobando si el carácter es '1', '2'.. etc. Y para la conversion vas a tener que currártelo un poco mas. Puedes guardar los valores en array de int.

Un saludo.
19  Programación / Programación C/C++ / Re: Cambiar de String a natural en: 8 Septiembre 2015, 20:58 pm
Una idea que puedo darte sería comprobar si el carácter siguiente al que te encuentras (i+1) es un digito o no con la función isdigit() de ctype. Si no lo es, los caracteres que lleves contados los guardas y los conviertes en decimal utilizando funciones como atoi().

Espero que te haya ayudado.
20  Programación / Programación C/C++ / Re: Vectores (Array) de N posiciones C++ en: 7 Septiembre 2015, 18:52 pm
Además de lo ya dicho me parece que si la variable resultado no tiene un valor inicial asignado no funcionara como contador. Si te diese problemas dale un valor inicial de 0, si te funciona bien no hay problema.


Un saludo.
Páginas: 1 [2] 3 4 5 6 7 8 9
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines