Test Foro de elhacker.net SMF 2.1

Programación => Programación C/C++ => Mensaje iniciado por: Bob1098 en 11 Septiembre 2015, 19:54 PM

Título: Mas problemas con Win32
Publicado por: Bob1098 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 (cpp) [Seleccionar]

#include <Windows.h>

namespace Win32
{
class Window
{
public:
HWND hWnd;

Window();

bool center();

void create(int height, int width, int x, int y,
DWORD dwStyle, HBRUSH color, HCURSOR cursor, HICON icon, HINSTANCE hInstance, HWND hwnd, HWND hwndParent,
LPCWSTR CLASS_NAME, LPCWSTR menu, LPCWSTR windowName, WNDPROC winProc);
void show(int nCmdShow);

};
}


Win32Lib.cpp

Código (cpp) [Seleccionar]

#include "Win32Lib.h"

namespace Win32
{
Window::Window() {};

bool Window::center()
{
int x, y;
RECT rc;

GetWindowRect(hWnd, &rc);
x = (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2;
y = (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2;

return SetWindowPos(hWnd, 0, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}

void Window::create(int height, int width, int x, int y,
DWORD dwStyle, HBRUSH color, HCURSOR cursor, HICON icon, HINSTANCE hInstance, HWND hwnd, HWND hwndParent,
LPCWSTR CLASS_NAME, LPCWSTR menu, LPCWSTR windowName, WNDPROC winProc)
{
WNDCLASS wc;

hWnd = hwnd;
wc.hbrBackground = color;
wc.hCursor = cursor;
wc.hIcon = icon;
wc.hInstance = hInstance;
wc.lpfnWndProc = winProc;
wc.lpszClassName = CLASS_NAME;
wc.lpszMenuName = menu;
RegisterClass(&wc);

hwnd = CreateWindowEx(0, CLASS_NAME, windowName, dwStyle, x, y, width, height, hwndParent, NULL, hInstance, NULL);
}

void Window::show(int nCmdShow)
{
ShowWindow(hWnd, nCmdShow);
}
}


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 (cpp) [Seleccionar]

#ifndef UNICODE
#define UNICODE
#endif

#include <Windows.h>
#include <Win32Lib.h>

using namespace Win32;

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
HWND hwnd = NULL;
LPCWSTR CLASS_NAME = L"MainWindow";
Window mainWindow = new Window();

MSG msg = {};

mainWindow.show(nCmdShow);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

return DefWindowProc(hwnd, uMsg, wParam, lParam);
}



A que se puede deber? =S
Título: Re: Mas problemas con Win32
Publicado por: ivancea96 en 11 Septiembre 2015, 20:51 PM
Código (cpp) [Seleccionar]
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 (cpp) [Seleccionar]
Window mainWindow();
O
Código (cpp) [Seleccionar]
Window* mainWindow = new Window();
Título: Re: Mas problemas con Win32
Publicado por: Bob1098 en 11 Septiembre 2015, 22:04 PM
Oh gracias, que fallo mas tonto  :rolleyes: