Hello,
I would like to encapsulate a view that contains a window and some widget in a class. So I started with something like below :
Display All
So I have two questions:
- Does anyone knows why view is always equal to NULL after a call to WM_GetUserData() to retrieve a pointer to "this" ?
- Is there a way to pass a user_data at construction and not after with a setter to avoid to check for WM_CREATE in internal_callback() ?
Thanks a lot,
Regards,
Nicolas
I would like to encapsulate a view that contains a window and some widget in a class. So I started with something like below :
C Source Code
- /// --- view.hpp
- class View
- {
- public:
- void create();
- private:
- static void internal_callback(WM_MESSAGE* pMsg);
- void callback(WM_MESSAGE * pMsg);
- WM_HWIN win_;
- };
- /// --- view.cpp
- void View::create()
- {
- win_ = WM_CreateWindowAsChild(0, 0, 240, 160, WM_HBKWIN, WM_CF_SHOW, View::internal_callback,
- sizeof(this));
- WM_SetUserData(win_, this, sizeof(this));
- }
- void View::internal_callback(WM_MESSAGE* pMsg)
- {
- /// I need to test this because SetUserData is call after creation
- /// So it avoids NULL pointer
- if (pMsg->MsgId == WM_CREATE)
- {
- /// Use static members...
- }
- else
- {
- void* view = NULL;
- WM_GetUserData(pMsg->hWin, view, 4); /// I can't call sizeof(this) but I know it is 4
- if (view != NULL) /// !!! view is always NULL
- {
- static_cast<View*>(view)->callback(pMsg);
- }
- }
- }
- void View::callback(WM_MESSAGE * pMsg)
- {
- switch (pMsg->MsgId)
- {
- case WM_PAINT:
- {
- GUI_SetBkColor(GUI_WHITE);
- GUI_Clear();
- GUI_SetColor(GUI_BLACK);
- GUI_DispString("Hello World");
- break;
- }
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
So I have two questions:
- Does anyone knows why view is always equal to NULL after a call to WM_GetUserData() to retrieve a pointer to "this" ?
- Is there a way to pass a user_data at construction and not after with a setter to avoid to check for WM_CREATE in internal_callback() ?
Thanks a lot,
Regards,
Nicolas