(WinAPI) Pures WinAPI Programm mach Probleme
-
Warum Visual C++ Forum?
Weil das Programm meckert das die Visual-blabla-Library versucht wurde in einer ungewöhnlicher Art zu Laden. Das ist mein Problem/* WINDOWS.HPP */ #ifndef WINDOW_HPP #define WINDOW_HPP #include <windows.h> namespace las { class Window { private: HWND hWindow; public: void Create(LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam); void SetLong(int nIndex, LONG dwNewLong); void SetPos(HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags); void Destroy(); }; } #endif /* WINDOWS.CPP */ #include "window.hpp" using namespace las; void Window::Create(LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) { hWindow = ::CreateWindow(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); if(!hWindow) throw(GetLastError()); } void Window::SetLong(int nIndex, LONG dwNewLong) { if(!::SetWindowLong(hWindow, nIndex, dwNewLong)) throw(GetLastError()); } void Window::Destroy() { ::DestroyWindow(hWindow); } void Window::SetPos(HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) { if(!::SetWindowPos(hWindow, hWndInsertAfter, X, Y, cx, cy, uFlags)) throw(GetLastError); } /* MAIN.CPP */ #include "window.hpp" #include <windows.h> using namespace las; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = ::DefWindowProc; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = ::LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = ::LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) ::GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = "Die erste WNDCLASS"; Window win; win.Create("Die erste WNDCLASS", "Die erste WNDCLASS", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); }
-
Hi!
Ich habe mal kurz dein Programm erstellt und bei mir schmiert es mit 'ner Exception ab. Du hast nämlich vergessen, deine Fensterklasse mit RegisterClass zu registrieren.
-
Oh sorry, so ein dummer Fehler
-
Ok Fehler ist immer noch da
#include "window.hpp" #include <windows.h> using namespace las; LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WindowProc; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = ::LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = ::LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) ::GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = "Die erste WNDCLASS"; RegisterClass(&wndclass); Window win; win.Create("Die erste WNDCLASS", "Die erste WNDCLASS", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); win.Show(SW_SHOWNORMAL); win.Update(); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, message, wParam, lParam); }
-
Ich glaub irgendwie das das KEIN Visual C++ Problem ist, daher bitte nach WinAPI schieben. Danke