WinProcs and C++

Started by
12 comments, last by OberonZ 21 years, 8 months ago
Hi,
Not exactly sure if this is off topic, so I apologize in advance if that's the case.

Anyway. I'm writing a simple map editor for my game. Because I want to eventually flesh it out to be a game editor for my game, I've decided to wrap all the functionality of the editor behind a few classes derived from the same parent (eg. CEditorFeature).

My problem is when creating window in a class. I don't want to have their WinProcs outside of the class, that goes against the purpose of my using classes in the first place.
When I try to compile (using VC6sp3), I get an error that says:

code:
error C2440: 'type cast' : cannot convert from '' to 'long (__stdcall *)(struct HWND__*, unsigned int, unsigned int, long)'

My code looks like this:
code:
class CMapEdit : public CEditorFeature{..BOOL CreateMEWindow ();LRESULT CALLBACK MEWndProc (HWND, UINT, WPARAM, LPARAM);}BOOL CMapEdit::CreateMEWindow (){WNDCLASSEX wcex;...wcex.lpfnWndProc = (WNDPROC) MEWndProc;...}

I can't figure out why that doesn't work. Also what's up with ''?

I tried removing the WNDPROC typecast, but that gave me a slightly different error:

code:
error C2440: 'type cast' : cannot convert from 'long (__stdcall CMapEdit::*)(struct HWND__*, unsigned int, unsigned int, long)' to 'long (__stdcall *)(struct HWND__*, unsigned int, unsigned int, long)'

If anybody knows anything about this, I would greatly appreciate the help. Oh, one more thing. I'm not using MFC (nor do I plan to).

I apoligize for the long message, but I banging my head against the wall here. Ouch.

Thanks again,
OberonZ


[This message has been edited by OberonZ (edited October 01, 1999).]

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
Advertisement
Thanks for the help.
You really saved me Kentamanos.

After my posting i figured out that i had to have a "this" pointer in the static member to the class, but i couldn't figure out how to get it there.

Question: When you call CreateWindow in your C++ class that you''ve wrote, do you save its return as your window handle (hWnd) or do you use the one that was assigned to the window by the handler for WM_NCCREATE?

Thanks
you can do it either way, but i'd probably assign the hwnd in create handler. atl does something like this for additional verification:

CWindow::Create(...) {
HWND hwnd = CreateWindow(...);
ATLASSERT(hwnd == m_hWnd);
}

edit: the above code will fail for WM_MINMAXINFO because the first WM_MINMAXINFO is processed before WM_NCCREATE and this pointer isn't available yet. keep that in mind.

[edited by - niyaw on August 5, 2002 11:07:32 AM]

This topic is closed to new replies.

Advertisement