Most of the time, the style of CComboBox is chosen by design time, but sometimes it needs to be changed dynamically by the program, and we find that the ModifyStyle function that comes with it does not work: GetWindowLong gets its style and then joins or removes our target style again:: SetWindowLong We find it doesn't work, so how do you change its style dynamically?
We know that there is a create function in CComboBox for creating the CComboBox instance, so we can change its style dynamically using the Create method, but we need to destroy the original window before the create, the code is as follows:
CRect Rrect; UINT UnID=0; DWORD Dwstyleex=0; CFont* pfont=NULL; Pfont=M_rghs.getfont (); Dwstyleex=M_rghs.getexstyle (); //Remove the original cbs_dropdownlist style, add Cbs_dropdown styleDwstyleex= Dwstyleex & ~cbs_dropdownlist |Cbs_dropdown; M_rghs.getwindowrect (&rrect); ScreenToClient (&rrect); UnID=m_rghs.getdlgctrlid (); M_rghs.destroywindow (); M_rghs.create (Dwstyleex, Rrect, This, UnID); M_rghs.showwindow (sw_show); M_rghs.setfont (Pfont, TRUE) ;
Go VC Dynamic Change CComboBox style