Probleme mit Klasse [Subclasse]
-
class Button { //eigene Proc friend LRESULT CALLBACK ButtonProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { getId(); break; } } return CallWindowProc ((WNDPROC) WndProc, hWnd, message, wParam, lParam); } public: //Variablen char szAppName[20]; HINSTANCE m_hInstance; HWND m_hWnd; BITMAP m_bitmap; HBITMAP m_hBitmap; WNDPROC WindowsProc; int m_idBitmap; //Methoden Button(HINSTANCE hInstance, int id_bitmap) { //Klasse definieren strcpy(szAppName, "blablA"); WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = ButtonProc ; 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 = szAppName ; if (!RegisterClass (&wndclass)) MessageBox (NULL, TEXT ("Programm arbeitet mit Unicode und setzt Windows NT voraus!"), 0, MB_ICONERROR) ; //Variablen binden m_hWnd = CreateWindow (szAppName, 0, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; m_hInstance=hInstance; m_idBitmap=id_bitmap; //Windows Proc sichern WindowsProc = (WNDPROC)SetWindowLong (m_hWnd, GWL_WNDPROC, (LONG)ButtonProc); } int getId() { return m_idBitmap; } };- : error C2352: 'Button::getId' : illegal call of non-static member function
E:\Programmierung\C++\winapi2\m.cpp(60) : see declaration of 'getId'
- : error C2352: 'Button::getId' : illegal call of non-static member function
-
buttonproc ist kein teil von button. und vorallem: von welcher instanz von button sollte denn getId() aufgerufen werden?
-
Natürlich ist ButtonProc ein Teil v. Button! - Die Funktion steht in d. Klassendefinition.
-
Trotzdem gibt es einen Unterschied zwischen member und non-member Funktion. wndclass.lpfnWndProc akzeptiert nunmal nur einen non-member Funktionszeiger. getId() kannst du aber ohne Instanz nur aus einer member Funktion heraus aufrufen.