]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.excel/native/SimanticsExcel/SimanticsExcel/SimanticsExcel.cpp
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.excel / native / SimanticsExcel / SimanticsExcel / SimanticsExcel.cpp
1 // SimanticsExcel.cpp : Defines the entry point for the application.\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "SimanticsExcel.h"\r
6 \r
7 #define MAX_LOADSTRING 100\r
8 \r
9 // Global Variables:\r
10 HINSTANCE hInst;                                                                // current instance\r
11 TCHAR szTitle[MAX_LOADSTRING];                                  // The title bar text\r
12 TCHAR szWindowClass[MAX_LOADSTRING];                    // the main window class name\r
13 \r
14 // Forward declarations of functions included in this code module:\r
15 ATOM                            MyRegisterClass(HINSTANCE hInstance);\r
16 BOOL                            InitInstance(HINSTANCE, int);\r
17 LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);\r
18 INT_PTR CALLBACK        About(HWND, UINT, WPARAM, LPARAM);\r
19 \r
20 int APIENTRY _tWinMain(HINSTANCE hInstance,\r
21                      HINSTANCE hPrevInstance,\r
22                      LPTSTR    lpCmdLine,\r
23                      int       nCmdShow)\r
24 {\r
25         UNREFERENCED_PARAMETER(hPrevInstance);\r
26         UNREFERENCED_PARAMETER(lpCmdLine);\r
27 \r
28         // TODO: Place code here.\r
29         MSG msg;\r
30         HACCEL hAccelTable;\r
31 \r
32         // Initialize global strings\r
33         LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);\r
34         LoadString(hInstance, IDC_SIMANTICSEXCEL, szWindowClass, MAX_LOADSTRING);\r
35         MyRegisterClass(hInstance);\r
36 \r
37         // Perform application initialization:\r
38         if (!InitInstance (hInstance, nCmdShow))\r
39         {\r
40                 return FALSE;\r
41         }\r
42 \r
43         hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SIMANTICSEXCEL));\r
44 \r
45         // Main message loop:\r
46         while (GetMessage(&msg, NULL, 0, 0))\r
47         {\r
48                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))\r
49                 {\r
50                         TranslateMessage(&msg);\r
51                         DispatchMessage(&msg);\r
52                 }\r
53         }\r
54 \r
55         return (int) msg.wParam;\r
56 }\r
57 \r
58 \r
59 \r
60 //\r
61 //  FUNCTION: MyRegisterClass()\r
62 //\r
63 //  PURPOSE: Registers the window class.\r
64 //\r
65 //  COMMENTS:\r
66 //\r
67 //    This function and its usage are only necessary if you want this code\r
68 //    to be compatible with Win32 systems prior to the 'RegisterClassEx'\r
69 //    function that was added to Windows 95. It is important to call this function\r
70 //    so that the application will get 'well formed' small icons associated\r
71 //    with it.\r
72 //\r
73 ATOM MyRegisterClass(HINSTANCE hInstance)\r
74 {\r
75         WNDCLASSEX wcex;\r
76 \r
77         wcex.cbSize = sizeof(WNDCLASSEX);\r
78 \r
79         wcex.style                      = CS_HREDRAW | CS_VREDRAW;\r
80         wcex.lpfnWndProc        = WndProc;\r
81         wcex.cbClsExtra         = 0;\r
82         wcex.cbWndExtra         = 0;\r
83         wcex.hInstance          = hInstance;\r
84         wcex.hIcon                      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SIMANTICSEXCEL));\r
85         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);\r
86         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);\r
87         wcex.lpszMenuName       = MAKEINTRESOURCE(IDC_SIMANTICSEXCEL);\r
88         wcex.lpszClassName      = szWindowClass;\r
89         wcex.hIconSm            = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));\r
90 \r
91         return RegisterClassEx(&wcex);\r
92 }\r
93 \r
94 //\r
95 //   FUNCTION: InitInstance(HINSTANCE, int)\r
96 //\r
97 //   PURPOSE: Saves instance handle and creates main window\r
98 //\r
99 //   COMMENTS:\r
100 //\r
101 //        In this function, we save the instance handle in a global variable and\r
102 //        create and display the main program window.\r
103 //\r
104 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)\r
105 {\r
106    HWND hWnd;\r
107 \r
108    hInst = hInstance; // Store instance handle in our global variable\r
109 \r
110    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,\r
111       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);\r
112 \r
113    if (!hWnd)\r
114    {\r
115       return FALSE;\r
116    }\r
117 \r
118    ShowWindow(hWnd, nCmdShow);\r
119    UpdateWindow(hWnd);\r
120 \r
121    return TRUE;\r
122 }\r
123 \r
124 //\r
125 //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)\r
126 //\r
127 //  PURPOSE:  Processes messages for the main window.\r
128 //\r
129 //  WM_COMMAND  - process the application menu\r
130 //  WM_PAINT    - Paint the main window\r
131 //  WM_DESTROY  - post a quit message and return\r
132 //\r
133 //\r
134 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\r
135 {\r
136         int wmId, wmEvent;\r
137         PAINTSTRUCT ps;\r
138         HDC hdc;\r
139 \r
140         switch (message)\r
141         {\r
142         case WM_COMMAND:\r
143                 wmId    = LOWORD(wParam);\r
144                 wmEvent = HIWORD(wParam);\r
145                 // Parse the menu selections:\r
146                 switch (wmId)\r
147                 {\r
148                 case IDM_ABOUT:\r
149                         DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);\r
150                         break;\r
151                 case IDM_EXIT:\r
152                         DestroyWindow(hWnd);\r
153                         break;\r
154                 default:\r
155                         return DefWindowProc(hWnd, message, wParam, lParam);\r
156                 }\r
157                 break;\r
158         case WM_PAINT:\r
159                 hdc = BeginPaint(hWnd, &ps);\r
160                 // TODO: Add any drawing code here...\r
161                 EndPaint(hWnd, &ps);\r
162                 break;\r
163         case WM_DESTROY:\r
164                 PostQuitMessage(0);\r
165                 break;\r
166         default:\r
167                 return DefWindowProc(hWnd, message, wParam, lParam);\r
168         }\r
169         return 0;\r
170 }\r
171 \r
172 // Message handler for about box.\r
173 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
174 {\r
175         UNREFERENCED_PARAMETER(lParam);\r
176         switch (message)\r
177         {\r
178         case WM_INITDIALOG:\r
179                 return (INT_PTR)TRUE;\r
180 \r
181         case WM_COMMAND:\r
182                 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)\r
183                 {\r
184                         EndDialog(hDlg, LOWORD(wParam));\r
185                         return (INT_PTR)TRUE;\r
186                 }\r
187                 break;\r
188         }\r
189         return (INT_PTR)FALSE;\r
190 }\r