Hallo, I am trying to remove some strange things in my program and I found something which im not sure why is not working.
Why does not the first example of setClassLongPrt work?
HBITMAP img = (HBITMAP)LoadImage(NULL, TEXT(imgPath.c_str()), IMAGE_BITMAP,640,480,LR_LOADFROMFILE);
HBRUSH brush = CreatePatternBrush(img);
// this does not work, is simply loads a white image
// This works, but here I get problems after the function have been called several times. Memory leak?
Yes, specifically GDI resources. You must DeleteObject any GDI object when you are done with it(caveat: shared system resources don't require deletion). In the case of the patterned brush, DeleteObject will not affect the bitmap used with CreatePatternBrush so you would have to use DeleteObject on that bitmap handle, too, once you were finished with it.
There is a delay when using SetClassLongPtr to change the background brush as the new brush is not drawn immediately. It also affects all windows of that particular window class which may not always be what you want.
Why does not ... work
Alternatively, to change the background of a single window, you can handle the window's WM_ERASEBKGND message.
Thanks for your reply.
But im still not sure why the code I posted does not work in the first case. I cant see why first loading data into a variable before passing it to a function makes any difference from just loading it into the function.
The problem was that I was deleting the brush while it still was in use by the window.