3

I've seen cases where people use DrawFrameControl along with PtInRect (where the mouse position is tested to the rectangle of the frame control), to simulate the effect of having a control (like a button). Why would you want to do this, rather than using child windows?

An example where this technique is used is this docking framework, where the docking window's close button isn't a physical window.

For an application I'm writing, I'm using a list view control which will hold up to 1000 items. Each item will hold, let's say, 10 buttons. All buttons are custom drawn.

Would it be considered a more efficient (and faster) approach to use the PtInRect mechanism for this?

Midas
  • 7,012
  • 5
  • 34
  • 52

2 Answers2

6

Each process has a limit of about 10,000 window handles. Not only would it be inefficient to create windows for 10 buttons on each of 1,000 items, it wouldn't necessarily be possible.

To answer your question: yes, creating "virtual" buttons by painting and hit-testing yourself is a much better solution.

arx
  • 16,686
  • 2
  • 44
  • 61
3

Having separate child windows brings certain overhead with them. Each child has its own attributes: window class, styles, window procedure, position, owning thread, etc. If you need to manage large array of such children many of their attributes will most probably be the same, wasting system resources. It may also become harder to manage them as separate windows:

  • You may notice painting glitches. Each window paints somewhat independently from the others, so when someone moves another window on top of your multi-children window and then moves that away, depending on how you organize things you may see unpleasant intermediate states like the background being redrawn with holes visible at the location of each child moments before children repaint. CS_PARENTDC might help with that.

  • Whenever you need to reposition these children, you need use the DeferWindowPos family of functions or else suffer similar repainting issues.

  • All these children need separate messages to manipulate.

After all it may be even simpler to simulate these children. My feeling is that attempting to put 10000 buttons on top of a list view will be much harder to implement and will suffer from the above visual problems. Using DrawFrameControl with owner-draw List View items would most probably give you simpler implementation with better visual result.

Besides there is a limit on the number of windows you can create, as @arx noted.

NonNumeric
  • 1,079
  • 7
  • 19