WinUtility.hpp
Go to the documentation of this file.
1 
6 #ifndef GOSU_WINUTILITY_HPP
7 #define GOSU_WINUTILITY_HPP
8 
9 #include <windows.h>
10 #include <Gosu/Platform.hpp>
11 #include <Gosu/TR1.hpp>
12 #include <string>
13 
14 namespace Gosu
15 {
17  namespace Win
18  {
20  HINSTANCE instance();
21 
24  void handleMessage();
25 
28  void processMessages();
29 
33  void registerMessageHook(const std::tr1::function<bool (MSG&)>& hook);
34 
38  GOSU_NORETURN void throwLastError(const std::string& action = "");
39 
43  template<typename T>
44  inline T check(T valToCheck, const std::string& action = "")
45  {
46  if (!valToCheck)
47  throwLastError(action);
48  return valToCheck;
49  }
50 
51  // IMPR: Why can't I use mem_fn for releasing objects even though it is
52  // shown like that in the shared_ptr documentation?
53  template<typename T>
54  void releaseComPtr(T* ptr)
55  {
56  ptr->Release();
57  }
58 
61  template<typename T>
62  inline std::tr1::shared_ptr<T> shareComPtr(T* ptr)
63  {
64  return std::tr1::shared_ptr<T>(ptr, releaseComPtr<T>);
65  }
66 
68  std::wstring appFilename();
69 
71  std::wstring appDirectory();
72  }
73 }
74 
75 #endif
Includes all parts of C++03 (TR1) that are relevant for Gosu.
void registerMessageHook(const std::tr1::function< bool(MSG &)> &hook)
Registers a function to be called by handleMessage and processMessages.
void processMessages()
Non-blocking function which processes all waiting messages but does not wait for further incoming mes...
T check(T valToCheck, const std::string &action="")
Small helper function that throws an exception whenever the value passed through is false...
Definition: WinUtility.hpp:44
std::wstring appFilename()
Returns the executable&#39;s filename.
std::wstring appDirectory()
Returns the executable&#39;s containing directory.
void releaseComPtr(T *ptr)
Definition: WinUtility.hpp:54
GOSU_NORETURN void throwLastError(const std::string &action="")
Throws an exception according to the error which GetLastError() returns, optionally prefixed with &quot;Wh...
HINSTANCE instance()
Returns the instance handle of the application.
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
void handleMessage()
Blocking function which waits for the next message, processes it, then returns.
std::tr1::shared_ptr< T > shareComPtr(T *ptr)
Small helper function that transfers ownership of a COM interface to a std::tr1::shared_ptr.
Definition: WinUtility.hpp:62