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


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Mas problemas con Win32
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Mas problemas con Win32  (Leído 1,449 veces)
Bob1098

Desconectado Desconectado

Mensajes: 87


Ver Perfil
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


En línea

ivancea96


Desconectado Desconectado

Mensajes: 3.412


ASMático


Ver Perfil WWW
Re: Mas problemas con Win32
« Respuesta #1 en: 11 Septiembre 2015, 20:51 pm »

Código
  1. Window mainWindow = new Window();

En C# y Java sí, pero en C++ esto no es así. "new" devuelve una dirección de memoria (Window*). Un Window* solo se le puede asignar a un Window*.

Código
  1. Window mainWindow();
O
Código
  1. Window* mainWindow = new Window();


En línea

Bob1098

Desconectado Desconectado

Mensajes: 87


Ver Perfil
Re: Mas problemas con Win32
« Respuesta #2 en: 11 Septiembre 2015, 22:04 pm »

Oh gracias, que fallo mas tonto  :rolleyes:
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Win32 PE Unknown
Ingeniería Inversa
dragonballz 8 3,909 Último mensaje 13 Noviembre 2003, 09:13 am
por byebye
Ayuda win32.beginupdateresource(), win32.updateresource(), no funciona.
.NET (C#, VB.NET, ASP)
krosty123 2 3,624 Último mensaje 6 Noviembre 2010, 04:10 am
por krosty123
Win32 en ada.
Programación General
m0rf 0 1,396 Último mensaje 30 Mayo 2012, 17:55 pm
por m0rf
Libros de Win32 API en C/C++
Programación C/C++
Locura_23 2 2,640 Último mensaje 26 Agosto 2021, 21:36 pm
por Locura_23
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines