这个 CreateWindowEx 函数有什么问题?
好的,首先概述一下我正在尝试做的事情..
我试图在主父窗口中创建 3 个子窗口,并使用 EnumChildWindow
和 EnumChildProc
枚举它们,我想创建 3 个与父窗口高度相同的子窗口但是 1/3 宽度,并将它们一个接一个地对齐。
因此,我捕获了 WM_CREATE
消息来创建这些子窗口,并捕获了 WM_SIZE
来移动并使用 MoveWindow
对齐它们,除了没有创建子窗口之外,一切都很好。当我调试它时,我发现(在 Visual Studio 2008 的自动窗口中,调试时)我的 CreateWindowEx 语句没有被执行(自动窗口显示“无法计算表达式”。
这是该语句:
CreateWindowEx(0, (LPCWSTR)("childClass"), (LPCWSTR)NULL, WS_CHILD | WS_BORDER, 0, 0, 0, 0, hWnd, (HMENU) (int) (ID_FIRSTCHILD + 1), hInst, NULL);
当然,我在 for 循环中使用它来创建 3 个窗口,但这是另一回事......
那么,有人可以帮助/指导/建议我这里发生了什么吗?或者我做错了什么?
ps:我正在阅读这本电子书,从我获得此代码和所有内容的地方,所以请不要要求我采用其他方法或其他方法,比如将子创建代码放在其他地方等等......因为我没有制作任何程序,但只是按照书上的例子...:)
Okay, so first a little overview of what I am tryna do..
I am trying to create 3 child window in a main parent window, and use EnumChildWindow
and EnumChildProc
to enumerate them, I want to create 3 child windows of same height as of parent but 1/3rd width, and align them one after the other..
So, I captured the WM_CREATE
msg to create those child window, and WM_SIZE
to move and align them using MoveWindow
, everything is fine except for the fact that no child window is created. When I debugged it, I found that (in the Autos Window in Visual Studio 2008, while debugging) my CreateWindowEx statement is not getting executed (the autos window said "Expression cannot be evaluated."
Here's the statement:
CreateWindowEx(0, (LPCWSTR)("childClass"), (LPCWSTR)NULL, WS_CHILD | WS_BORDER, 0, 0, 0, 0, hWnd, (HMENU) (int) (ID_FIRSTCHILD + 1), hInst, NULL);
of course I was using it in a for loop to create 3 windows, but that's the other thing...
So, can anyone please help/guide/advice me what is going on in here? Or what am I doing wrong?
ps: I am reading this ebook from where I got this code and all, so please don't ask me to adopt another approach or something, say put the Child creation code somewhere else or so... because I am not making any program, but just following a book's example... :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的通灵能力建议您需要将 WS_VISIBLE 样式传递给上面的子窗口的 CreateWindow 调用 - 这样您就可以看到它们。 :)
我的开发经验表明:
CreateWindowEx 的返回值是多少?您是否将返回值分配给变量。如果是这样,您是否在调试器中的该行上设置了断点?如果 CreateWindow 的返回值为 NULL,那么 GetLastError 是什么(您可以在调试器中将其计算为“@err”)。
主窗口弹出后(子窗口不可见),您是否运行 Spy++ 来查看子窗口是否存在?他们的状态如何?
否则,您是否验证子窗口类的 WndProc 的 WM_CREATE 回调被调用?
My psychic powers suggest you need to pass in the WS_VISIBLE style to the CreateWindow call above for your child windows - so you can seem them. :)
My development experience suggests the following:
What is the return value of CreateWindowEx? Did you assign the return value to a variable. And if so, did you set a breakpoint on that line in the debugger? And if the return value from CreateWindow is NULL, then what is GetLastError (which you can evaluate in the debugger as "@err").
After your main window pops up (with the children invisible), did you run Spy++ to see if the child windows exist? What is their state?
Otherwise, did you validate that the WM_CREATE callback of the WndProc of your child window class is getting called?