6

I need a dummy window in MSVC++, this will never be visible and is created even before the app's main window. 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.

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • 1
    "required by a rendering engine" suggests that this window is used to create a render context. Is that so? In that case, you should preferrably create a window of the same class as your application window's. Otherwise, you have no guarantee that a) you can create a context at all, and b) that the context will be compatible with the one you use later. You'll have to register a class anyway for your main window, so it doesn't "cost extra", really. – Damon Mar 08 '11 at 10:30
  • I am not creating my own main window, so I have no class to re-use... and this window will be used as a dummy render-window by the engine... never actually rendered to. – Mr. Boy Mar 08 '11 at 11:23
  • 1
    I second this because I often run into situations that I need a dummy hWnd. For instance I need an hwnd for some win32 font API, in order to blit the font into a 2d memory array without showing it to the window. – Ricky Lung Apr 20 '12 at 02:41

3 Answers3

16

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...

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • 7
    @DavidHeffernan: Why not? It _is_ an answer to the question and there is nothing wrong (in principle) with answering your own question on stackoverflow. – CB Bailey Mar 08 '11 at 11:35
  • It is my answer to my question - after asking the question I tried it and it worked. By critique I mean it's open for improvements or whatever. – Mr. Boy Mar 08 '11 at 11:47
  • The return type of CreateWindow is void. CreateWindowEx returns an HWND – Bernd Elkemann Jan 03 '19 at 07:24
2

After CreateWindow you need to call ShowWindow to make it visible.

Dan Byström
  • 9,067
  • 5
  • 38
  • 68
1

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. If you need it for something else than OpenGL context I believe the code they present can be easily adopted.

CygnusX1
  • 20,968
  • 5
  • 65
  • 109