- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码有问题。我正在创建一个类来围绕一些 WinAPI 来创建 GUI,但是我在尝试注册该类时遇到了问题。
我的代码:
inline Window::Window(const TCHAR *windowName, const int x, const int y, const int width, const int height, const TCHAR *className) : abstractWindow() {
Window(0, className, windowName, WS_OVERLAPPEDWINDOW, x, y, width, height, NULL, NULL, NULL, NULL);
}
Window::Window(const DWORD dwExStyle, const TCHAR *lpClassName, const TCHAR *lpWindowName, const DWORD dwStyle, const int x, const int y, const int nWidth, const int nHeight, const HWND hWndParent, const HMENU hMenu, const HINSTANCE hInstance, const LPVOID lpParam) : abstractWindow() {
_proc = (WNDPROC*) &abstractWindow::msgRouter;
_styleEx = dwExStyle;
_className = (!lpClassName) ? TEXT("MyGuiClass") : lpClassName;
_windowName = lpWindowName;
_style = dwStyle;
_x = x;
_y = y;
_width = nWidth;
_height = nHeight;
_hwndParent = hWndParent;
_hInstance = (!hInstance) ? ::GetModuleHandle(NULL) : hInstance;
_hMenu = hMenu;
_lpParam = lpParam;
_wndClassEx.cbSize = sizeof(_wndClassEx);
_wndClassEx.style = CS_HREDRAW | CS_VREDRAW;
_wndClassEx.lpfnWndProc = abstractWindow::msgRouter;
_wndClassEx.cbClsExtra = 0;
_wndClassEx.cbWndExtra = 0;
_wndClassEx.hInstance = _hInstance;
_wndClassEx.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
_wndClassEx.hCursor = ::LoadCursor(NULL, IDC_ARROW);
_wndClassEx.hbrBackground = (HBRUSH) COLOR_WINDOW;
_wndClassEx.lpszMenuName = NULL;
_wndClassEx.lpszClassName = _className;
_wndClassEx.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION);
}
_wndClassEx 已在 WNDCLASSEX 的类 header 中定义,注册函数仅运行 RegisterClassEx(&_wndClassEx)。
以下是我如何调用这些类:(但是一次只调用一个)
Window gui (TEXT("Title"), 10, 10, 500, 250);
Window gui (0, NULL, TEXT("Title"), WS_OVERLAPPEDWINDOW, 10, 10, 500, 200, NULL, NULL, hInstance, NULL);
第二个工作得很好,但是当我调用第一个(较短的参数,将其传递给第二个)时,类注册失败。我已经完整地编写了 _wndClassEx 并且遍历了每一个并对其进行了修改但没有成功。我已经使用调试器进行了调试,似乎一切正常。所以我完全不知道该怎么做。
顺便说一下,abstractWindow::msgRouter 是静态的。
谢谢。
最佳答案
问题出在这个构造函数上:
inline Window::Window(const TCHAR *windowName, const int x, const int y, const int width, const int height, const TCHAR *className) : abstractWindow() {
Window(0, className, windowName, WS_OVERLAPPEDWINDOW, x, y, width, height, NULL, NULL, NULL, NULL);
}
你不能像那样从另一个构造函数调用构造函数。最终发生的事情是创建了一个临时对象,然后立即将其丢弃。实现这一点的方法(这只有在你有一个从新的 C++11 标准实现这个特性的编译器时才有效)是如果你说
inline Window::Window(const TCHAR *windowName, const int x, const int y, const int width, const int height, const TCHAR *className) : Window(0, className, windowName, WS_OVERLAPPEDWINDOW, x, y, width, height, NULL, NULL, NULL, NULL) {};
另一种方法是按照@aztaroth 所说的去做:创建一个单独的方法并从两个构造函数中调用它(即使使用较旧的编译器也可以)。
关于c++ - WinAPI C++ - RegisterClassEx 'The parameter was incorrect',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10684498/
我正在用下面的代码创建一个窗口 int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgum
我正在使用 Windows 库,我是新手,但我遇到了一个错误,我在谷歌上搜索了足够多,但我不知道发生了什么。 这是我的代码: LRESULT CALLBACK WbWindow::st_wind_ca
在我的 Win32 C++ DLL 中,我发现如果我尝试以这种方式使用 RegisterClassEx,它工作得很好: WNDCLASSEX wx = {}; wx.cbSize = sizeof(W
在我的应用程序中调用 RegisterClassEx 失败,错误代码为 87,“参数不正确。” memset( &m_wcx, 0, sizeof(WNDCLASSEX) ); m_wcx.cbSiz
我正在尝试使用 VC++ 编译器和 Visual Studio 通过 Win32 API 打开一个简单的窗口。我想知道为什么这门课不及格;我试过在没有指针的情况下分配它,以及将它作为指针分配并将它作为
出于好奇: 在我的 wWinMain() 入口点中,我正在填充一个 WNDCLASSEX 结构,我随后将其传递给 RegisterClassEx()。这是 WinMain 中要做的第一件事,看起来像这
这是代码 #include const wchar_t g_szClassName[] = L"myWindowClass"; // Step 4: the Window Procedure LRE
我的代码有问题。我正在创建一个类来围绕一些 WinAPI 来创建 GUI,但是我在尝试注册该类时遇到了问题。 我的代码: inline Window::Window(const TCHAR *wind
我构建了一个为 32 位和 64 位编译的 DLL。以下代码片段适用于 32 位,但不适用于 64 位(错误代码 87 - 参数无效) const CHAR g_szClassName[] = "My
我是一名优秀的程序员,十分优秀!