📄 propsheet.c
字号:
switch (message) { case MSG_CREATE: { if (!(pData = calloc (1, sizeof (PROPSHEETDATA)))) return -1; pCtrl->dwAddData2 = (DWORD)pData; pData->head_rc.top = 0; pData->head_rc.left = 0; pData->head_rc.right = 0; pData->head_rc.bottom = GetMainWinMetrics (MWM_ICONY) + 4 + _ICON_OFFSET * 2; break; } /* make the client size same as window size */ case MSG_SIZECHANGED: { const RECT* rcWin = (RECT*)wParam; RECT* rcClient = (RECT*)lParam; *rcClient = *rcWin; pData->head_rc.right = RECTWP (rcClient); recalc_tab_widths (hwnd, pData, pCtrl->dwStyle); resize_children (pData, rcClient); InvalidateRect (hwnd, &pData->head_rc, TRUE); return 1; } case MSG_DESTROY: { PPROPPAGE page, temp; page = pData->head; while (page) { temp = page->next; destroy_page (page); free (page); page = temp; } free (pData); break; } case MSG_GETDLGCODE: return DLGC_WANTTAB | DLGC_WANTARROWS; case PSM_SHEETCMD: { int index = 0; PPROPPAGE page; page = pData->head; while (page) { if (SendMessage (page->hwnd, MSG_SHEETCMD, wParam, lParam)) /* when encounter an error, return page index plus 1. */ return index + 1; index++; page = page->next; } /* success, return 0 */ return 0; } /* set the active page. */ case PSM_SETACTIVEINDEX: { PPROPPAGE page; if ((page = get_page (pData, wParam)) && page != pData->active) { show_hide_page (pData->active, SW_HIDE); pData->active = page; NotifyParent (hwnd, pCtrl->id, PSN_ACTIVE_CHANGED); show_hide_page (page, SW_SHOW); InvalidateRect (hwnd, &pData->head_rc, TRUE); return PS_OKAY; } return PS_ERR; } /* Retrieves the index of the active page of the property sheet. */ case PSM_GETACTIVEINDEX: { int index = 0; PPROPPAGE page; page = pData->head; while (page) { if (page == pData->active) return index; index ++; page = page->next; } return PS_ERR; } case PSM_GETACTIVEPAGE: { if (pData->active) return pData->active->hwnd; else return HWND_INVALID; } /* Returns the page handle by index */ case PSM_GETPAGE: { int index = 0; PPROPPAGE page; page = pData->head; while (page) { if (index == wParam) return page->hwnd; index ++; page = page->next; } return HWND_INVALID; } /* Returns the page index by handle */ case PSM_GETPAGEINDEX: { int index = 0; PPROPPAGE page; page = pData->head; while (page) { if (page->hwnd == wParam) return index; index ++; page = page->next; } return PS_ERR; } /* Retrieves the number of pages in the property sheet */ case PSM_GETPAGECOUNT: return pData->page_count; case PSM_GETTITLELENGTH: { int len = PS_ERR; PPROPPAGE page; if ((page = get_page (pData, wParam))) { len = strlen (page->title); } return len; } case PSM_GETTITLE: { char* buffer = (char*)lParam; PPROPPAGE page; if ((page = get_page (pData, wParam))) { strcpy (buffer, page->title); return PS_OKAY; } return PS_ERR; } case PSM_SETTITLE: { BOOL rc = PS_ERR; char* buffer = (char*)lParam; PPROPPAGE page; if ((page = get_page (pData, wParam))) { rc = set_page_title (page, buffer); recalc_tab_widths (hwnd, pData, pCtrl->dwStyle); InvalidateRect (hwnd, &pData->head_rc, TRUE); } return rc; } case PSM_ADDPAGE: { int index; PPROPPAGE page; if ((pData->head_rc.right / (pData->page_count + 1)) < _MIN_TAB_WIDTH) return PS_ERR; if (!(page = calloc (1, sizeof (PROPPAGE)))) { return PS_ERR; } if (!create_page (hwnd, pData, page, (DLGTEMPLATE *)wParam, (WNDPROC)lParam)) { free (page); return PS_ERR; } index = append_page (pData, page); if (pData->active) show_hide_page (pData->active, SW_HIDE); pData->active = page; NotifyParent (hwnd, pCtrl->id, PSN_ACTIVE_CHANGED); show_hide_page (page, SW_SHOW); recalc_tab_widths (hwnd, pData, pCtrl->dwStyle); InvalidateRect (hwnd, &pData->head_rc, TRUE); return index; } case PSM_REMOVEPAGE: { PPROPPAGE page; if ((page = get_page (pData, wParam))) { remove_page (pData, page); destroy_page (page); free (page); recalc_tab_widths (hwnd, pData, pCtrl->dwStyle); } else return PS_ERR; if (pData->active == page) { pData->active = pData->head; NotifyParent (hwnd, pCtrl->id, PSN_ACTIVE_CHANGED); if (pData->active) show_hide_page (pData->active, SW_SHOW); } InvalidateRect (hwnd, &pData->head_rc, TRUE); return PS_OKAY; } case MSG_LBUTTONDOWN: { int x, y; RECT title_rc = {0, 0, 0, pData->head_rc.bottom}; PPROPPAGE page; x = LOSWORD(lParam); y = HISWORD(lParam); page = pData->head; while (page) { title_rc.left = title_rc.right; title_rc.right = title_rc.left + page->width; if (PtInRect (&title_rc, x, y) && page != pData->active) { show_hide_page (pData->active, SW_HIDE); pData->active = page; NotifyParent (hwnd, pCtrl->id, PSN_ACTIVE_CHANGED); show_hide_page (page, SW_SHOW); InvalidateRect (hwnd, &pData->head_rc, TRUE); break; } page = page->next; } break; } case MSG_KEYDOWN: { PPROPPAGE page, new_active = NULL; if (pData->head == NULL) break;#if 0 if (pData->active && SendMessage (pData->active->hwnd, MSG_GETDLGCODE, 0, 0L) & DLGC_WANTARROWS) { break; }#else if (!(lParam & KS_CTRL)) break;#endif switch (LOWORD (wParam)) { case SCANCODE_CURSORBLOCKDOWN: case SCANCODE_CURSORBLOCKRIGHT: new_active = pData->active->next; if (new_active == NULL) new_active = pData->head; break; case SCANCODE_CURSORBLOCKUP: case SCANCODE_CURSORBLOCKLEFT: page = pData->head; if (pData->head == pData->active) { while (page && page->next) { page = page->next; } } else { while (page) { if (page->next == pData->active) break; page = page->next; } } new_active = page; break; } if (new_active == NULL) break; show_hide_page (pData->active, SW_HIDE); pData->active = new_active; NotifyParent (hwnd, pCtrl->id, PSN_ACTIVE_CHANGED); show_hide_page (new_active, SW_SHOW); InvalidateRect (hwnd, &pData->head_rc, TRUE); return 0; } case MSG_NCPAINT: case MSG_ERASEBKGND: return 0; case MSG_PAINT: { int x, ty, by; HDC hdc; RECT title_rc = {0, 0, 0, pData->head_rc.bottom}; int text_extent; PPROPPAGE page; hdc = BeginPaint (hwnd);#ifdef _FLAT_WINDOW_STYLE DrawFlatControlFrameEx (hdc, 0, pData->head_rc.bottom - 2, pData->head_rc.right, pCtrl->bottom - pCtrl->top, PIXEL_invalid, 1, TRUE);#else Draw3DUpThickFrame (hdc, 0, pData->head_rc.bottom - 2, pData->head_rc.right, pCtrl->bottom - pCtrl->top, PIXEL_invalid);#endif SetBrushColor (hdc, GetWindowElementColor (BKC_CONTROL_DEF)); FillBox (hdc, 0, 0, pData->head_width, pData->head_rc.bottom - 3); page = pData->head; while (page) { title_rc.left = title_rc.right; title_rc.right = title_rc.left + page->width; SelectClipRect (hdc, &title_rc); x = title_rc.left + _ICON_OFFSET; ty = title_rc.top; if (page != pData->active) { ty += 2; by = title_rc.bottom - 2;#if defined(_FLAT_WINDOW_STYLE) && !defined(_GRAY_SCREEN) SetBrushColor (hdc, PIXEL_lightgray); FillBox (hdc, title_rc.left, ty, title_rc.right - title_rc.left, by - 2);#endif } else { by = title_rc.bottom;#if defined(_FLAT_WINDOW_STYLE) && !defined(_GRAY_SCREEN) ty += 1; SetBrushColor (hdc, PIXEL_lightwhite);#endif FillBox (hdc, title_rc.left, ty, title_rc.right - title_rc.left, by); }#ifdef _FLAT_WINDOW_STYLE#ifdef _GRAY_SCREEN SetPenColor (hdc, GetWindowElementColor (WEC_FLAT_BORDER)); MoveTo (hdc, title_rc.left + 1, by); LineTo (hdc, title_rc.left + 1, ty); LineTo (hdc, title_rc.right - 3, ty); LineTo (hdc, title_rc.right - 1, ty + 2); LineTo (hdc, title_rc.right - 1, by);#else SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER)); if (page == pData->head) { MoveTo (hdc, title_rc.left, by); LineTo (hdc, title_rc.left, ty + 2); } MoveTo (hdc, title_rc.left, ty + 2); LineTo (hdc, title_rc.left + 2, ty); LineTo (hdc, title_rc.right - 3, ty); LineTo (hdc, title_rc.right - 1, ty + 2); SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_OUTER)); LineTo (hdc, title_rc.right - 1, by - 1);#endif#else SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER)); MoveTo (hdc, title_rc.left, by); LineTo (hdc, title_rc.left, ty + 2); LineTo (hdc, title_rc.left + 2, ty); LineTo (hdc, title_rc.right - 3, ty); LineTo (hdc, title_rc.right - 1, ty + 2); SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_OUTER)); LineTo (hdc, title_rc.right - 1, by); SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_RIGHT_OUTER)); MoveTo (hdc, title_rc.left + 1, by); LineTo (hdc, title_rc.left + 1, ty + 3); LineTo (hdc, title_rc.left + 3, ty + 1); LineTo (hdc, title_rc.right - 4, ty + 1); LineTo (hdc, title_rc.right - 2, ty + 3); SetPenColor(hdc, GetWindowElementColor (WEC_3DFRAME_LEFT_INNER)); LineTo (hdc, title_rc.right - 2, by);#endif ty += _ICON_OFFSET + 2; text_extent = RECTW (title_rc) - _ICON_OFFSET * 2; if (page->icon) { DrawIcon (hdc, x, ty, GetMainWinMetrics (MWM_ICONX), GetMainWinMetrics (MWM_ICONY), page->icon); x += GetMainWinMetrics (MWM_ICONX); x += _GAP_ICON_TEXT; text_extent -= GetMainWinMetrics (MWM_ICONX) + _GAP_ICON_TEXT; }#if defined(_FLAT_WINDOW_STYLE) && !defined(_GRAY_SCREEN) if (page != pData->active) { SetBkColor (hdc, PIXEL_lightgray); } else { SetBkColor (hdc, PIXEL_lightwhite); }#else SetBkColor (hdc, GetWindowElementColor (BKC_CONTROL_DEF));#endif { SIZE size; int eff_chars, eff_len; eff_len = GetTextExtentPoint (hdc, page->title, strlen(page->title), text_extent, &eff_chars, NULL, NULL, &size); TextOutLen (hdc, x, ty, page->title, eff_len); } page = page->next; } EndPaint (hwnd, hdc); return 0; } default: break; } return DefaultControlProc (hwnd, message, wParam, lParam);}#endif /* _CTRL_PROPSHEET*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -