/***************************************************************************
                             Wnd.h
                             -------------------
    Begin                : Sun Oct 7,2001
    Objective            : Winwdow wrapper class
    Author               : Drew Hall
    Email                : dhall@Zero-Soft.com
 ***************************************************************************/

#include "stdafx.h"

#ifndef __WINDOW_H__
#define __WINDOW_H__

class CWnd;
class CDialog;
typedef map<HWND,CWnd*> WndMap; 


class CWnd
{
public:
   CWnd();
   ~CWnd();

   // Creat window functions
   bool DoModal(int nTemplate, HWND hWndParent = NULL);
   bool CreateDlg(LPCDLGTEMPLATE lpTemplate, HWND hWndParent = NULL);
   bool Create(const TCHAR*, const TCHAR*, HMENU hMenu = NULL, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, 
               int nCmdShow = SW_SHOW);
   
   // Overridable Message Functions
   virtual bool OnNCCreate(LPCREATESTRUCT lpcs);
   virtual int OnCreate(LPCREATESTRUCT lpcs);
   virtual bool OnInitDialog(HWND hWndFocus);
   virtual bool OnCommand(int nID, HWND hWndCtrl, UINT nCodeNotify);
   virtual bool OnSize(UINT nState, int cx, int cy);
   //virtual bool OnPaint();
   virtual bool OnKey(UINT vk, bool fDown, int nRepeat, UINT nFlags);
   virtual bool OnTimer(int nID);
   virtual bool OnClose();
   virtual bool OnDestroy();

   // Fake DlgProc to bounce back inside of our class
   friend LRESULT CALLBACK BounceProc(HWND, UINT, WPARAM, LPARAM);

   // Access Functions
   HWND GetHwnd();
   HMENU GetMenu();
   HINSTANCE GetInstance();

   // Window Rect Functions
   int GetClientRect(RECT* rect);
   int GetWindowRect(RECT* rect);
   
   // Window Style Functions
   long GetWindowLong(int nIndex);
   long SetWindowLong(int nIndex, long dwData);

   // Window Title Functions
   int SetWindowText(const TCHAR* szTitle);
   int GetWindowText(TCHAR* szTitle, int nLen);

   // Window Positioning Functions
   int MoveWindow(LPRECT lpRect, bool bRepaint = true);
   int MoveWindow(int x, int y, int nWidth, int yHeight, bool bRepaint = true);
   int SetWindowPos(HWND hWndAfter, int x, int y, int nWitdth, int yHeight, UINT nFlags);
   int CenterWindow(HWND hWndParent = NULL, bool bRepaint = true);
   
   // Messagebox 
   virtual int MessageBox(const TCHAR* szText, const TCHAR* szTitle = NULL, UINT nType = MB_OK);
   
   // HWND to CWnd* Functions
   static bool AddCWnd(HWND hWnd, CWnd* cWnd);
   static CWnd* LookupCWnd(HWND hwnd);

private:
   LRESULT WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);
   bool RegisterAtom(const TCHAR*, HMENU hMenu);

  
   static WndMap m_WndMap;
   WNDCLASSEX wc;

protected:
   virtual int MessagePump();

   HWND m_hWnd;
   HMENU m_hMenu;
   HINSTANCE m_hInst;

};


#endif