Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. virtual function MeasureItem problem(owner draw function problem)

virtual function MeasureItem problem(owner draw function problem)

Scheduled Pinned Locked Moved C / C++ / MFC
helplearningc++question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fantasy1215
    wrote on last edited by
    #1

    I derived my class from CListBox called CMyListBox. then I write the virtual function MeasureItem to change the height of items. In my main dialog CMyDialog, construct a CMyListBox object. CMyListBox m_ctlBox; and in the CMyDialog::OnInitDialog DDX_Control(pDX, BOXID, m_ctlBox); CMyDialog::OnInitDialog() { m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); } but it has no affect. The height doesn't change at all. But it executes fine. Then I've tried comment the code m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); And in the resource editor, I change the property of the ListBox with OwnerDraw to OwnerDrawFixed, then I got compilation assertion error. What do I miss? And Why do I get the assertion error?But I don't want to create the CMyListBox on the fly at all, cause If I create it on the fly, I can't adjust its position and size. And in the book «Programming with MFC 2nd», I program as the book shows, it works fine. First, in the CMyListBox use the PreCreateWindowClass to add the style with LBS_OWNERDRAWFIXED OR LBS_OWNERDRAWVARIABLE. Second, in the virtual MeasureItem function to change the height. Third, But you should in the CMyDialog::OnInitDialog to create the CMyListBox on the fly, it should use CMyListBox.Create to create the ListBox, otherwise the CMyListBox::PreCreateWindowClass would not be called to initialize the style with LBS_OWNERDRAWFIXED.

    M 1 Reply Last reply
    0
    • F fantasy1215

      I derived my class from CListBox called CMyListBox. then I write the virtual function MeasureItem to change the height of items. In my main dialog CMyDialog, construct a CMyListBox object. CMyListBox m_ctlBox; and in the CMyDialog::OnInitDialog DDX_Control(pDX, BOXID, m_ctlBox); CMyDialog::OnInitDialog() { m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); } but it has no affect. The height doesn't change at all. But it executes fine. Then I've tried comment the code m_ctlBox.ModifyStyle(0, LBS_OWNERDRAWFIXED); And in the resource editor, I change the property of the ListBox with OwnerDraw to OwnerDrawFixed, then I got compilation assertion error. What do I miss? And Why do I get the assertion error?But I don't want to create the CMyListBox on the fly at all, cause If I create it on the fly, I can't adjust its position and size. And in the book «Programming with MFC 2nd», I program as the book shows, it works fine. First, in the CMyListBox use the PreCreateWindowClass to add the style with LBS_OWNERDRAWFIXED OR LBS_OWNERDRAWVARIABLE. Second, in the virtual MeasureItem function to change the height. Third, But you should in the CMyDialog::OnInitDialog to create the CMyListBox on the fly, it should use CMyListBox.Create to create the ListBox, otherwise the CMyListBox::PreCreateWindowClass would not be called to initialize the style with LBS_OWNERDRAWFIXED.

      M Offline
      M Offline
      Mike ONeill
      wrote on last edited by
      #2

      The proper place to do all this is inside your override of the PreSubclassWindow() function. This function is called regardless of whether the control is created dynamically with a call to Create(), or on-the-fly with a dialog resource template and subclassed with the DDX_Control functions. See http://www.flounder.com/presubclasswindow.htm[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups