c++ - WinAPI. How to redraw window which has no background? -


hi have wndclassex structure has data:

m_wndclass.cbsize = sizeof(wndclassex); m_wndclass.style = cs_noclose; m_wndclass.lpfnwndproc = wndproc; m_wndclass.cbclsextra = 0; m_wndclass.cbwndextra = 0; m_wndclass.hinstance = getmodulehandle(null); m_wndclass.hicon = null; m_wndclass.hcursor = loadcursor(null, idc_arrow); m_wndclass.hbrbackground = null; m_wndclass.lpszmenuname = null; m_wndclass.lpszclassname = checkbox::checkbox_class.c_str();  m_wndclass.hiconsm = null; 

i need have window without background, because need draw text on parent window , text may color.

drawing works fine, code drawing:

case wm_paint: {     paintstruct ps;     hdc dc = beginpaint(window, &ps);      if (!classinfo->m_text.empty())     {         hdc wdc = getdc(window);          setbkmode(wdc,transparent);         drawtext(wdc, classinfo->m_text.c_str(), -1, &classinfo->m_textrect, dt_center | dt_vcenter | dt_singleline | dt_noclip);         releasedc(window, wdc);      }      endpaint(window, &ps);     break; } 

however have method change text of label:

void checkbox::settext(const string& text) {     m_text = text;     settextrectsize();   //calculates size of rect      if (m_window != null)         invalidaterect(m_window, null, true); } 

after create window label see label, if want change text on it, doesn't change (i need manualy resize window , changes after that). hadn't have problem @ time when used have colored background, example window class had this:

m_wndclass.hbrbackground = hbrush(color_3dface+1); 

i want ask, how update window which, has no background.

edit: have tried stuff

fillrect(dc, &rect, (hbrush)getstockobject(null_brush));

also tried change window procedure:

case wm_ctlcolorstatic: {     hdc hdc = (hdc) wp;      setbkmode (hdc, transparent);     return (lresult)getstockobject(null_brush); } 

and result draw new text on previous, after setting text some longer text part of label becomes corupted! see this after resizing main window label becomes readable.

your code doesn't set device context's text foreground color drawtext(), although default black. see settextcolor().

setbkmode(..., transparent) sets background color/mode drawtext() rect, not entire window.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -