Original, please indicate the source. -------------------------------------------------- sample: material: (1) the parameters typedef struct {DWORD lStructSize; HWND hwndOwner; HWND hInstance; COLORREF rgbResult; COLORREF * lpCustColors; DWORD Flags; LPARAM lCustData; LPCCHOOKPROC lpfnHook; LPCTSTR lpTemplateName;} CHOOSECOLOR, * LPCHOOSECOLOR; (2) API function BOOL ChooseColor (LPCHOOSECOLOR lpcc // initialization data); (3) a callback function for processing messages UINT_PTR cALLBACK CCHookProc (HWND hdlg, // handle to dialog box UINT uiMsg, // message identifier WPARAM wParam, // message parameter LPARAM lParam // Message parameter; method: (1), fill in the structure: ColorRef retcolor = RGB (255, 0, 0); ColorRef Cuscolor [16]; MEMSET (Cuscolor, 0, Sizeof (ColorRef) * 16);
Choosecolor cc = {sizeof (choiseColor), m_hwndparent, // parent window, set to null, is a desktop null, // a handle, not used, see MSDN RetColor, // If set cc_rgbinit is the initial The color value, and it is also a return value, returns the selected color cuscolor, // initial custom color array, set to null, if it is wrong, if it is not set, it seems to be a random value, I cleaned it into it. 0 CC_RGBINIT | CC_Fullopen | CC_ENABLEHOK | CC_AnyColor, // Red For setting your own message processing function null, (lpcchookProc) MycchookProc, // uses custom message processing function null}; (2), call Choosecolor (& CC); / / Click "OK" to return True, otherwise return false (3), custom message processing function hWnd halpha; // for text box INT XCURRENTSCROLL for the alpha value; // is used to save the current value of the scroll bar, and alpha value UINT_PTR CALLBACK CAColorDialog :: MyCCHookProc (HWND hdlg, // handle to dialog box UINT uiMsg, // message identifier WPARAM wParam, // message parameter LPARAM lParam // message parameter) {HWND hctrl; RECT rt; POINT pt; int Delta; // xdelta = new_pos - current_pos int xnewpos; // new position bool fscroll = false; switch (uimsg) {Case WM_INITDIALOG:
Assert (PTHIS); // Modify the size of the color dialog :: getWindowRect (hdlg, & rt); rt.bottom = 20; :: setWindowPos (HDLG, NULL, 0, 0, RT.right - RT.LEFT, RT .bottom - rt.top, swp_nomove; // Modify the location of the "Cancel" button hctrl = :: getdlgitem (hdlg, idcancel); :: getWindowRect (hctrl, & rt); pt.x = rt.Left; pt.y = rt.top; :: ScreenToClient (HDLG, & PT); Pt.x = 250; Pt.y = 22; :: setWindowPos (HCTRL, NULL, PT.X, Pt.y, 0, 0, SWP_NOSIZE) / / Modify the position of the "OK" button hctrl = :: getdlgitem (hdlg, idok); :: getWindowRect (hctrl, & rt); pt.x = rt.LEFT; pt.y = rt.top; :: screenToclient HDLG, & PT); Pt.x = 250; Pt.y = 22; :: setWindowPos (HCTRL, NULL, PT.X, Pt.Y, 0, 0, SWP_NOSIZE); // Add scrolling bar Pt.x - = 250; HCTRL = CreateWindowex (0L, "Scrollbar", "Alpha Channel", SBS_Topalign | SBS_LEFTALIGN | WS_CHILD | WS_VISIBLE | WS_TABSTOP, PT.X, Pt.y, 160, 20, HDLG, NULL, NULL, NULL; :: SetscrollRange (HCTRL, SB_CTL, 0, 255, TRUE); :: setscrollpos (HCTRL, SB_CTL, 128 , XCurrentscroll = 128; // Add a text box to display the current transparency Pt.x = 162; Halpha = CREATEWINDOWEX (0L, "Edit", "Alpha Value", // ES_READOONLY | ES_LEFT | ES_NUMBER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, PT.X, Pt.y, 36, 20, HDLG, NULL, NULL, NULL; PT.X - = 162; // Add a static text, the font is a bit problem Pt.y - = 22 HCTRL = CREATEWINDOWEX (0L, "static", "transparency (255 means complete opaque)", ws_child | ws_visible, pt.x, pt.y, 220, 20, hdlg, null, null, null;
:: setWindowText (PTHIS-> HALPHA, "128"); Break; Case WM_HSCROLL: {HCTRL = (hwnd) LPARAM; // Event processing of the scroll bar, taken from MSDN Switch (Loword (WPARAM)) {// keyboard pageup / down case SB_PAGEUP: xNewPos = xCurrentScroll - 20; break; case SB_PAGEDOWN: xNewPos = xCurrentScroll 20; break; // click the left and right arrows, or use the arrow keys on the keyboard case SB_LINEUP: xNewPos = xCurrentScroll - 1; break; Case SB_Linedown: XnewPos = Xcurrentscroll 1; Break; // Use the mouse to drag the slider (end) Case SB_thumbPosition: XnewPos = HiWord (wparam); Break; // Drag the slider (process) Case Sb_thumbTrack: xnewpos = HIWORD (wParam); break; default: xNewPos = xCurrentScroll;} xNewPos = max (0, xNewPos); xNewPos = min (255, xNewPos); if (xNewPos == xCurrentScroll) break; fScroll = TRUE; Delta = xNewPos - xCurrentScroll Xcurrentscroll = xnewpos; // reset the scroll bar. Setscrollpos (HCTRL, SB_CTL, Xcurrentscroll, fscroll); char STR [4]; strset (STR, 0); s Printf (STR, "% D", xcurrentscroll ;: setwindowtext (halpha, str); break;} / * case wm_command: if (wparam) == idok) // Determine button {// trace ("IDOK CLICK "); char str []; :: getWindowText (Halpha, STR, 3); ATOI (STR);} * /} // Returns 0, indicating that the default message processing function continues to process // return non-0 It will be very depressed 50;} // ---------------------------------------- ------------------ This will use ccolordialog, you can use subclassics, there is an example on CodeProject http://www.codeproject.com/ Dialog / SELECT_ALL_BUTTON.ASP / / ------------------------------------------- ---------------- In addition, I have tried to package into a class, I have encountered some problems: