@ Lars Skiba Windows-Programm
-
Das Thema ist irgendwie geschlossen worden (keine Ahnung warum), daher neuer Thread:
Show() und Update() fehlen; außer dem fehlt das "return 0;" aus WinMain().
Hier der lauffähige Code (alles in einer Pelle):
#include <windows.h> 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(); void Show(int nCmdShow); void Update(); }; 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); } void Window::Show(int nCmdShow) { ::ShowWindow(hWindow, nCmdShow); } void Window::Update() { ::UpdateWindow(hWindow); } 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); } 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); } return 0; }
EDIT:
CodeTags vervollständigt[ Dieser Beitrag wurde am 09.08.2002 um 20:40 Uhr von dEUs editiert. ]
-
Der Thread wurde nach WinAPI verschoben, weil er da auch hingehört