OSDN Git Service

2011/11/03 22:37:57
[nlite/nlite.git] / nlite / nlite.cpp
1 // nlite.cpp : \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83G\83\93\83g\83\8a \83|\83C\83\93\83g\82ð\92è\8b`\82µ\82Ü\82·\81B
2 //
3
4 #include "stdafx.h"
5 #include "nlite_include.h"
6
7 #define MAX_LOADSTRING 100
8
9 // \83O\83\8d\81[\83o\83\8b\95Ï\90\94:
10 HINSTANCE hInst;                                                                // \8c»\8dÝ\82Ì\83C\83\93\83^\81[\83t\83F\83C\83X
11 TCHAR szTitle[MAX_LOADSTRING];                                  // \83^\83C\83g\83\8b \83o\81[\82Ì\83e\83L\83X\83g
12 TCHAR szWindowClass[MAX_LOADSTRING];                    // \83\81\83C\83\93 \83E\83B\83\93\83h\83\83N\83\89\83X\96¼
13
14 // \82±\82Ì\83R\81[\83\83\82\83W\83\85\81[\83\8b\82É\8aÜ\82Ü\82ê\82é\8aÖ\90\94\82Ì\90é\8c¾\82ð\93]\91\97\82µ\82Ü\82·:
15 ATOM                            nliteRegisterClass(HINSTANCE hInstance);
16 BOOL                            InitInstance(HINSTANCE, int);
17 LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
18 INT_PTR CALLBACK        About(HWND, UINT, WPARAM, LPARAM);
19
20 int APIENTRY _tWinMain(HINSTANCE hInstance,
21                      HINSTANCE hPrevInstance,
22                      LPTSTR    lpCmdLine,
23                      int       nCmdShow)
24 {
25         UNREFERENCED_PARAMETER(hPrevInstance);
26         UNREFERENCED_PARAMETER(lpCmdLine);
27
28         // TODO: \82±\82±\82É\83R\81[\83h\82ð\91}\93ü\82µ\82Ä\82­\82¾\82³\82¢\81B
29         MSG msg;
30         HACCEL hAccelTable;
31
32         // \83O\83\8d\81[\83o\83\8b\95\8e\9a\97ñ\82ð\8f\89\8aú\89»\82µ\82Ä\82¢\82Ü\82·\81B
33         LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
34         LoadString(hInstance, IDC_NLITE, szWindowClass, MAX_LOADSTRING);
35         nliteRegisterClass(hInstance);
36
37         // \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\8f\89\8aú\89»\82ð\8eÀ\8ds\82µ\82Ü\82·:
38         if (!InitInstance (hInstance, nCmdShow))
39         {
40                 return FALSE;
41         }
42
43         hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_NLITE));
44
45         // \83\81\83C\83\93 \83\81\83b\83Z\81[\83\83\8b\81[\83v:
46         while (GetMessage(&msg, NULL, 0, 0))
47         {
48                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
49                 {
50                         TranslateMessage(&msg);
51                         DispatchMessage(&msg);
52                 }
53         }
54
55         return (int) msg.wParam;
56 }
57
58
59
60 //
61 //  \8aÖ\90\94: nliteRegisterClass()
62 //
63 //  \96Ú\93I: \83E\83B\83\93\83h\83\83N\83\89\83X\82ð\93o\98^\82µ\82Ü\82·\81B
64 //
65 //  \83R\83\81\83\93\83g:
66 //
67 //    \82±\82Ì\8aÖ\90\94\82¨\82æ\82Ñ\8eg\82¢\95û\82Í\81A'RegisterClassEx' \8aÖ\90\94\82ª\92Ç\89Á\82³\82ê\82½
68 //    Windows 95 \82æ\82è\91O\82Ì Win32 \83V\83X\83e\83\80\82Æ\8cÝ\8a·\82³\82¹\82é\8fê\8d\87\82É\82Ì\82Ý\95K\97v\82Å\82·\81B
69 //    \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82ª\81A\8aÖ\98A\95t\82¯\82ç\82ê\82½
70 //    \90³\82µ\82¢\8c`\8e®\82Ì\8f¬\82³\82¢\83A\83C\83R\83\93\82ð\8eæ\93¾\82Å\82«\82é\82æ\82¤\82É\82·\82é\82É\82Í\81A
71 //    \82±\82Ì\8aÖ\90\94\82ð\8cÄ\82Ñ\8fo\82µ\82Ä\82­\82¾\82³\82¢\81B
72 //
73 ATOM nliteRegisterClass(HINSTANCE hInstance)
74 {
75         WNDCLASSEX wcex;
76
77         wcex.cbSize = sizeof(WNDCLASSEX);
78
79         wcex.style                      = CS_HREDRAW | CS_VREDRAW;
80         wcex.lpfnWndProc        = WndProc;
81         wcex.cbClsExtra         = 0;
82         wcex.cbWndExtra         = 0;
83         wcex.hInstance          = hInstance;
84         wcex.hIcon                      = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NLITE));
85         wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);
86         wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
87         wcex.lpszMenuName       = MAKEINTRESOURCE(IDC_NLITE);
88         wcex.lpszClassName      = szWindowClass;
89         wcex.hIconSm            = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
90
91         return RegisterClassEx(&wcex);
92 }
93
94 //
95 //   \8aÖ\90\94: InitInstance(HINSTANCE, int)
96 //
97 //   \96Ú\93I: \83C\83\93\83X\83^\83\93\83\83n\83\93\83h\83\8b\82ð\95Û\91\82µ\82Ä\81A\83\81\83C\83\93 \83E\83B\83\93\83h\83E\82ð\8dì\90¬\82µ\82Ü\82·\81B
98 //
99 //   \83R\83\81\83\93\83g:
100 //
101 //        \82±\82Ì\8aÖ\90\94\82Å\81A\83O\83\8d\81[\83o\83\8b\95Ï\90\94\82Å\83C\83\93\83X\83^\83\93\83\83n\83\93\83h\83\8b\82ð\95Û\91\82µ\81A
102 //        \83\81\83C\83\93 \83v\83\8d\83O\83\89\83\80 \83E\83B\83\93\83h\83E\82ð\8dì\90¬\82¨\82æ\82Ñ\95\\8e¦\82µ\82Ü\82·\81B
103 //
104 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
105 {
106    HWND hWnd;
107
108    hInst = hInstance; // \83O\83\8d\81[\83o\83\8b\95Ï\90\94\82É\83C\83\93\83X\83^\83\93\83X\8f\88\97\9d\82ð\8ai\94[\82µ\82Ü\82·\81B
109
110    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
111       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
112
113    if (!hWnd)
114    {
115       return FALSE;
116    }
117
118    ShowWindow(hWnd, nCmdShow);
119    UpdateWindow(hWnd);
120
121    return TRUE;
122 }
123
124 //
125 //  \8aÖ\90\94: WndProc(HWND, UINT, WPARAM, LPARAM)
126 //
127 //  \96Ú\93I:  \83\81\83C\83\93 \83E\83B\83\93\83h\83E\82Ì\83\81\83b\83Z\81[\83W\82ð\8f\88\97\9d\82µ\82Ü\82·\81B
128 //
129 //  WM_COMMAND  - \83A\83v\83\8a\83P\81[\83V\83\87\83\93 \83\81\83j\83\85\81[\82Ì\8f\88\97\9d
130 //  WM_PAINT    - \83\81\83C\83\93 \83E\83B\83\93\83h\83E\82Ì\95`\89æ
131 //  WM_DESTROY  - \92\86\8e~\83\81\83b\83Z\81[\83W\82ð\95\\8e¦\82µ\82Ä\96ß\82é
132 //
133 //
134 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
135 {
136         int wmId, wmEvent;
137         PAINTSTRUCT ps;
138         HDC hdc;
139
140         switch (message)
141         {
142         case WM_COMMAND:
143                 wmId    = LOWORD(wParam);
144                 wmEvent = HIWORD(wParam);
145                 // \91I\91ð\82³\82ê\82½\83\81\83j\83\85\81[\82Ì\89ð\90Í:
146                 switch (wmId)
147                 {
148                 case IDM_ABOUT:
149                         DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
150                         break;
151                 case IDM_EXIT:
152                         DestroyWindow(hWnd);
153                         break;
154                 default:
155                         return DefWindowProc(hWnd, message, wParam, lParam);
156                 }
157                 break;
158         case WM_PAINT:
159                 hdc = BeginPaint(hWnd, &ps);
160                 // TODO: \95`\89æ\83R\81[\83h\82ð\82±\82±\82É\92Ç\89Á\82µ\82Ä\82­\82¾\82³\82¢...
161                 EndPaint(hWnd, &ps);
162                 break;
163         case WM_DESTROY:
164                 PostQuitMessage(0);
165                 break;
166         default:
167                 return DefWindowProc(hWnd, message, wParam, lParam);
168         }
169         return 0;
170 }
171
172 // \83o\81[\83W\83\87\83\93\8fî\95ñ\83{\83b\83N\83X\82Ì\83\81\83b\83Z\81[\83\83n\83\93\83h\83\89\81[\82Å\82·\81B
173 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
174 {
175         UNREFERENCED_PARAMETER(lParam);
176         switch (message)
177         {
178         case WM_INITDIALOG:
179                 return (INT_PTR)TRUE;
180
181         case WM_COMMAND:
182                 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
183                 {
184                         EndDialog(hDlg, LOWORD(wParam));
185                         return (INT_PTR)TRUE;
186                 }
187                 break;
188         }
189         return (INT_PTR)FALSE;
190 }