core/vgui/impl/win32/vgui_win32.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/win32/vgui_win32.h
00002 
00003 #ifndef vgui_win32_h_
00004 #define vgui_win32_h_
00005 
00006 // The Win32 Application Programming Interfaces (API) implementation of
00007 // vgui_toolkit.
00008 // author: Lianqing Yu
00009 
00010 // Modifications:
00011 // July 30, 2009              Initial version
00012 
00013 // Notes:
00014 // vgui_win32 acts like CWinThread and CWinApp in MFC. It performs program
00015 // initialization/termination, process message loops, and deal with
00016 // command line arguments.
00017 
00018 // Enable Windows XP (or later) visual styles for common controls
00019 #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
00020 
00021 #include <vgui/vgui_toolkit.h>
00022 #include <windows.h>
00023 
00024 // TODO issues:
00025 // 1. add_event()
00026 
00027 
00028 // Provide functions for (a) controlling event loop,
00029 //                       (b) translating Win32's event system to vgui_event.
00030 
00031 class vgui_win32 : public vgui_toolkit
00032 {
00033  public:
00034   ~vgui_win32();
00035 
00036   // Window management functions.
00037   vgui_window* get_current_window() { return current_window; }
00038   void set_current_window(HWND);
00039   void remove_current_window();
00040   int find_window(HWND);
00041   void dump_window_stack();
00042 
00043   // Dialog box management functions
00044   vgui_dialog_impl* get_current_dialog() { return current_dialog; }
00045   void remove_current_dialog();
00046 
00047   // Singleton method instance.
00048   static vgui_win32* instance();
00049 
00050   virtual void init(int &, char **);
00051   virtual void uninit();
00052 
00053   // Returns the name of the toolkit
00054   virtual vcl_string name() const { return "win32"; }
00055 
00056   virtual vgui_window* produce_window(int width, int height,
00057                                       vgui_menu const &menubar,
00058                                       char const *title);
00059 
00060   virtual vgui_window* produce_window(int width, int height,
00061                                       char const *title);
00062 
00063   virtual vgui_dialog_impl* produce_dialog(char const *name);
00064 
00065   virtual vgui_dialog_extensions_impl* produce_dialog_extension(char const *name);
00066 
00067   virtual void run();
00068   virtual void run_one_event();
00069   virtual void run_till_idle();
00070   virtual void flush();
00071   virtual void add_event(vgui_event const &);
00072   virtual void quit();
00073 
00074  protected:
00075   vgui_win32();
00076 
00077   // Process command line arguments
00078   BOOL ProcessShellCommand(int argc, char **argv);
00079 
00080   // Pump a message from the thread's message queue and process it.
00081   BOOL PumpMessage();
00082 
00083   static vgui_win32 *instance_; // or put this member into instance().
00084 
00085   // The four arguments of WinMain() are put here as class members.
00086   HINSTANCE hInstance_; // application instance handle
00087   HINSTANCE hPrevInstance_;
00088   PSTR      szCmdLine_;
00089   int       iCmdShow_;
00090   char     *szAppName_;
00091 
00092   // Save pointers to vgui_win32_window for access and free at app exit.
00093   vcl_vector<vgui_window*> windows_to_delete;
00094   vgui_window* current_window;
00095 
00096   // Save pointer to vgui_dialog_impl for access from dialog procedure.
00097   vcl_vector<vgui_dialog_impl*> dialogs_to_delete;
00098   vgui_dialog_impl* current_dialog;
00099 };
00100 
00101 // Global window procedure and dialog procedure
00102 LRESULT CALLBACK globalWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
00103 LRESULT CALLBACK globalDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
00104 LRESULT CALLBACK globalTableauProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
00105 
00106 #endif // vgui_win32_h_