SDK编程(简单问题,高分). 用CreateWindow创建一个ComboBox之后, 怎样再设置(还要可以取消)Drop List属性?

rtdb 2003-04-09 11:29:46
RT
...全文
165 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
rtdb 2003-04-10
  • 打赏
  • 举报
回复
谢谢pcman1990(pcman)!
zqone 2003-04-10
  • 打赏
  • 举报
回复
SetWindowLong
SetWindowPos
pcman1990 2003-04-10
  • 打赏
  • 举报
回复
不知你切换风格的目的是什么,如果只是在某些时候不想让用户在编辑框中输入的话,倒是有个办法--如果实在找不到办法的话(估计你也只能用这招了:)):
顺着那篇文章的思路,把edit框设置成readonly:) 代码如下:
假设你的combobox的窗口句柄是hwndComboBox

// combobox的第一个子窗口是edit
HWND hwndEdit = ::GetWindow(hwndComboBox, GW_CHILD);
if(hwndEdit != NULL)
::SendMessage(hwndEdit, EM_SETREADONLY, TRUE, 0L);
jemmylau 2003-04-09
  • 打赏
  • 举报
回复
是不是啊?

都一颗星了,还问这个问题啊?

怪!
jemmylau 2003-04-09
  • 打赏
  • 举报
回复
HWND hWnd = CreateWindow(...);

::SendMessage(hWnd,CB_SHOWDROPDOWN,TRUE,0);

SendMessage(
(HWND) hWnd, // handle to destination window
CB_SHOWDROPDOWN, // message to send
(WPARAM) wParam, // show state
(LPARAM) lParam // not used; must be zero
);
rtdb 2003-04-09
  • 打赏
  • 举报
回复
请继续。第一个给出可用CODE的人给高分。
rtdb 2003-04-09
  • 打赏
  • 举报
回复
我要的是CBS_DROPDOWNLIST。

主要是没空查, 顺便当散分了。
Coder 青田 2003-04-09
  • 打赏
  • 举报
回复
控制子窗口的样式,和一些操作,都是通过SendMessage发送消息来完成的。希望你阅读MSDN,里面所有的样式和消息都做了详细说明~~~~~~

Combo Box Styles
To create a combo box using the CreateWindow or CreateWindowEx function, specify the COMBOBOX class, appropriate window style constants, and a combination of the following combo box styles.

Style Description
CBS_AUTOHSCROLL Automatically scrolls the text in an edit control to the right when the user types a character at the end of the line. If this style is not set, only text that fits within the rectangular boundary is allowed.
CBS_DISABLENOSCROLL Shows a disabled vertical scroll bar in the list box when the box does not contain enough items to scroll. Without this style, the scroll bar is hidden when the list box does not contain enough items.
CBS_DROPDOWN Similar to CBS_SIMPLE, except that the list box is not displayed unless the user selects an icon next to the edit control.
CBS_DROPDOWNLIST Similar to CBS_DROPDOWN, except that the edit control is replaced by a static text item that displays the current selection in the list box.
CBS_HASSTRINGS Specifies that an owner-drawn combo box contains items consisting of strings. The combo box maintains the memory and address for the strings so the application can use the CB_GETLBTEXT message to retrieve the text for a particular item.
CBS_LOWERCASE Converts to lowercase all text in both the selection field and the list.
CBS_NOINTEGRALHEIGHT Specifies that the size of the combo box is exactly the size specified by the application when it created the combo box. Normally, the system sizes a combo box so that it does not display partial items.
CBS_OEMCONVERT Converts text entered in the combo box edit control from the Windows character set to the OEM character set and then back to the Windows set. This ensures proper character conversion when the application calls theCharToOem function to convert a Windows string in the combo box to OEM characters. This style is most useful for combo boxes that contain filenames and applies only to combo boxes created with the CBS_SIMPLE or CBS_DROPDOWN style.
CBS_OWNERDRAWFIXED Specifies that the owner of the list box is responsible for drawing its contents and that the items in the list box are all the same height. The owner window receives a WM_MEASUREITEM message when the combo box is created and a WM_DRAWITEM message when a visual aspect of the combo box has changed.
CBS_OWNERDRAWVARIABLE Specifies that the owner of the list box is responsible for drawing its contents and that the items in the list box are variable in height. The owner window receives a WM_MEASUREITEM message for each item in the combo box when you create the combo box and a WM_DRAWITEM message when a visual aspect of the combo box has changed.
CBS_SIMPLE Displays the list box at all times. The current selection in the list box is displayed in the edit control.
CBS_SORT Automatically sorts strings added to the list box.
CBS_UPPERCASE Converts to uppercase all text in both the selection field and the list.


下面是消息:
CB_DELETESTRING
CB_FINDSTRINGEXACT
CB_GETCOUNT
CB_GETCURSEL
CB_GETDROPPEDCONTROLRECT
CB_GETDROPPEDSTATE
CB_GETITEMDATA
CB_GETITEMHEIGHT
CB_GETLBTEXT
CB_GETLBTEXTLEN
CB_GETEXTENDEDUI
CB_LIMITTEXT
CB_RESETCONTENT
CB_SELECTSTRING
CB_SETCURSEL
CB_SETDROPPEDWIDTH
CB_SETEXTENDEDUI
CB_SETITEMDATA
CB_SETITEMHEIGHT
CB_SHOWDROPDOWN

既然你学习SDK,那么手边就必须有一份msdn~~~~~~~~里面有一切想要的资料
dawner 2003-04-09
  • 打赏
  • 举报
回复
用SendMessage 函数可以设定。
rtdb 2003-04-09
  • 打赏
  • 举报
回复
TO jemmylau(枕头): 我要的不是SHOWDROPDOWN这个动作, 而是CBS_DROPDOWNLIST这种风格。

谢谢 pcman1990(pcman)。
它的“切换”真的很有意思, 竟然内置了另一个控件。

我的问题是在库中创建了这个窗口,我不能改库。所以想改变它的风格。
希望大家继续帮忙。


pcman1990 2003-04-09
  • 打赏
  • 举报
回复
不能通过简单的设置风格来达到目的的。这里有一篇文章,是关于如何“切换”组合框风格的,其做法是自己处理组合框的edit子窗口。代码用MFC写成,但其原理或许对你有启发:
Switch between drop-list and drop-down mode:
http://www.codeguru.com/combobox//SwitchCombo.shtml

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧