Search code examples
winapimfcwtl

PtInRect vs child windows


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?


Solution

  • 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.