1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #include "platform_helper.h"
6 #include "../../../lib/platform/win32/win32support.h"
7 #include <windows.h>
8 
9 namespace VSTGUI {
10 namespace UnitTest {
11 
MainWndProc(HWND h,UINT m,WPARAM w,LPARAM l)12 static LRESULT CALLBACK MainWndProc (HWND h, UINT m , WPARAM w, LPARAM l)
13 {
14 	return DefWindowProc (h, m, w, l);
15 }
16 
InitApplication(HINSTANCE hinstance)17 BOOL InitApplication(HINSTANCE hinstance)
18 {
19     WNDCLASSEX wcx;
20 
21     // Fill in the window class structure with parameters
22     // that describe the main window.
23 
24     wcx.cbSize = sizeof(wcx);          // size of structure
25     wcx.style = CS_HREDRAW |
26         CS_VREDRAW;                    // redraw if size changes
27     wcx.lpfnWndProc = MainWndProc;     // points to window procedure
28     wcx.cbClsExtra = 0;                // no extra class memory
29     wcx.cbWndExtra = 0;                // no extra window memory
30     wcx.hInstance = hinstance;         // handle to instance
31     wcx.hIcon = LoadIcon(NULL,
32         IDI_APPLICATION);              // predefined app. icon
33     wcx.hCursor = LoadCursor(NULL,
34         IDC_ARROW);                    // predefined arrow
35     wcx.hbrBackground = nullptr;             // white background brush
36     wcx.lpszMenuName =  nullptr;    // name of menu resource
37     wcx.lpszClassName = L"MainWClass";  // name of window class
38     wcx.hIconSm = nullptr;
39 
40     // Register the window class.
41 
42     return RegisterClassEx(&wcx);
43 }
44 
45 struct Initializer
46 {
instanceVSTGUI::UnitTest::Initializer47 	static Initializer& instance ()
48 	{
49 		static Initializer gInstance;
50 		return gInstance;
51 	}
InitializerVSTGUI::UnitTest::Initializer52 	Initializer ()
53 	{
54 		InitApplication (GetInstance ());
55 	}
56 };
57 
58 struct WinPlatformHandle : PlatformParentHandle
59 {
60 	HWND window{ nullptr };
61 
WinPlatformHandleVSTGUI::UnitTest::WinPlatformHandle62 	WinPlatformHandle ()
63 	{
64 		Initializer::instance ();
65 		window = CreateWindow (L"MainWClass", L"Test", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, nullptr, nullptr, GetInstance (), 0);
66 	}
67 
~WinPlatformHandleVSTGUI::UnitTest::WinPlatformHandle68 	~WinPlatformHandle ()
69 	{
70 		DestroyWindow (window);
71 	}
72 
getTypeVSTGUI::UnitTest::WinPlatformHandle73 	PlatformType getType () const override { return kHWND; }
getHandleVSTGUI::UnitTest::WinPlatformHandle74 	void* getHandle () const override { return window; };
forceRedrawVSTGUI::UnitTest::WinPlatformHandle75 	void forceRedraw () override {};
76 };
77 
create()78 SharedPointer<PlatformParentHandle> PlatformParentHandle::create()
79 {
80 	return owned (dynamic_cast<PlatformParentHandle*> (new WinPlatformHandle ()));
81 }
82 
83 } // UnitTest
84 } // VSTGUI
85 
86