diff --git a/EXCLUDE/GLTSF/include/App.hpp b/EXCLUDE/GLTSF/include/App.hpp index 658f73b81..afa9783e1 100644 --- a/EXCLUDE/GLTSF/include/App.hpp +++ b/EXCLUDE/GLTSF/include/App.hpp @@ -17,8 +17,14 @@ public: virtual void On_Close(); virtual void On_Key_Down(int Key); virtual void On_Key_Up(int Key); + virtual void On_Char(unsigned int Char); private: + static const int Width = 800; + static const int Height = 600; + static const int Bits_Per_Pixel = 32; + static const bool Fullscreen = false; + Window my_Window; bool my_Done; }; diff --git a/EXCLUDE/GLTSF/include/TSF.hpp b/EXCLUDE/GLTSF/include/TSF.hpp index c37f4a4be..9e58b1e4e 100644 --- a/EXCLUDE/GLTSF/include/TSF.hpp +++ b/EXCLUDE/GLTSF/include/TSF.hpp @@ -7,51 +7,15 @@ class TSF { public: - -protected: - class UI_Sink : public ITfUIElementSink, public ITfInputProcessorProfileActivationSink - { - public: - UI_Sink(); - ~UI_Sink(); - - // IUnknown - STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj); - STDMETHODIMP_(ULONG) AddRef(void); - STDMETHODIMP_(ULONG) Release(void); - - // ITfUIElementSink - STDMETHODIMP BeginUIElement(DWORD dwUIElementId, BOOL *pbShow); - STDMETHODIMP UpdateUIElement(DWORD dwUIElementId); - STDMETHODIMP EndUIElement(DWORD dwUIElementId); - - // ITfInputProcessorProfileActivationSink - STDMETHODIMP OnActivated(DWORD dwProfileType, LANGID langid, - REFCLSID clsid, REFGUID catid, - REFGUID guidProfile, HKL hkl, - DWORD dwFlags); - - // ITfCompartmentEventSink - STDMETHODIMP OnChange(REFGUID rguid); - - private: - LONG my_Reference_Count; - }; - - TSF(); - ~TSF(); - - void Initialize(); - void Finalize(); + static void Initialize(); + static void Finalize(); private: - bool my_COM_Initialized; + TSF(); - CComPtr my_Thread_Manager; - UI_Sink *my_UI_Sink; + static bool COM_Initialized; - DWORD my_UI_Element_Sink_Cookie; - DWORD my_IPPA_Sink_Cookie; + static CComPtr Thread_Manager; }; #endif diff --git a/EXCLUDE/GLTSF/include/Window.hpp b/EXCLUDE/GLTSF/include/Window.hpp index f07fd477a..eda00a5a3 100644 --- a/EXCLUDE/GLTSF/include/Window.hpp +++ b/EXCLUDE/GLTSF/include/Window.hpp @@ -8,6 +8,7 @@ #include "Video_Mode.hpp" #include "Window_Listener.hpp" +#include "TSF.hpp" class Window { @@ -26,6 +27,8 @@ public: void Update(); void Display(); + void Clear(); + private: static const wchar_t *Window_Class_Name; diff --git a/EXCLUDE/GLTSF/include/Window_Listener.hpp b/EXCLUDE/GLTSF/include/Window_Listener.hpp index 52396f7e8..c99c2418a 100644 --- a/EXCLUDE/GLTSF/include/Window_Listener.hpp +++ b/EXCLUDE/GLTSF/include/Window_Listener.hpp @@ -8,6 +8,7 @@ public: virtual void On_Key_Down(int Key){} virtual void On_Key_Up(int Key){} + virtual void On_Char(unsigned int Char){} }; #endif diff --git a/EXCLUDE/GLTSF/src/App.cpp b/EXCLUDE/GLTSF/src/App.cpp index ae8ca73a5..6ce3b5627 100644 --- a/EXCLUDE/GLTSF/src/App.cpp +++ b/EXCLUDE/GLTSF/src/App.cpp @@ -1,20 +1,22 @@ #include "App.hpp" +#include "TSF.hpp" App::App() : my_Done(false) { - + TSF::Initialize(); } App::~App() { Finalize(); + TSF::Finalize(); } void App::Initialize() { Finalize(); - my_Window.Initialize(L"GLTSF", Video_Mode(800, 600, 32), false); + my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen); my_Window.Set_Listener(this); my_Window.Show(); } @@ -30,6 +32,7 @@ void App::Run() while (!my_Done) { my_Window.Update(); + my_Window.Clear(); my_Window.Display(); } } @@ -54,3 +57,8 @@ void App::On_Key_Up(int Key) { } + +void App::On_Char(unsigned int Char) +{ + printf("Char: U+%04X\n", Char); +} diff --git a/EXCLUDE/GLTSF/src/Main.cpp b/EXCLUDE/GLTSF/src/Main.cpp index 31febadbf..26c975da4 100644 --- a/EXCLUDE/GLTSF/src/Main.cpp +++ b/EXCLUDE/GLTSF/src/Main.cpp @@ -3,6 +3,7 @@ int main(int argc, char *argv[]) { + int Result = EXIT_SUCCESS; try { App theApp; @@ -11,7 +12,13 @@ int main(int argc, char *argv[]) catch (const std::exception& e) { printf("Error: %s\n", e.what()); - return 1; + Result = EXIT_FAILURE; } - return 0; + catch (...) + { + printf("Unhandled exception\n"); + Result = EXIT_FAILURE; + } + system("PAUSE"); + return Result; } diff --git a/EXCLUDE/GLTSF/src/TSF.cpp b/EXCLUDE/GLTSF/src/TSF.cpp index 2f2df17c5..f447e6c5b 100644 --- a/EXCLUDE/GLTSF/src/TSF.cpp +++ b/EXCLUDE/GLTSF/src/TSF.cpp @@ -1,140 +1,40 @@ #include "TSF.hpp" #include -TSF::TSF() : my_COM_Initialized(false), - my_UI_Sink(0), - my_UI_Element_Sink_Cookie(TF_INVALID_COOKIE), - my_IPPA_Sink_Cookie(TF_INVALID_COOKIE) -{ - -} - -TSF::~TSF() -{ - Finalize(); -} +bool TSF::COM_Initialized = false; +CComPtr TSF::Thread_Manager; void TSF::Initialize() { - Finalize(); + if (!COM_Initialized) + { + HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + if (S_OK != hr && S_FALSE != hr) + throw std::runtime_error("Failed to initialize COM"); - if (S_OK != CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)) - throw std::runtime_error("Failed to initialize COM"); + COM_Initialized = true; + } + if (!Thread_Manager) + { + if (FAILED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast(&Thread_Manager)))) + throw std::runtime_error("Failed to create ITfThreadMgr instance"); - my_COM_Initialized = true; - if (S_OK != CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, __uuidof(ITfThreadMgrEx), (void **)&my_Thread_Manager)) - throw std::runtime_error("Failed to create ITfThreadMgrEx instance"); - - TfClientId Client_Id = 0; - if (FAILED(my_Thread_Manager->ActivateEx(&Client_Id, TF_TMAE_UIELEMENTENABLEDONLY))) - throw std::runtime_error("ITfThreadMgrEx::ActivateEx failed"); - - my_UI_Sink = new UI_Sink(); - ITfSource *Source = NULL; - if (FAILED(my_Thread_Manager->QueryInterface(__uuidof(ITfSource), (void **)&Source))) - throw std::runtime_error("QueryInterface failed"); - - if (FAILED(Source->AdviseSink(__uuidof(ITfUIElementSink), (ITfUIElementSink *)my_UI_Sink, &my_UI_Element_Sink_Cookie))) - throw std::runtime_error("AdviseSink failed"); - - if (FAILED(Source->AdviseSink(__uuidof(ITfInputProcessorProfileActivationSink), (ITfInputProcessorProfileActivationSink *)my_UI_Sink, &my_IPPA_Sink_Cookie))) - throw std::runtime_error("AdviseSink failed"); + TfClientId ClientId; + if (FAILED(Thread_Manager->Activate(&ClientId))) + throw std::runtime_error("ITfThreadMgr::Activate failed"); + } } void TSF::Finalize() { - if (my_UI_Sink) + if (Thread_Manager) { - ITfSource *Source = NULL; - if (SUCCEEDED(my_Thread_Manager->QueryInterface(__uuidof(ITfSource), (void **)&Source))) - { - Source->UnadviseSink(my_IPPA_Sink_Cookie); - Source->UnadviseSink(my_UI_Element_Sink_Cookie); - Source->Release(); - } - if (my_Thread_Manager) - my_Thread_Manager->Deactivate(); - - my_UI_Sink->Release(); - delete my_UI_Sink; - my_UI_Sink = NULL; + Thread_Manager->Deactivate(); + Thread_Manager = NULL; } - my_Thread_Manager = NULL; - if (my_COM_Initialized) + if (COM_Initialized) { CoUninitialize(); - my_COM_Initialized = false; + COM_Initialized = false; } } - -TSF::UI_Sink::UI_Sink() -{ - my_Reference_Count = 1; -} - -TSF::UI_Sink::~UI_Sink() -{ - -} - -STDMETHODIMP TSF::UI_Sink::QueryInterface(REFIID riid, void **ppvObj) -{ - if (NULL == ppvObj) - return E_INVALIDARG; - - *ppvObj = NULL; - if (IsEqualIID(riid, IID_IUnknown)) - *ppvObj = reinterpret_cast(this); - else if (IsEqualIID(riid, __uuidof(ITfUIElementSink))) - *ppvObj = reinterpret_cast(this); - else if (IsEqualIID(riid, __uuidof(ITfInputProcessorProfileActivationSink))) - *ppvObj = reinterpret_cast(this); - else if (IsEqualIID(riid, __uuidof(ITfCompartmentEventSink))) - *ppvObj = reinterpret_cast(this); - - if (*ppvObj) - { - AddRef(); - return S_OK; - } - return E_NOINTERFACE; -} - -ULONG TSF::UI_Sink::AddRef(void) -{ - return ++my_Reference_Count; -} - -ULONG TSF::UI_Sink::Release(void) -{ - LONG Count = --my_Reference_Count; - if (0 == Count) - delete this; - - return Count; -} - -STDMETHODIMP TSF::UI_Sink::BeginUIElement(DWORD dwUIElementId, BOOL *pbShow) -{ - return S_OK; -} - -STDMETHODIMP TSF::UI_Sink::UpdateUIElement(DWORD dwUIElementId) -{ - return S_OK; -} - -STDMETHODIMP TSF::UI_Sink::EndUIElement(DWORD dwUIElementId) -{ - return S_OK; -} - -STDMETHODIMP TSF::UI_Sink::OnActivated(DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID catid, REFGUID guidProfile, HKL hkl, DWORD dwFlags) -{ - return S_OK; -} - -STDMETHODIMP TSF::UI_Sink::OnChange(REFGUID rguid) -{ - return S_OK; -} diff --git a/EXCLUDE/GLTSF/src/Window.cpp b/EXCLUDE/GLTSF/src/Window.cpp index 955693c05..bbb08654a 100644 --- a/EXCLUDE/GLTSF/src/Window.cpp +++ b/EXCLUDE/GLTSF/src/Window.cpp @@ -1,4 +1,5 @@ #include "Window.hpp" +#include #pragma comment(lib, "opengl32.lib") @@ -83,7 +84,7 @@ void Window::Create_Window(const std::wstring &Title, const Video_Mode &Mode, bo int Height = my_Video_Mode.Height; ReleaseDC(NULL, Screen_DC); - DWORD Style = WS_OVERLAPPEDWINDOW; + DWORD Style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU; if (!my_Fullscreen) { RECT Rect = {0, 0, Width, Height}; @@ -227,6 +228,9 @@ LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM case WM_KEYUP: Call_Listener(On_Key_Up(wParam)); break; + case WM_CHAR: + Call_Listener(On_Char(wParam)); + break; default: return DefWindowProcW(Handle, Message, wParam, lParam); break; @@ -261,3 +265,8 @@ void Window::Display() if (my_Device_Context && my_GL_Context) SwapBuffers(my_Device_Context); } + +void Window::Clear() +{ + glClear(GL_COLOR_BUFFER_BIT); +}