📄 winctrls.c
字号:
SelectObject(hdc, oldfont); ReleaseDC(cp->hwnd, hdc); if (lines) *lines = nlines; return ret;}/* * A single standalone static text control. */void statictext(struct ctlpos *cp, char *text, int lines, int id){ RECT r; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = STATICHEIGHT * lines; cp->ypos += r.bottom + GAPBETWEEN; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_LEFTNOWORDWRAP, 0, text, id);}/* * An owner-drawn static text control for a panel title. */void paneltitle(struct ctlpos *cp, int id){ RECT r; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = TITLEHEIGHT; cp->ypos += r.bottom + GAPBETWEEN; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_OWNERDRAW, 0, NULL, id);}/* * A button on the right hand side, with a static to its left. */void staticbtn(struct ctlpos *cp, char *stext, int sid, char *btext, int bid){ const int height = (PUSHBTNHEIGHT > STATICHEIGHT ? PUSHBTNHEIGHT : STATICHEIGHT); RECT r; int lwid, rwid, rpos; rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4; lwid = rpos - 2 * GAPBETWEEN; rwid = cp->width + GAPBETWEEN - rpos; r.left = GAPBETWEEN; r.top = cp->ypos + (height - STATICHEIGHT) / 2; r.right = lwid; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = rpos; r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2; r.right = rwid; r.bottom = PUSHBTNHEIGHT; doctl(cp, r, "BUTTON", BS_NOTIFY | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 0, btext, bid); cp->ypos += height + GAPBETWEEN;}/* * A simple push button. */void button(struct ctlpos *cp, char *btext, int bid, int defbtn){ RECT r; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = PUSHBTNHEIGHT; /* Q67655: the _dialog box_ must know which button is default * as well as the button itself knowing */ if (defbtn && cp->hwnd) SendMessage(cp->hwnd, DM_SETDEFID, bid, 0); doctl(cp, r, "BUTTON", BS_NOTIFY | WS_CHILD | WS_VISIBLE | WS_TABSTOP | (defbtn ? BS_DEFPUSHBUTTON : 0) | BS_PUSHBUTTON, 0, btext, bid); cp->ypos += PUSHBTNHEIGHT + GAPBETWEEN;}/* * Like staticbtn, but two buttons. */void static2btn(struct ctlpos *cp, char *stext, int sid, char *btext1, int bid1, char *btext2, int bid2){ const int height = (PUSHBTNHEIGHT > STATICHEIGHT ? PUSHBTNHEIGHT : STATICHEIGHT); RECT r; int lwid, rwid1, rwid2, rpos1, rpos2; rpos1 = GAPBETWEEN + (cp->width + GAPBETWEEN) / 2; rpos2 = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4; lwid = rpos1 - 2 * GAPBETWEEN; rwid1 = rpos2 - rpos1 - GAPBETWEEN; rwid2 = cp->width + GAPBETWEEN - rpos2; r.left = GAPBETWEEN; r.top = cp->ypos + (height - STATICHEIGHT) / 2; r.right = lwid; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = rpos1; r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2; r.right = rwid1; r.bottom = PUSHBTNHEIGHT; doctl(cp, r, "BUTTON", BS_NOTIFY | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 0, btext1, bid1); r.left = rpos2; r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2; r.right = rwid2; r.bottom = PUSHBTNHEIGHT; doctl(cp, r, "BUTTON", BS_NOTIFY | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 0, btext2, bid2); cp->ypos += height + GAPBETWEEN;}/* * An edit control on the right hand side, with a static to its left. */static void staticedit_internal(struct ctlpos *cp, char *stext, int sid, int eid, int percentedit, int style){ const int height = (EDITHEIGHT > STATICHEIGHT ? EDITHEIGHT : STATICHEIGHT); RECT r; int lwid, rwid, rpos; rpos = GAPBETWEEN + (100 - percentedit) * (cp->width + GAPBETWEEN) / 100; lwid = rpos - 2 * GAPBETWEEN; rwid = cp->width + GAPBETWEEN - rpos; r.left = GAPBETWEEN; r.top = cp->ypos + (height - STATICHEIGHT) / 2; r.right = lwid; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = rpos; r.top = cp->ypos + (height - EDITHEIGHT) / 2; r.right = rwid; r.bottom = EDITHEIGHT; doctl(cp, r, "EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL | style, WS_EX_CLIENTEDGE, "", eid); cp->ypos += height + GAPBETWEEN;}void staticedit(struct ctlpos *cp, char *stext, int sid, int eid, int percentedit){ staticedit_internal(cp, stext, sid, eid, percentedit, 0);}void staticpassedit(struct ctlpos *cp, char *stext, int sid, int eid, int percentedit){ staticedit_internal(cp, stext, sid, eid, percentedit, ES_PASSWORD);}/* * A drop-down list box on the right hand side, with a static to * its left. */void staticddl(struct ctlpos *cp, char *stext, int sid, int lid, int percentlist){ const int height = (COMBOHEIGHT > STATICHEIGHT ? COMBOHEIGHT : STATICHEIGHT); RECT r; int lwid, rwid, rpos; rpos = GAPBETWEEN + (100 - percentlist) * (cp->width + GAPBETWEEN) / 100; lwid = rpos - 2 * GAPBETWEEN; rwid = cp->width + GAPBETWEEN - rpos; r.left = GAPBETWEEN; r.top = cp->ypos + (height - STATICHEIGHT) / 2; r.right = lwid; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = rpos; r.top = cp->ypos + (height - EDITHEIGHT) / 2; r.right = rwid; r.bottom = COMBOHEIGHT*4; doctl(cp, r, "COMBOBOX", WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid); cp->ypos += height + GAPBETWEEN;}/* * A combo box on the right hand side, with a static to its left. */void staticcombo(struct ctlpos *cp, char *stext, int sid, int lid, int percentlist){ const int height = (COMBOHEIGHT > STATICHEIGHT ? COMBOHEIGHT : STATICHEIGHT); RECT r; int lwid, rwid, rpos; rpos = GAPBETWEEN + (100 - percentlist) * (cp->width + GAPBETWEEN) / 100; lwid = rpos - 2 * GAPBETWEEN; rwid = cp->width + GAPBETWEEN - rpos; r.left = GAPBETWEEN; r.top = cp->ypos + (height - STATICHEIGHT) / 2; r.right = lwid; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = rpos; r.top = cp->ypos + (height - EDITHEIGHT) / 2; r.right = rwid; r.bottom = COMBOHEIGHT*10; doctl(cp, r, "COMBOBOX", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWN | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid); cp->ypos += height + GAPBETWEEN;}/* * A static, with a full-width drop-down list box below it. */void staticddlbig(struct ctlpos *cp, char *stext, int sid, int lid){ RECT r; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); cp->ypos += STATICHEIGHT; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = COMBOHEIGHT*4; doctl(cp, r, "COMBOBOX", WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid); cp->ypos += COMBOHEIGHT + GAPBETWEEN;}/* * A big multiline edit control with a static labelling it. */void bigeditctrl(struct ctlpos *cp, char *stext, int sid, int eid, int lines){ RECT r; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = STATICHEIGHT; cp->ypos += r.bottom + GAPWITHIN; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = EDITHEIGHT + (lines - 1) * STATICHEIGHT; cp->ypos += r.bottom + GAPBETWEEN; doctl(cp, r, "EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE, WS_EX_CLIENTEDGE, "", eid);}/* * A list box with a static labelling it. */void listbox(struct ctlpos *cp, char *stext, int sid, int lid, int lines, int multi){ RECT r; if (stext != NULL) { r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = STATICHEIGHT; cp->ypos += r.bottom + GAPWITHIN; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); } r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = LISTHEIGHT + (lines - 1) * LISTINCREMENT; cp->ypos += r.bottom + GAPBETWEEN; doctl(cp, r, "LISTBOX", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY | LBS_HASSTRINGS | LBS_USETABSTOPS | (multi ? LBS_MULTIPLESEL : 0), WS_EX_CLIENTEDGE, "", lid);}/* * A tab-control substitute when a real tab control is unavailable. */void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id){ const int height = (COMBOHEIGHT > STATICHEIGHT ? COMBOHEIGHT : STATICHEIGHT); RECT r; int bigwid, lwid, rwid, rpos; static const int BIGGAP = 15; static const int MEDGAP = 3; bigwid = cp->width + 2 * GAPBETWEEN - 2 * BIGGAP; cp->ypos += MEDGAP; rpos = BIGGAP + (bigwid + BIGGAP) / 2; lwid = rpos - 2 * BIGGAP; rwid = bigwid + BIGGAP - rpos; r.left = BIGGAP; r.top = cp->ypos + (height - STATICHEIGHT) / 2; r.right = lwid; r.bottom = STATICHEIGHT; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); r.left = rpos; r.top = cp->ypos + (height - COMBOHEIGHT) / 2; r.right = rwid; r.bottom = COMBOHEIGHT * 10; doctl(cp, r, "COMBOBOX", WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS, WS_EX_CLIENTEDGE, "", lid); cp->ypos += height + MEDGAP + GAPBETWEEN; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = 2; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, "", s2id);}/* * A static line, followed by an edit control on the left hand side * and a button on the right. */void editbutton(struct ctlpos *cp, char *stext, int sid, int eid, char *btext, int bid){ const int height = (EDITHEIGHT > PUSHBTNHEIGHT ? EDITHEIGHT : PUSHBTNHEIGHT); RECT r; int lwid, rwid, rpos; r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = STATICHEIGHT; cp->ypos += r.bottom + GAPWITHIN; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); rpos = GAPBETWEEN + 3 * (cp->width + GAPBETWEEN) / 4; lwid = rpos - 2 * GAPBETWEEN; rwid = cp->width + GAPBETWEEN - rpos; r.left = GAPBETWEEN; r.top = cp->ypos + (height - EDITHEIGHT) / 2; r.right = lwid; r.bottom = EDITHEIGHT; doctl(cp, r, "EDIT", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, WS_EX_CLIENTEDGE, "", eid); r.left = rpos; r.top = cp->ypos + (height - PUSHBTNHEIGHT) / 2; r.right = rwid; r.bottom = PUSHBTNHEIGHT; doctl(cp, r, "BUTTON", BS_NOTIFY | WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON, 0, btext, bid); cp->ypos += height + GAPBETWEEN;}/* * A special control for manipulating an ordered preference list * (eg. for cipher selection). * XXX: this is a rough hack and could be improved. */void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines, char *stext, int sid, int listid, int upbid, int dnbid){ const static int percents[] = { 5, 75, 20 }; RECT r; int xpos, percent = 0, i; int listheight = LISTHEIGHT + (lines - 1) * LISTINCREMENT; const int BTNSHEIGHT = 2*PUSHBTNHEIGHT + GAPBETWEEN; int totalheight, buttonpos; /* Squirrel away IDs. */ hdl->listid = listid; hdl->upbid = upbid; hdl->dnbid = dnbid; /* The static label. */ if (stext != NULL) { r.left = GAPBETWEEN; r.top = cp->ypos; r.right = cp->width; r.bottom = STATICHEIGHT; cp->ypos += r.bottom + GAPWITHIN; doctl(cp, r, "STATIC", WS_CHILD | WS_VISIBLE, 0, stext, sid); } if (listheight > BTNSHEIGHT) { totalheight = listheight; buttonpos = (listheight - BTNSHEIGHT) / 2; } else { totalheight = BTNSHEIGHT; buttonpos = 0; } for (i=0; i<3; i++) { int left, wid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -