I am looking at some MFC/C++ CView object subclass like this:
BOOL CCustomView::CreateView(DWORD dwStyle,
CDocument * pDocument,
CWnd * pParent,
String title)
{
...
CString className = AfxRegisterWndClass(CS_DBLCLKS,
::LoadCursor(NULL, IDC_IBEAM));
return Create(className, title, dwStyle,
rect, pParent, -1, &context);
}
What I don't like about this, although maybe it's normal for MFC application programming, is that the runtime Window Class Name, is not a name of my own choosing. If later, I wanted to find this window, from another Win32 application, and find the window by window class name, I'd have to use the ugly "Afx:123:39843:39843" strings, and actually, I don't know if those window class names can be counted on to not change. I'd rather change the window class to "CCustomView", but still have it have the same behaviours as the window class created above. How do I do that?
There are better ways to solve your problem. The typical protocol I use is:
RegisterWindowMessage
in both applications. The message name should contain a GUID to make it unique PostMessage(HWND_BROADCAST, registeredMsg, idIWantToFindYou, HWNDofA)
idIWantTofindYou
to distinguish between different commands for your message. PostMessage(HWNDofA, registeredMessage, idHereIsMyHWnd, HWNDofB)
The upside of this mechanism is not running into problems with unresponsive programs. However, the "connection" isn't immediate, so you have to change your program flow. Alternatively, you can use EnumWindows
and SendMessageTimeout
to probe all top-level windows.
If you need to use the window class:
The class name assigned by MFC is only so window classes with the same attributes get reused. I am not aware of any problems with using your own window classes.
So the following should work:
WNDCLASS
or WNDCLASSEX
with the required attributes DefWindowProc
as WNDPROC
(that's what MFC does, MFC's WNDPROC
is set when creating the window) AfxRegisterClass
or RegisterClass
to register the window class. AfxRegisterClass
checks if the class is already registered and if the class is registered from a DLL, it will unregister the class when the DLL is unloaded. Otherwise they are roughly equivalent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.