Archived

This topic is now archived and is closed to further replies.

Zeblar Nagrim

Alternatives for void pointers

Recommended Posts

Please take a look at this code:
  

...

enum ControlType
{
 BUTTON=0,
 CHECK_BUTTON,
 RADIO_BUTTON,
 LABEL,
 SCROLLBAR,
 TEXTBOX,
 LISTBOX,
 COMBOBOX
};

...

LRESULT CGUI::MessageProc(int Message, WPARAM wParam, LPARAM lParam)
{
  static void* l_ptCtrlInFocus=NULL;
  static ControlType l_eCtrlInFocusType;

  ...

  CGUIListbox* pListBox = FindListbox(l_tMousePos);
  if(pListBox != NULL)
  {
    l_ptCtrlInFocus = pListBox;
    l_eCtrlInFocusType = LISTBOX;
  }

  ...

  CGUITextbox* pTextBox = FindTextbox(l_tMousePos);
  if(pTextBox != NULL)
  {
    l_ptCtrlInFocus = pTextBox;
    l_eCtrlInFocusType = TEXTBOX;
  }

  ...

  switch(LOWORD(wParam))
  {

    ...

    case VK_UP:
    {
       if(l_ptCtrlInFocus != NULL)
       {
          switch(l_eCtrlInFocusType)
          {

          ...

          case LISTBOX:
             CGUIListbox* pListBox = (CGUIListbox*) l_ptCtrlInFocus;
             pListBox->OnKeyDown(LOWORD(wParam)); 
             break;

          ...

          case TEXTBOX:
             CGUITextbox* pTextBox = (CGUITextbox*) l_ptCtrlInFocus;
             pTextBox->OnKeyDown(LOWORD(wParam)); 
             break;
          ...
          }
       }
    }

   ...

  }

 ...
}

  
This code is ugly. I want to use a diffrent method. Something more OO. Any idea? Zeblar Nagrim, Lord of Chaos

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
Have a CControl class and derive all your other classes from that. Then use virtual functions to dispatch the correct method.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!



Thanks!

I will try that as soon as possible.



Zeblar Nagrim, Lord of Chaos

Share this post


Link to post
Share on other sites