简体   繁体   English

RegisterClassEx失败为无效参数 - C ++

[英]RegisterClassEx Fails as Invalid Parameter - C++

A call to RegisterClassEx in my application is failing with error code 87, "The parameter is incorrect." 在我的应用程序中调用RegisterClassEx失败,错误代码为87,“参数不正确”。

memset( &m_wcx, 0, sizeof(WNDCLASSEX) );

m_wcx.cbSize = sizeof(WNDCLASSEX);  // size of structure
m_wcx.style = WS_ICONIC;            // initially minimized
m_wcx.lpfnWndProc = &WndProc;       // points to window procedure
m_wcx.cbClsExtra = 0;               // no extra class memory
m_wcx.cbWndExtra = 0;               // no extra window memory
m_wcx.hInstance = m_hInstance;      // handle to instance
m_wcx.hIcon = ::LoadIcon( NULL, IDI_APPLICATION ); // default app icon
m_wcx.hCursor = ::LoadCursor( NULL, IDC_ARROW ); // standard arrow cursor
m_wcx.hbrBackground = NULL;         // no background to paint
m_wcx.lpszMenuName = NULL;          // no menu resource
m_wcx.lpszClassName = _pwcWindowClass; // name of window class
m_wcx.hIconSm = NULL;               // search system resources for sm icon

m_atom = ::RegisterClassEx( &m_wcx );

if ( m_atom == 0 )
{
    TRACE(_T("CNotifyWindow::CNotifyWindow : Failed to register window class.\r\n\tError: %d\r\n\tFile: %s\r\n\tLine: %d\r\n"), ::GetLastError(), __WFILE__, __LINE__);
    THROW(::GetLastError());
}

Does anyone know what I'm doing wrong? 有谁知道我做错了什么? Thanks. 谢谢。

The style member of the WNDCLASSEX structure accepts class styles , not window styles . WNDCLASSEX结构的style成员接受类样式 ,而不是窗口样式 In other words, you can't make all windows of that class initially minimized that way. 换句话说,您不能使该类的所有窗口最初以这种方式最小化。

You should pass WS_ICONIC in the dwStyle argument to CreateWindow() or CreateWindowEx() instead. 您应该将WS_ICONIC参数中的dwStyle传递给CreateWindow()CreateWindowEx()

Usually "The parameter is incorrect" is the WINAPI's way of saying, "dude, you're sending me crap." 通常“参数不正确”是WINAPI的说法,“伙计,你给我发垃圾。”

So one of the WNDCLASSEX member variables is probably crap. 因此,其中一个WNDCLASSEX成员变量可能是废话。 Start by taking a closer look at the variables that are most likely to have something inappropriate in them: m_wcx.hInstance , m_wcx.lpfnWndProc , and m_wcx.lpszClassName . 首先仔细查看最有可能出现不适合的变量: m_wcx.hInstancem_wcx.lpfnWndProcm_wcx.lpszClassName

EDIT: 编辑:

As pointed out by @Johann Gerell, m_wcx.style = WS_ICONIC is an example of this. 正如@Johann Gerell所指出的, m_wcx.style = WS_ICONIC就是一个例子。 The documentation says that this is a class style , but you've sent a window style . 文档说这是一种类风格 ,但你发送了一种窗口样式 No good. 不好。

What's the difference? 有什么不同? Well, you know the difference between a C++ class and an object, right? 嗯,你知道C ++ class和对象之间的区别,对吧? A class is like a blueprint. 一个class就像一个蓝图。 An object is an instantiation of that blueprint. 对象是该蓝图的实例化。 Same is true of Window Classes & Windows. Window Classes和Windows也是如此。 A Window Class is a blueprint for creating a window, and a window is an instantiation of that Window Class. Window类是创建窗口的蓝图,窗口是该Window类的实例。 Window Classes have styles that specify things like what kind of DC to use, when to vertical refresh -- low level stuff like that which applies to every instance of that window class. Window Classes有一些样式,可以指定什么样的DC使用,何时进行垂直刷新 - 低级别的东西,如适用于该窗口类的每个实例的东西。 Windows also have styles, but these are different. Windows也有样式,但这些是不同的。 Window styles specify per-window things like if the window should be visible, minimized, etc. So RegisterClassEx asked you for an orange, and you tried to give it an apple. 窗口样式指定每个窗口的东西,如窗口应该是可见的,最小化的等等。所以RegisterClassEx问你橙色,你试图给它一个苹果。

The first thing is the WS_ICONIC . 首先是WS_ICONIC The window class style is something entirely diferent from window style. 窗口样式与窗口样式完全不同。 The class styles are the CS_* ones. 类样式是CS_*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM