title: Ownerdraw ComboBox Text Align Vertically Center
body: <p>I am using owner-draw ComboBox in my MFC dialog based application.</p>
  
  <p>I can draw Combobox's  ListBox items but I cant set the ComboBox text in the ComboBox's edit control with vertical center alignment, it always renders on the top left of the edit control.</p>
  
  <p>I need the text to be rendered on vertical center in the edit control.</p>
  
  <p>How to achieve it?
  CombobOx style :- CBS_DROPDOWN | CBS_OWNERDRAWFIXED | CBS_SORT | CBS_HASSTRINGS | CBS_UPPERCASE | WS_VSCROLL | WS_TABSTOP</p>
  
  <pre><code>BOOL CTestComboDlg::OnInitDialog()
  {
      CDialog::OnInitDialog();
  
      // TODO: Add extra initialization here
      COMBOBOXINFO cbi = { sizeof cbi};
      m_ctrlCombo.GetComboBoxInfo(&amp;cbi);
      CRect r;
      CWnd* p = CWnd::FromHandle(cbi.hwndItem);
      ((CEdit*)p)-&gt;GetRect(&amp;r);
  
      r.DeflateRect(10,10);
      ((CEdit*)p)-&gt;SetRect(r);
      m_ctrlCombo.AddString("GHKL");
      m_ctrlCombo.AddString("FGHJKL");
      m_ctrlCombo.AddString("ASDFGH");
      m_ctrlCombo.AddString("QWERTY");
      m_ctrlCombo.SetCurSel(0);
      return TRUE;  // return TRUE  unless you set the focus to a control
  }
  
  void CMyComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  {
      CDC dc;
      dc.Attach(lpDrawItemStruct-&gt;hDC);
  
      LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct-&gt;itemData;
      ASSERT(lpszText != NULL);
  
      if (lpDrawItemStruct-&gt;itemID != -1)
          dc.DrawText(lpszText, strlen(lpszText),
          &amp;lpDrawItemStruct-&gt;rcItem,
          DT_LEFT|DT_SINGLELINE|DT_VCENTER);
      dc.Detach();
  
  }
  </code></pre>
  
  <p>Thanks</p>