|
-
March 9th, 2013, 12:24 AM
#6
Re: Problem registering windowsclass
Callback functions must be static, that is, they cannot be associated with any particular instance of a class.
Code:
static LRESULT CALLBACK App::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
...
}
Code:
static INT_PTR CALLBACK App::About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
...
}
Your method, of passing this as the lParam of the WM_CREATE event and then storing it in the extra window memory for that particular window instance, is exactly what I use in my applications. However, for it to work, you need to specify the amount of extra memory, needed to store the pointer to the class instance, when you register the window class.
Code:
wcex.cbWndExtra = sizeof(App*);
To access the beginning of the extra window memory, use an index of 0, instead of GWLP_USERDATA.
Code:
...
::SetWindowLongPtrW(hWnd, 0, PtrToUlong(pApp));
...
pApp = reinterpret_cast<App *>(static_cast<LONG_PTR>(::GetWindowLongPtrW(hWnd, 0)));
...
It is considered poor style to use global variables. By using the extra window memory for the window, you do not need global variables at all. Declare hInst as a private data member of your App class (if you even need it). Any other data that needs to be retained between events should also be private data members.
Last edited by Coder Dave; March 9th, 2013 at 12:30 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|