今天终于把这个给搞清楚了,之前那个图形编辑器因为不知道如何往toolbar中添加combobox,因此就没做场景的同比扩大,与缩小。现在终于明白如何用sdk实现此功能了,并且实现相关的combobox消息。说起来也是巧合,中午看到一个同学用mfc实现的把combobox加到toolbar中,发现也就这么回事,只需要设置combobox的父窗口是toolbar窗口就行了。但是当时的问题是如何接受到从combobox中得到的消息,因为主窗口是combobox的父亲的父亲,所以发送的WM_COMMAND ,wParam,lParam 主窗口无法接受。而那家伙的mfc程序也没有实现此功能,本来还可以根据它实现一下。正在苦思冥想中,突然眼前豁然开朗,msdn中的toolbar control 一块出现了如下语句:(介绍如何实现主窗口得到combobox改变选择后的消息)
You might want the edit control notifications to go to another window, such as the toolbar's parent. To do this, create the edit control as a child of the toolbar's parent window. Then change the parent of the edit control to the toolbar. Notifications go to the original parent; therefore, the edit control messages go to the parent of the toolbar and yet the edit window resides in the toolbar window. The following code example demonstrates this.
// Create the edit control. Notice that hWndParent, parent of // the toolbar, is used as the parent of the edit control. hWndEdit = CreateWindowEx(0L, "Edit", NULL, WS_CHILD | WS_BORDER | WS_VISIBLE | ES_LEFT | ES_AUTOVSCROLL | ES_MULTILINE, 0, 0, cx_edit, cy_edit, hWndParent, (HMENU) IDM_EDIT, hInst, 0 ); // Set the toolbar window as the parent of the edit control // window. You must set the toolbar as the parent of the edit // control for it to appear embedded in the toolbar. SetParent (hWndEdit, hWndToolbar);
以下是combobox的
hCombobox = CreateWindow(TEXT("combobox"),NULL,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,//!!!!
400,30,50,100,hWnd,(HMENU)IDM_COMBOX,hInst,NULL);
for(i=0;i<3;i++)
{
SendMessage(hCombobox,CB_ADDSTRING,0,(LPARAM)str[i]);
}
SendMessage(hCombobox,CB_SETCURSEL,1,0);
SetParent(hCombobox,hToolBar);
这样就可以让hWnd窗口接受来自combobox的消息了
这么看来在createwindow 中设立的父窗口 和用setparent设定的貌似有一点区别阿,正在研究中,目前还不知道。
现在都2007年了,跨年度的发现阿,真是值得纪年一下。