WNDCLASSEX

2004-09-06
2004-09-08
  • moswald0000
    moswald0000
    2004-09-06

    What's the best way to associate a unique WNDCLASSEX with my windows?  When I change one to have a gray background brush (using SetClassLongPtr or by modifying it before creation), I end up changing ALL my window's WNDCLASSEX objects.  I would even suggest making every class instance have its own unique WNDCLASSEX by default.  Even if they have the same values, it would be easier to modify that way.

    --Also, could you add a function to window_class_info that will allow me to change the default brush?  I'm currently using a const_cast hack to get around the fact that the only way to get at it is by using raw_info().

     
    • John Torjo
      John Torjo
      2004-09-08

      The simplest way is to use the window_class_info() wrapper. Then, override def_create_info() and register your class there.

      It's like this:
      // custom_wnd.h
      struct custom_wnd : wnd_extend<window_base,custom_wnd> {
          static win32::gui::create_info def_create_info();
          // ... other members
      };

      // custom_wnd.cpp
      struct custom_wnd_handler : event_handler<custom_wnd_handler, window_base, custom_wnd> {
          // ... handle events, the usual way
      };

      create_info custom_wnd::def_create_info() {
          ::RegisterClassEx( &window_class_info().wnd_class_name("My Custom Window").raw_info() );
          return create_info().class_name( "My Custom Window")
                  .style( WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_TABSTOP);
      }

      // ... other members

      As for the new function, it should be spelled like this:
      // in window_class_params.hpp
          window_class_info & bg(HBRUSH h) {
              m_info.hbrBackground = h;
              return *this;
          }

      Sorry for forgetting to add this in the first place. I've added it now, and it'll be present in the next version - which should be online in a few days - hopefully by the end of this week.

      Best,
      John