Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Custom color controls

twocanoes
Beginner
442 Views
Hi,

I'm working on an application using CVF v6.6b that has several windows, all with custom color controls generated with createWindowEX calls and responding the the CTLCOLORxxxxx messaging. During the course of using the application, it might be necessary to open and close one or more of the secondary windows several times. After doing this many times (more than 100), the custom control graphics start to draw themselves elsewhere on the window other than where they belong and fonts change, even though the the 'hot' area for the button remains where it belongs.

I'd sure appreciate any help that's out there to resolve this.
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
442 Views
Heh, it's so common error -- you have a GDI memory leak. Every object created with CreateXXX (probably CreateSolidBrush in your case) must be destroyed using DeleteObject -- and you are responsible for that. I bet you're using Win9x/ME, where this problem is exposed very quickly, due to small GDI memory poll.

So, instead of
case (WM_CTLCOLOREDIT)
  hBr = CreateSolidBrush(...)
  MyWindowProc = hBr

you need something like:
integer, save:: hBr(as_much_as_you_need)
...
case (WM_CREATE)
   hBr(1) = CreateSolidBrush(...)
   hBr(2) = CreateSolidBrush(...)
...
case (WM_CTLCOLOREDIT)
   select case(GetDlgItemId(hWnd, lParam))
   case (IDC_CONTROL1)
     MyWindowProc = hBr(1)
   case (IDC_CONTROL2)
     MyWindowProc = hBr(2)
...
case (WM_DESTROY)
   do i = 1, as_much_as_you_need
      b = DeleteObject(hBr(i))
   end do
...
If the colors should change at run-time, make sure to DeleteObject(hBr(x)) before creating a new one on its place.

Implementation details may vary (for example, you could use SetWindowLong/SetProp APIs to keep hBr's instead of saved array) but the principle is same -- create once, use as necessary, delete once.

HTH
Jugoslav
0 Kudos
twocanoes
Beginner
442 Views
You appear to be a hero. I've still got quite a bit of cleaning up to do, but the first test results look very promising. Thanks a lot!
0 Kudos
Reply