c++ - Win32-Based Applications, trying to update the text of the label -


this code displays window text label saying: "please enter number", , button.

when click button should replace text " text ". works, writes/prints new text on top of first text. overlapping.

i want string of text change instead of writing on first one, don't know how i'm new windows application development.

please me out guys.

the whole source is:

#include <windows.h> #include <iostream>   using namespace std;   enum { id_label = 1,id_button0};  static  hwnd static_label, button0;  hdc          hdc; hbrush  newbrush; hinstance g_hinst;   lresult callback wndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam);   int winapi winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd) {     lpctstr classname = text("myclass");     wndclassex wc;      wc.cbsize        = sizeof(wc);     wc.style         = cs_hredraw | cs_vredraw;     wc.cbwndextra    = 0;     wc.cbclsextra    = 0;     wc.lpfnwndproc   = wndproc;     wc.hinstance     = hinstance;     wc.lpszmenuname  = null;     wc.lpszclassname = text("myclass");       wc.hbrbackground  = (hbrush)(createsolidbrush(rgb(48, 38, 88)));      wc.hicon             = loadicon(null, idi_application);     wc.hiconsm           = loadicon(null, idi_application);     wc.hcursor           = loadcursor(null, idc_arrow);      if(!registerclassex(&wc))     {         messagebox(null, text("error! failed register class!"), text("fatal error!"), mb_iconerror | mb_ok);         return 1;     }      hwnd hwnd = createwindowex(0, text("myclass"), text("window title"), ws_overlappedwindow, 450, 100, 500 + 7, 500 + 33 , null, null, hinstance, null);      if(!hwnd)     {         messagebox(null, text("error! failed create window!"), text("fatal error!"), mb_iconerror | mb_ok);          return true;     }        showwindow(hwnd, nshowcmd);                     updatewindow(hwnd);       msg msg;      while(getmessage(&msg, null, 0, 0) > 0)     {         translatemessage(&msg);         dispatchmessage(&msg);     }      return (int)msg.wparam; }    lresult callback wndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam) {     switch(msg)     {         case wm_paint:         {          }          case wm_ctlcolorstatic:         {            setbkmode((hdc) wparam, transparent);                     return (long) getstockobject(null_brush);     }      break;      case wm_create:     {         static_label = createwindow(l"static",l"please enter number",ws_child | ws_visible,35,15,175,25,hwnd,0, g_hinst,0);          button0 = createwindow(l"button",l"ok",bs_pushbutton | ws_child | ws_visible ,80,220,35,35,hwnd,(hmenu)id_button0,g_hinst,0);          }        break;        case wm_command: //command child windows , menus under message        switch(wparam) //the id wparam       {          case id_button0: //check our button id          {              setwindowtext(static_label,l"text");               break;          }       }//switch.     break;    case wm_destroy:           postquitmessage(0);          break; // pass defwindowproc(...)        case wm_close:          destroywindow(hwnd);          break;    }       return defwindowproc(hwnd, msg, wparam, lparam);     } 

the problem here:

case wm_ctlcolorstatic: {    setbkmode((hdc) wparam, transparent);            return (long) getstockobject(null_brush); } 

this code tells static control draw text without background color , not repaint background. new text drawn on top of old text instead of on fresh background.

if need custom background show through, you'll have invalidate part of underlying parent window , possibly use ws_ex_transparent ensure child static control drawn last. way, time tries draw new text, fresh background should painted.

note means cannot use ws_clipchildren on underlying parent window, can increase flicker when things redraw.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -