Author Topic: Somewhat off topic: Windows Programming Issues  (Read 914 times)

0 Members and 1 Guest are viewing this topic.

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic: Windows Programming Issues
Howdy... I am currently working with a team to develop a MMORPG game. We are working on the client-side application and I was writing a windows wrapper class complete with a message router/handler (NOTE: HEAVY WINDOWS!!!). I am running into problems and invite anyone who can help to visit this post on gamedev:

http://www.gamedev.net/community/forums/topic.asp?topic_id=222144
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D

 

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic: Windows Programming Issues
Here is any code that is relevant:


Code: [Select]

void CWND::CreateWND(int showCmd, HINSTANCE instance)
{
  DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style

HWND hwnd;
  WNDCLASSEX wc;
 
  RECT windowRect; // Grabs Rectangle Upper Left / Lower Right Values
windowRect.left = (long)0; // Set Left Value To 0
windowRect.right = (long)m_width; // Set Right Value To Requested Width
windowRect.top = (long)0; // Set Top Value To 0
windowRect.bottom = (long)m_height; // Set Bottom Value To Requested Height
 
  // Setup the windows class
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = this->MessageRouter; // window procedure
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = instance;
  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);  // default app icon
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);    // default cursor
  wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);; // windows default black
  wc.lpszClassName = m_className; // class name
  wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);  
 
  // register the class
  if (!RegisterClassEx(&wc))
        { MessageBox(NULL, "Class Registration Failed!", "ERROR!", MB_OK | MB_ICONEXCLAMATION); }
  else
  {
    // save the class
    m_wndClass = wc;
    p_log->Log("Window class registered\n");
  }
   
  if (m_fullscreen) // Attempt Fullscreen Mode?
{
    DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize = sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = m_width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = m_height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = m_bpp;  // Selected Bits Per Pixel
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
 // If The Mode Fails, Offer Two Options.  Quit Or Run In A Window.
if (MessageBox(NULL, "The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Using windowed mode instead.",
          "ERROR", MB_OK | MB_ICONEXCLAMATION) == IDOK)
{
  m_fullscreen = false;
}
}
}

if (m_fullscreen) // Are We Still In Fullscreen Mode?
{
 dwExStyle = WS_EX_APPWINDOW; // Window Extended Style
dwStyle = WS_POPUP; // Windows Style
}
else
{
    dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle = WS_OVERLAPPEDWINDOW; // Windows Style
}

// Adjust Window To True Requested Size
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
 
  // Create the window
  hwnd = CreateWindowEx(dwExStyle, m_className, m_className, WS_OVERLAPPEDWINDOW |
      WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, m_width, m_height, NULL, NULL,
      instance, this);                    
 
  // Check to see if window creation failed
  if(!hwnd)
      { MessageBox(NULL, "Window Creation Failed!", "ERROR!", MB_OK | MB_ICONEXCLAMATION); }
  else
  {
    // Show and update the window
    ShowWindow(hwnd, showCmd);
    UpdateWindow(hwnd);
 
    p_log->Log("Window created\n");
  }
}


Code: [Select]

// Class message router: this function is static and will rout messages
// to the correct class instance
LRESULT CALLBACK CWND::MessageRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  CWND *p_wnd = 0;
   
  if(msg == WM_CREATE)
  {
    p_log->Log("msg == WM_CREATE\n");
  }
  else if(msg == WM_NCCALCSIZE)
  {
    p_log->Log("msg == WM_NCCALCSIZE\n");
  }
  else if(msg == WM_NCCREATE)
  {
    p_log->Log("msg == WM_NCCREATE\n");
   
    // retrieve Window instance from window creation data and associate
    LPCREATESTRUCT cs = reinterpret_cast(lParam);
    SetWindowLong(hwnd, GWL_USERDATA, reinterpret_cast(cs->lpCreateParams));
 
 // retrieve associated Window instance
 p_wnd = reinterpret_cast(GetWindowLong(hwnd, GWL_USERDATA));
 
    // save window handle
    if(p_wnd)
    {
      p_wnd->SetHWND(hwnd);
    }
  }
  else
  {
    // retrieve associated Window instance
    p_wnd = reinterpret_cast(GetWindowLong(hwnd, GWL_USERDATA));
  }
 
  if(p_wnd)
  {
    t_messageIterator i;
   
    // retrieve the associated message handler
    i = p_wnd->GetMessageHandler(msg);
    return (i->second)(p_wnd, hwnd, wParam, lParam);
  }
   
  return DefWindowProc(hwnd, msg, wParam, lParam);
}
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D