|
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.
|
|
|
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 #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 #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" #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
|
|
|
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... // Main File // Build Date: 10-09-2015 #ifndef UNICODE #define UNICODE #endif #include <Windows.h> LRESULT CALLBACK MainWindowProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ParentWindowProc(HWND, UINT, WPARAM, LPARAM); int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) { const wchar_t MAIN_CLASS_NAME[] = L"MainWindow"; const wchar_t PARENT_CLASS_NAME[] = L"ParentWindow"; HWND mainHwnd, parentHwnd; WNDCLASS mainWc = {}, parentWc = {}; MSG msg = {}; //MainHwnd mainWc.hbrBackground = (HBRUSH)COLOR_WINDOW; mainWc.hInstance = hInstance; mainWc.lpfnWndProc = MainWindowProc; mainWc.lpszClassName = MAIN_CLASS_NAME; RegisterClass(&mainWc); mainHwnd = CreateWindowEx(0, MAIN_CLASS_NAME, L"Ventana principal", WS_OVERLAPPEDWINDOW, 100, 100, 800, 600, NULL, NULL, hInstance, NULL); if (!mainHwnd) return 1; //ParentHwnd parentWc.hbrBackground = (HBRUSH)COLOR_WINDOWTEXT; parentWc.hInstance = hInstance; parentWc.lpfnWndProc = ParentWindowProc; parentWc.lpszClassName = PARENT_CLASS_NAME; RegisterClass(&parentWc); parentHwnd = CreateWindowEx(0, PARENT_CLASS_NAME, L"Ventana secundaria", WS_OVERLAPPEDWINDOW, 300, 300, 800, 600, NULL, NULL, hInstance, NULL); if (!parentHwnd) return 2; ShowWindow(mainHwnd, nCmdShow); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam); } LRESULT CALLBACK ParentWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
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.
|
|
|
|
|
|
|