?
Naja...-Ich habe zumindest die Antwort jetzt raus:
Die Nachrichten-Schleife muss offenbar immer static sein. Dummerweise ist in einer Methode, welche als static deklariert ist, jeweils kein This-Pointer verfügbar, aber auch der lässt sich nachbilden...
fenster.h:
#include <windows.h>
class CFenster
{
public:
HWND hHandle;
WNDCLASS wWndclass;
MSG mMsg;
bool bDestroyed;
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
this->bDestroyed=true;
return 0;
}
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
static LRESULT CALLBACK WndProc_static(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
if(message==WM_CREATE)
{
SetWindowLong(hWnd,GWL_USERDATA,(LONG)((LPCREATESTRUCT)lParam)->lpCreateParams);
}
CFenster *pThis=(CFenster*)GetWindowLong(hWnd,GWL_USERDATA);
if(pThis==0)
{
return DefWindowProc (hWnd,message,wParam,lParam);
}
else
{
return pThis->WndProc(hWnd,message,wParam,lParam);
}
}
void FensterErstellen(void)
{
wWndclass.style = CS_HREDRAW|CS_VREDRAW;
wWndclass.lpfnWndProc = WndProc_static;
wWndclass.cbClsExtra = 0;
wWndclass.cbWndExtra = 0;
wWndclass.hInstance = 0;
wWndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wWndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wWndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wWndclass.lpszClassName = TEXT("Name-der-Fensterklasse");
wWndclass.lpszMenuName = NULL;
RegisterClass(&wWndclass);
hHandle=CreateWindow( TEXT("Name-der-Fensterklasse"),
TEXT("Fenstertitel"),
WS_OVERLAPPEDWINDOW,
0,
0,
500,
500,
NULL,
NULL,
0,
this);
this->bDestroyed=false;
ShowWindow(this->hHandle,SW_SHOW);
UpdateWindow(this->hHandle);
}
};
main.cpp:
#include "fenster.h"
void main(void)
{
CFenster MeinFenster;
MeinFenster.FensterErstellen();
while(!MeinFenster.bDestroyed)
{
if(PeekMessage(&MeinFenster.mMsg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&MeinFenster.mMsg);
DispatchMessage(&MeinFenster.mMsg);
}
}
}