xref: /reactos/dll/cpl/sysdm/licence.c (revision c7bba39a)
1 /*
2  * PROJECT:     ReactOS System Control Panel Applet
3  * LICENSE:     GPL - See COPYING in the top level directory
4  * FILE:        dll/cpl/sysdm/licence.c
5  * PURPOSE:     Licence dialog box message handler
6  * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
7  *
8  */
9 
10 #include "precomp.h"
11 
12 typedef struct _LIC_CONTEXT
13 {
14     HICON hIcon;
15 } LIC_CONTEXT, *PLIC_CONTEXT;
16 
17 
18 static BOOL
19 OnInitDialog(HWND hDlg, PLIC_CONTEXT pLicInfo)
20 {
21     HRSRC hResInfo;
22     HGLOBAL hResMem;
23     PCSTR LicenseText;
24 
25     pLicInfo->hIcon = LoadImage(hApplet,
26                                 MAKEINTRESOURCE(IDI_CPLSYSTEM),
27                                 IMAGE_ICON,
28                                 16,
29                                 16,
30                                 0);
31 
32     SendMessage(hDlg,
33                 WM_SETICON,
34                 ICON_SMALL,
35                 (LPARAM)pLicInfo->hIcon);
36 
37     /* Load license from resource */
38     if (!(hResInfo = FindResource(hApplet,
39                                   MAKEINTRESOURCE(RC_LICENSE),
40                                   MAKEINTRESOURCE(RTDATA))) ||
41         !(hResMem = LoadResource(hApplet, hResInfo)) ||
42         !(LicenseText = LockResource(hResMem)))
43     {
44         ShowLastWin32Error(hDlg);
45         return FALSE;
46     }
47 
48     /* Insert the license into the edit control */
49     SetDlgItemTextA(hDlg,
50                     IDC_LICENCEEDIT,
51                     LicenseText);
52 
53     PostMessage(GetDlgItem(hDlg, IDC_LICENCEEDIT),
54                 EM_SETSEL,
55                 -1,
56                 0);
57     PostMessage(GetDlgItem(hDlg, IDC_LICENCEEDIT), WM_VSCROLL, SB_TOP, 0);
58     return TRUE;
59 }
60 
61 
62 INT_PTR CALLBACK
63 LicenceDlgProc(HWND hDlg,
64                UINT uMsg,
65                WPARAM wParam,
66                LPARAM lParam)
67 {
68     PLIC_CONTEXT pLicInfo;
69 
70     UNREFERENCED_PARAMETER(lParam);
71 
72     pLicInfo = (PLIC_CONTEXT)GetWindowLongPtr(hDlg, DWLP_USER);
73 
74     switch (uMsg)
75     {
76         case WM_INITDIALOG:
77             pLicInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LIC_CONTEXT));
78             if (pLicInfo == NULL)
79             {
80                 EndDialog(hDlg, 0);
81                 return FALSE;
82             }
83             SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pLicInfo);
84             return OnInitDialog(hDlg, pLicInfo);
85 
86         case WM_DESTROY:
87             if (pLicInfo)
88             {
89                 DestroyIcon(pLicInfo->hIcon);
90                 HeapFree(GetProcessHeap(), 0, pLicInfo);
91             }
92             break;
93 
94         case WM_COMMAND:
95             if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
96             {
97                 EndDialog(hDlg,
98                           LOWORD(wParam));
99                 return TRUE;
100             }
101             break;
102     }
103 
104     return FALSE;
105 }
106