Little Design Problem :)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Florian3321
Posts: 27
Joined: February 12th, 2017, 1:50 pm

Little Design Problem :)

Post by Florian3321 » November 23rd, 2017, 2:03 pm

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!

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Little Design Problem :)

Post by albinopapa » November 24th, 2017, 8:14 pm

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Little Design Problem :)

Post by albinopapa » November 24th, 2017, 8:15 pm

I think you should upload your cleaned and zipped project here or share a github repo link for a more focused answer.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Florian3321
Posts: 27
Joined: February 12th, 2017, 1:50 pm

Re: Little Design Problem :)

Post by Florian3321 » November 24th, 2017, 9:52 pm

I will upload it to github :)
Thanks for the answers between :)

Post Reply