📄 combobox.c
字号:
GetTextMetrics(hDC,&tm);
ReleaseDC(hWnd,hDC);
wEditHeight = tm.tmHeight + 3 * tm.tmInternalLeading;
if (wEditHeight == lp->uHeight)
return 0L;
lp->uHeight = (UINT)wEditHeight;
lp->ButtonRect.bottom = wEditHeight;
/*
** The following SetWindowPos causes WM_WINDOWPOSCHANGING message
** where child windows are resized and/or moved.
*/
ShowWindow(hWnd, SW_HIDE);
GetClientRect(hWnd,&rcClient);
if ((lp->wStyle & 0xf) != CBS_SIMPLE)
SetWindowPos(hWnd, 0,
0, 0, rcClient.right, (int)wEditHeight,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW);
else SetWindowPos(hWnd, 0,
0, 0, rcClient.right, (int)wEditHeight + lp->ListBoxRect.bottom - lp->ListBoxRect.top + 1,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW);
ShowWindow(hWnd, SW_SHOWNA);
if (lp->EditControl)
SendMessage(lp->EditControl, WM_SETFONT, wParam,lParam);
SendMessage(lp->ListBoxControl, WM_SETFONT, wParam,lParam);
if(LOWORD(lParam))
RedrawWindow(hWnd,(const RECT *)0,(HRGN)0,
RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW );
return (LRESULT)0;
case WM_GETFONT:
return lp->hFont;
#endif /* WM_SETFONT/WM_GETFONT */
case WM_MOVE: /*WM_WINDOWPOSCHANGING:*/
#if 0
lpwp = (LPWINDOWPOS)lParam;
#else
pp.x=LOWORD(lParam);
pp.y=HIWORD(lParam);
#endif
if (1)/*(lpwp)*/ {
if (1)/*(!(lpwp->flags & SWP_NOSIZE))*/ {
lp->ButtonRect.right = (hWnd->winrect.right-hWnd->winrect.left); /* lpwp->cx; */
if ((lp->wStyle & 0xf) == CBS_SIMPLE)
lp->ButtonRect.left = lp->ButtonRect.right;
else lp->ButtonRect.left = (hWnd->winrect.right-hWnd->winrect.left)/*lpwp->cx*/ - 1 -
GetSystemMetrics(SM_CXVSCROLL);
if (lp->EditControl)
{
wEditWidth = lp->ButtonRect.left + 1;
if ((lp->wStyle & 0xf) == CBS_SIMPLE)
wEditWidth --;
if ((lp->wStyle & 0xf) == CBS_DROPDOWN)
wEditWidth -= 5;
SetWindowPos(lp->EditControl,(HWND)0,
0,0,
wEditWidth, lp->uHeight,
SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
}
if (lp->ListBoxControl)
{
if ((lp->wStyle & 0x0F) == CBS_SIMPLE)
{
lp->ListBoxRect.left = 5;
lp->ListBoxRect.top = lp->uHeight - 1;
lp->ListBoxRect.right = (hWnd->winrect.right-hWnd->winrect.left); /* lpwp->cx; */
lp->ListBoxRect.bottom = (hWnd->winrect.bottom-hWnd->winrect.top)/*lpwp->cy*/ - 2;
}
else {
POINT cp;
cp.x = 0;
cp.y = lp->uHeight - 1;
ClientToScreen(hWnd, &cp);
OffsetRect(&lp->ListBoxRect, cp.x - lp->ListBoxRect.left, cp.y - lp->ListBoxRect.top);
lp->ListBoxRect.right = lp->ListBoxRect.left + (hWnd->winrect.right-hWnd->winrect.left)/*lpwp->cx*/;
if ((lp->wStyle & 0xf) != CBS_DROPDOWNLIST)
lp->ListBoxRect.right -= 5;
}
SetWindowPos(lp->ListBoxControl,(HWND)0,
lp->ListBoxRect.left, lp->ListBoxRect.top,
lp->ListBoxRect.right - lp->ListBoxRect.left,
lp->ListBoxRect.bottom - lp->ListBoxRect.top,
SWP_NOACTIVATE|SWP_NOZORDER);
}
#if 0 /* jmt: fix: no WM_WINDOWPOSCHANGING */
/* the height of the normal state stays the same */
if ((lp->wStyle & 0xf) != CBS_SIMPLE)
lpwp->cy = (int)lp->uHeight;
#endif
}
}
return (LRESULT)0;
case WM_WINDOWPOSCHANGED:
DefWindowProc(hWnd,uMsg,wParam,lParam);
lpwp = (LPWINDOWPOS)lParam;
if (lpwp) {
if (!(lpwp->flags & SWP_NOSIZE)) /* TODO */
#if 0
RedrawWindow(hWnd,(const RECT *)0,(HRGN)0,
RDW_INVALIDATE|RDW_ERASE);
#else
InvalidateRect(hWnd,NULL,TRUE);
#endif
}
return (LRESULT)0;
#if 0 /* jmt: fix: no ownerdraw */
/* *******************************************/
/* ownerdraw stuff */
/* *******************************************/
case WM_DRAWITEM:
lpdis = (LPDRAWITEMSTRUCT)lParam;
lpdis->CtlType = ODT_COMBOBOX;
lpdis->CtlID = lp->nID;
lpdis->hwndItem = hWnd;
return SendMessage(lp->hWndParent,WM_DRAWITEM,
(WPARAM)lp->nID,lParam);
case WM_MEASUREITEM:
lpmis = (LPMEASUREITEMSTRUCT)lParam;
lpmis->CtlType = ODT_COMBOBOX;
lpmis->CtlID = lp->nID;
return SendMessage(lp->hWndParent,WM_MEASUREITEM,
(WPARAM)lp->nID,lParam);
case WM_DELETEITEM:
lpdlis = (LPDELETEITEMSTRUCT)lParam;
lpdlis->CtlType = ODT_COMBOBOX;
lpdlis->CtlID = lp->nID;
lpdlis->hwndItem = hWnd;
return SendMessage(lp->hWndParent,WM_DELETEITEM,
(WPARAM)lp->nID,lParam);
case WM_CONVERT:
if (!lpComboBinToNat) {
hComboClass32 = FindClass("COMBOBOX",0);
lpComboBinToNat = (WNDPROC)GetClassHandleLong(
hComboClass32,GCL_BINTONAT);
}
if (lpComboBinToNat)
return lpComboBinToNat(hWnd, uMsg, wParam, lParam);
else
return (LRESULT)0;
#endif /* ownerdraw */
default:
return DefCBProc( hWnd, uMsg, wParam, lParam);
}
return rc;
}
/* **********************************************************************
**
************************************************************************/
static LRESULT DefCBProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int len,index;
COMBOBOX *lp;
char *selection;
int rc;
POINT cp;
lp = (COMBOBOX *) hWnd->userdata/*GetWindowLong(hWnd,CWD_LPCBDATA)*/;
switch(uMsg) {
/* *******************************************/
/* messages specific to the list box control */
/* *******************************************/
case CB_ADDSTRING:
lp->nListItems++; /* shd. test for successful return */
return SendMessage(lp->ListBoxControl,LB_ADDSTRING,
wParam,lParam);
case CB_DELETESTRING:
if (lp->nListItems)
lp->nListItems--;
return SendMessage(lp->ListBoxControl,LB_DELETESTRING,
wParam,lParam);
case CB_DIR:
return SendMessage(lp->ListBoxControl,LB_DIR,
wParam,lParam);
case CB_FINDSTRING:
return SendMessage(lp->ListBoxControl,LB_FINDSTRING,
wParam,lParam);
case CB_FINDSTRINGEXACT:
return SendMessage(lp->ListBoxControl,LB_FINDSTRINGEXACT,
wParam,lParam);
case CB_GETCOUNT:
return SendMessage(lp->ListBoxControl,LB_GETCOUNT,
wParam,lParam);
case CB_GETCURSEL:
return SendMessage(lp->ListBoxControl,LB_GETCURSEL,
wParam,lParam);
case CB_GETITEMDATA:
return SendMessage(lp->ListBoxControl,LB_GETITEMDATA,
wParam,lParam);
case CB_GETITEMHEIGHT:
return SendMessage(lp->ListBoxControl,LB_GETITEMHEIGHT,
wParam,lParam);
case CB_GETLBTEXT:
return SendMessage(lp->ListBoxControl,LB_GETTEXT,
wParam,lParam);
case CB_GETLBTEXTLEN:
return SendMessage(lp->ListBoxControl,LB_GETTEXTLEN,
wParam,lParam);
case CB_INSERTSTRING:
return SendMessage(lp->ListBoxControl,LB_INSERTSTRING,
wParam,lParam);
case CB_SETITEMDATA:
return SendMessage(lp->ListBoxControl,LB_SETITEMDATA,
wParam,lParam);
/* *******************************************/
/* messages specific to the edit control */
/* *******************************************/
case CB_GETEDITSEL:
return SendMessage(lp->EditControl,EM_GETSEL,0,0);
case CB_LIMITTEXT:
return SendMessage(lp->EditControl,EM_LIMITTEXT,
wParam,lParam);
case CB_SETEDITSEL:
return SendMessage(lp->EditControl,EM_SETSEL,
wParam,lParam);
/* *******************************************/
/* messages handled by the combobox */
/* *******************************************/
case CB_GETDROPPEDCONTROLRECT:
CopyRect((LPRECT)lParam,&lp->ListBoxRect);
break;
case CB_GETDROPPEDSTATE:
return IS_SET(lp,CSF_CAPTUREACTIVE);
case CB_GETEXTENDEDUI:
return (LRESULT)lp->bExtended;
case CB_RESETCONTENT:
SendMessage(lp->ListBoxControl,LB_RESETCONTENT,0,0);
if (lp->EditControl)
SendMessage(lp->EditControl,WM_SETTEXT,0,(LPARAM)(LPSTR)"");
break;
case CB_SELECTSTRING:
index = (int)SendMessage(lp->ListBoxControl, LB_SELECTSTRING, wParam, lParam);
if (index == LB_ERR)
return CB_ERR;
len = (int)SendMessage(lp->ListBoxControl, LB_GETTEXTLEN, index, 0);
if (len <= 0)
return CB_ERR;
selection = (LPSTR)GdMalloc((UINT)len+1);
rc = (int)SendMessage(lp->ListBoxControl, LB_GETTEXT, (WPARAM)index, (LPARAM)selection);
if (lp->EditControl)
rc = (int)SendMessage(lp->EditControl, WM_SETTEXT, 0, (LPARAM)selection);
else CBoxDrawStatic(lp, hWnd, index);
WinFree(selection);
break;
case CB_SETCURSEL:
rc = (int)SendMessage(lp->ListBoxControl, LB_SETCURSEL, wParam, lParam);
if (rc == LB_ERR)
return CB_ERR;
len = (int)SendMessage(lp->ListBoxControl, LB_GETTEXTLEN, wParam, 0);
if (len <= 0)
return CB_ERR;
selection = (LPSTR)GdMalloc((UINT)len+1);
rc = (int)SendMessage(lp->ListBoxControl, LB_GETTEXT, wParam, (LPARAM)selection);
if (lp->EditControl)
rc = (int)SendMessage(lp->EditControl, WM_SETTEXT, 0, (LPARAM)selection);
else CBoxDrawStatic(lp, hWnd, wParam);
WinFree(selection);
return (LRESULT)wParam;
case CB_SETEXTENDEDUI:
lp->bExtended = (BOOL)wParam;
break;
case CB_SETITEMHEIGHT: /* TODO */
break;
case CB_SHOWDROPDOWN:
if ((lp->wStyle & 0xf) == CBS_SIMPLE)
return 1L;
if (wParam)
{
if (IS_SET(lp,CSF_CAPTUREACTIVE))
return 1L;
cp.x = ((lp->wStyle & 0xf) != CBS_DROPDOWNLIST) ? 5 : 0;
cp.y = lp->uHeight -1;
ClientToScreen(hWnd, &cp);
OffsetRect(&lp->ListBoxRect, cp.x - lp->ListBoxRect.left, cp.y - lp->ListBoxRect.top);
SetWindowPos(lp->ListBoxControl, 0,
cp.x, cp.y, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
SendMessage(lp->hWndParent,WM_COMMAND, GET_WM_COMMAND_MPS(lp->nID,hWnd,CBN_DROPDOWN));
fprintf(stderr," 1330: SetWindowPos(lp->ListBoxControl, , 0, 0, 0, 0,..)\n");
SetWindowPos(lp->ListBoxControl, HWND_TOP,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
CBoxCapture(hWnd, 1);
SET_STATE(lp,CSF_CAPTUREACTIVE);
}
else
{
if (!IS_SET(lp,CSF_CAPTUREACTIVE))
return 1L;
SendMessage(lp->hWndParent, WM_COMMAND, GET_WM_COMMAND_MPS(lp->nID,hWnd,CBN_CLOSEUP));
/* test: */
fprintf(stderr," 1343: (hide) SetWindowPos(lp->ListBoxControl, , 0, 0, 0, 0,..)\n");
SetWindowPos(lp->ListBoxControl, 0,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_HIDEWINDOW);
CBoxCapture(hWnd, 0);
CLEAR_STATE(lp, CSF_CAPTUREACTIVE);
}
return 1L;
/* *******************************************/
/* messages handled by the defwindowproc.... */
/* *******************************************/
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam);
}
return CB_OKAY;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -