| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #define UNICODE |
| 4 | #define _UNICODE |
| 5 | #include <windows.h> |
| 6 | #include "richedit.h" |
| 7 | #include "tchar.h" |
| 8 | #include "main.h" |
| 9 | |
| 10 | static LPCTSTR szWindowClass = _T("DesktopApp"); |
| 11 | |
| 12 | static HINSTANCE hInst; |
| 13 | static HWND hToken; |
| 14 | static HWND hRoom; |
| 15 | |
| 16 | LRESULT CALLBACK WndProc(HWND hNetdatawnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 17 | { |
| 18 | PAINTSTRUCT ps; |
| 19 | HDC hdc; |
| 20 | LPCTSTR topMsg[] = { L" Help", |
| 21 | L" ", |
| 22 | L"In this initial version of the software, there are no fields for data", |
| 23 | L" entry. To claim your agent, you must use the following options:", |
| 24 | L" ", |
| 25 | L"/T TOKEN: The cloud token;", |
| 26 | L"/R ROOMS: A list of rooms to claim;", |
| 27 | L"/P PROXY: The proxy information;", |
| 28 | L"/U URL : The cloud URL;", |
| 29 | L"/I : Use insecure connection;", |
| 30 | L"/F File : file to store cloud info;" |
| 31 | }; |
| 32 | |
| 33 | switch (message) |
| 34 | { |
| 35 | case WM_PAINT: { |
| 36 | hdc = BeginPaint(hNetdatawnd, &ps); |
| 37 | |
| 38 | int i; |
| 39 | for (i = 0; i < sizeof(topMsg) / sizeof(LPCTSTR); i++) { |
| 40 | TextOut(hdc, 5, 5 + 15*i, topMsg[i], wcslen(topMsg[i])); |
| 41 | } |
| 42 | EndPaint(hNetdatawnd, &ps); |
| 43 | break; |
| 44 | } |
| 45 | case WM_COMMAND: |
| 46 | case WM_DESTROY: { |
| 47 | PostQuitMessage(0); |
| 48 | break; |
| 49 | } |
| 50 | default: { |
| 51 | return DefWindowProc(hNetdatawnd, message, wParam, lParam); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | int netdata_claim_window_loop(HINSTANCE hInstance, int nCmdShow) |
| 59 | { |
| 60 | WNDCLASSEX wcex; |
| 61 | |
| 62 | wcex.cbSize = sizeof(WNDCLASSEX); |
| 63 | wcex.style = CS_HREDRAW | CS_VREDRAW; |
| 64 | wcex.lpfnWndProc = WndProc; |
| 65 | wcex.cbClsExtra = 0; |
| 66 | wcex.cbWndExtra = 0; |
| 67 | wcex.hInstance = hInstance; |
| 68 | wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCEW(11)); |
| 69 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 70 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); |
| 71 | wcex.lpszMenuName = NULL; |
| 72 | wcex.lpszClassName = szWindowClass; |
| 73 | wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION); |
| 74 | |
| 75 | if (!RegisterClassEx(&wcex)) { |
| 76 | MessageBoxW(NULL, L"Call to RegisterClassEx failed!", L"Error", 0); |
| 77 | return 1; |
| 78 | } |
| 79 | |
| 80 | hInst = hInstance; |
| 81 | |
| 82 | HWND hNetdatawnd = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, |
| 83 | szWindowClass, |
| 84 | L"Netdata Claim", |
| 85 | WS_OVERLAPPEDWINDOW, |
| 86 | CW_USEDEFAULT, CW_USEDEFAULT, |
| 87 | 460, 240, |
| 88 | NULL, |
| 89 | NULL, |
| 90 | hInstance, |
| 91 | NULL |
| 92 | ); |
| 93 | |
| 94 | if (!hNetdatawnd) { |
| 95 | MessageBoxW(NULL, L"Call to CreateWindow failed!", L"Error", 0); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | ShowWindow(hNetdatawnd, nCmdShow); |
| 100 | UpdateWindow(hNetdatawnd); |
| 101 | |
| 102 | MSG msg; |
| 103 | while (GetMessage(&msg, NULL, 0, 0)) { |
| 104 | TranslateMessage(&msg); |
| 105 | DispatchMessage(&msg); |
| 106 | } |
| 107 | |
| 108 | return (int) msg.wParam; |
| 109 | } |