Page 1 of 1

Little Design Problem :)

Posted: November 23rd, 2017, 2:03 pm
by Florian3321
Hi there!
I have a little problem and maybe someone can help :)
So, I have a window class, and a gfx class that has an reference to a window, to draw to. But now I need also a reference of the gfx in window, because in WM_PAINT I want to redraw the screen (I use GDI to make a backbuffer and blt it). I just want to do that, because I get some flickering and have read that it could be a solution. Should I make the gfx class a nested class of window? Or do you have other recommendations? I hope I explained my situtation well :mrgreen:
Thanks in advance!

Re: Little Design Problem :)

Posted: November 24th, 2017, 8:14 pm
by albinopapa
Providing a project solution would be a faster way of getting a solution to your problem.

You really haven't explained what your problem is, or what is wrong. I'm guessing it might be circular dependency ( can't include Window.h in Graphics.h and Graphics.h in Window.h ) or it could be needing to construct Window with a Graphics& or construct Graphics with a Window& which wouldn't be possible.

The solutions could be to use forward declarations, forward declare the Graphics class in Window.h and include in Window.cpp and include Window.h in Graphics.h.
You could store pointers and initialize the other at a later point.
You could create a third class that knows about both and can handle cross communication between the two.
I normally have a System class that handles WM messages, and keep a Window object and a Graphics object in System. When I get a WM_PAINT message, I can call my graphics object. If I get a WM_SIZE message, I can resize the Window::OnResize() and call Graphics::OnResize() since System has both objects available.

Re: Little Design Problem :)

Posted: November 24th, 2017, 8:15 pm
by albinopapa
I think you should upload your cleaned and zipped project here or share a github repo link for a more focused answer.

Re: Little Design Problem :)

Posted: November 24th, 2017, 9:52 pm
by Florian3321
I will upload it to github :)
Thanks for the answers between :)