永发信息网

怎样使组合框中编辑框文字居中对齐【3】(VC)

答案:1  悬赏:20  手机版
解决时间 2021-04-11 14:36

如题,有没有哪位高手能够帮我实现 [步骤五] 啊.

[步骤一] 在对话框中加入一个按钮和组合框

[步骤二] 调整按钮的高度,如下图:

[步骤三] 发现按钮的高度和组合框的高度不一样 ,把组合框的高度调成和按钮一样

[步骤四]调成一样后,给组合框加入文字,编辑框显示的是下列框的第一个值,如下图:

[步骤五]加入文字后,发现字体居然不在编辑框的中间,我想要的就是怎样让它跑到中间去!

不知道是我表达得还不够清楚还是这个问题很难解决,一直都没有解决掉!

关于此问题,这是我发的第三遍了,我会一直发下去,直到解决为止!

附:

【1】第一次提问:

http://wenwen.soso.com/z/q166679631.htm

【2】第二次提问:

http://wenwen.soso.com/z/q166723316.htm

最佳答案
重载吧
用的linux没办法帮你作
不过在msdn 上帮你查找了几个例子
应该会对你有帮助
CComboBox::DrawItem

Called by the framework when a visual aspect of an owner-draw combo box changes.











virtual void DrawItem(
LPDRAWITEMSTRUCT lpDrawItemStruct
);







Parameters


lpDrawItemStruct

A pointer to a DRAWITEMSTRUCT structure that contains information about the type of drawing required.








Remarks


The itemAction member of the DRAWITEMSTRUCT structure defines the drawing action that is to be performed. See CWnd::OnDrawItem for a description of this structure.

By default, this member function does nothing. Override this member function to implement drawing for an owner-draw CComboBox
object. Before this member function terminates, the application should
restore all graphics device interface (GDI) objects selected for the
display context supplied in lpDrawItemStruct.








Example







Visual C++




// CMyComboBox is my owner-drawn combo box derived from CComboBox. This
// example draws an item's text centered vertically and horizontally. The
// combo box control was created with the following code:
// pmyComboBox->Create(
// WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|
// CBS_SORT|CBS_OWNERDRAWVARIABLE,
// myRect, pParentWnd, 1);
//
void CMyComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
ASSERT(lpszText != NULL);
CDC dc;

dc.Attach(lpDrawItemStruct->hDC);

// Save these value to restore them when done drawing.
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();

// If this item is selected, set the background color
// and the text color to appropriate values. Erase
// the rect by filling it with the background color.
if ((lpDrawItemStruct->itemAction & ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
}

// Draw the text.
dc.DrawText(
lpszText,
(int)_tcslen(lpszText),
&lpDrawItemStruct->rcItem,
DT_CENTER|DT_SINGLELINE|DT_VCENTER);

// Reset the background color and the text color back to their
// original values.
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);

dc.Detach();
}









DRAWITEMSTRUCT Structure

The DRAWITEMSTRUCT structure provides information the owner window must have to determine how to paint an owner-drawn control or menu item.











typedef struct tagDRAWITEMSTRUCT {
UINT CtlType;
UINT CtlID;
UINT itemID;
UINT itemAction;
UINT itemState;
HWND hwndItem;
HDC hDC;
RECT rcItem;
DWORD itemData;
} DRAWITEMSTRUCT;







Parameters


CtlType

The control type. The values for control types are as follows:

  • ODT_BUTTON Owner-drawn button

  • ODT_COMBOBOX Owner-drawn combo box

  • ODT_LISTBOX Owner-drawn list box

  • ODT_MENU Owner-drawn menu

  • ODT_LISTVIEW List view control

  • ODT_STATIC Owner-drawn static control

  • ODT_TAB Tab control

CtlID

The control ID for a combo box, list box, or button. This member is not used for a menu.

itemID

The
menu-item ID for a menu or the index of the item in a list box or combo
box. For an empty list box or combo box, this member is a negative
value, which allows the application to draw only the focus rectangle at
the coordinates specified by the rcItem member even though
there are no items in the control. The user can thus be shown whether
the list box or combo box has the input focus. The setting of the bits
in the itemAction member determines whether the rectangle is to be drawn as though the list box or combo box has input focus.

itemAction

Defines the drawing action required. This will be one or more of the following bits:

  • ODA_DRAWENTIRE This bit is set when the entire control needs to be drawn.

  • ODA_FOCUS This bit is set when the control gains or loses input focus. The itemState member should be checked to determine whether the control has focus.

  • ODA_SELECT This bit is set when only the selection status has changed. The itemState member should be checked to determine the new selection state.

itemState

Specifies
the visual state of the item after the current drawing action takes
place. That is, if a menu item is to be dimmed, the state flag ODS_GRAYED will be set. The state flags are as follows:

  • ODS_CHECKED This bit is set if the menu item is to be checked. This bit is used only in a menu.

  • ODS_DISABLED This bit is set if the item is to be drawn as disabled.

  • ODS_FOCUS This bit is set if the item has input focus.

  • ODS_GRAYED This bit is set if the item is to be dimmed. This bit is used only in a menu.

  • ODS_SELECTED This bit is set if the item's status is selected.

  • ODS_COMBOBOXEDIT The drawing takes place in the selection field (edit control) of an ownerdrawn combo box.

  • ODS_DEFAULT The item is the default item.

hwndItem

Specifies the window handle of the control for combo boxes, list boxes, and buttons. Specifies the handle of the menu (HMENU) that contains the item for menus.

hDC

Identifies a device context. This device context must be used when performing drawing operations on the control.

rcItem

A rectangle in the device context specified by the hDC
member that defines the boundaries of the control to be drawn. Windows
automatically clips anything the owner draws in the device context for
combo boxes, list boxes, and buttons, but it does not clip menu items.
When drawing menu items, the owner must not draw outside the boundaries
of the rectangle defined by the rcItem member.

itemData

For a combo box or list box, this member contains the value that was passed to the list box by one of the following:

  • CComboBox::AddString

  • CComboBox::InsertString

  • CListBox::AddString

  • CListBox::InsertString

For a menu, this member contains the value that was passed to the menu by one of the following:

  • CMenu::AppendMenu

  • CMenu::InsertMenu

  • CMenu::ModifyMenu








我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
谁知道像《花漾明星》这样的超可爱少女版的动
学一年钣金工 出来能拿到2500一个月吗?
平流层到底离地有多远?
问你下大家这个东东还好用吗?
“治国之道,在乎自强.而审时度势,则自强以练
高竹琴内科诊所地址有知道的么?有点事想过去
美少女战士里的经典台词
电脑重启问题
(-3)2-(-2)3的结果是A.-1B.1C.-17D.17
养锦鲤出现鱼缸换水后两三天就变浑浊里面有像
现在还有游戏人生的号吗?谁有,能送我吗?给
歌词里有说一句我爱你,粤语歌词"一封家书 一
滦县一中谁人是
今天下午长沙有雨没?
布鲁克斯多高呀
推荐资讯
家园等级有多少级!
判断题0.78米也就是78%米.
男女亲热最好在什么时候啊?
松下传真机故障
昆明医科大二本临床药学能考研吗?
最近新买了一台锐凌准德牌液压油电动加油机,
关于人成长的句子,诗句形容人很多
锡林郭勒盟蓝旗上都镇腾达进口轿车修配在什么
为什么杨颖会喝醉了酒
The teacher called Tom to his office becau
辛集市是地级市吗,现在辛集成为副地级市,什
QQ语音 没反应 怎么回事
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?