简体   繁体   English

创建HWND的最简单方法

[英]Simplest way to create a HWND

I need a dummy window in MSVC++, this will never be visible and is created even before the app's main window. 我需要一个MSVC ++中的虚拟窗口,这将永远不可见,甚至在应用程序的主窗口之前创建。 It's required by a rendering engine. 它是渲染引擎所必需的。 So I'd rather not have to register a class if possible. 所以如果可能的话,我宁愿不必注册课程。

For testing it would be better to make it visible to prove it is there - can I use a static or a button or something? 为了测试,最好让它可见以证明它在那里 - 我可以使用静态或按钮或其他东西吗? I've been trying with CreateWindow() but while I am getting a return value, nothing visible is appearing. 我一直在尝试使用CreateWindow()但是当我得到一个返回值时,没有任何可见的东西出现。

I submit my own test code for critique: 我提交了自己的评论代码:

HWND dummyHWND = ::CreateWindowA("STATIC","dummy",WS_VISIBLE,0,0,100,100,NULL,NULL,NULL,NULL);
::SetWindowTextA(dummyHWND,"Dummy Window!");

It seemed to work... 它似乎工作......

在CreateWindow之后,您需要调用ShowWindow使其可见。

In the first tutorial of NeHe they describe carefully what you need to do to set up an OpenGL rendering context, and the creation of a window (and HWND) is a part of it. NeHe的第一篇教程中,他们仔细描述了设置OpenGL渲染上下文所需要做的事情,并且创建窗口(和HWND)是其中的一部分。 If you need it for something else than OpenGL context I believe the code they present can be easily adopted. 如果你需要它而不是OpenGL上下文,我相信它们提供的代码可以很容易地被采用。

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

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