xref: /reactos/base/applications/mspaint/main.cpp (revision 6af1813f)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:    PAINT for ReactOS
38f1f1c7aSStanislav Motylkov  * LICENSE:    LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4bf13ebdaSKatayama Hirofumi MZ  * PURPOSE:    The main window and wWinMain etc.
5f5200e6cSStanislav Motylkov  * COPYRIGHT:  Copyright 2015 Benedikt Freisen <b.freisen@gmx.net>
6bf13ebdaSKatayama Hirofumi MZ  *             Copyright 2017-2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7bf13ebdaSKatayama Hirofumi MZ  *             Copyright 2018 Stanislav Motylkov <x86corez@gmail.com>
8c2c66affSColin Finck  */
9c2c66affSColin Finck 
10c2c66affSColin Finck #include "precomp.h"
11c2c66affSColin Finck 
12d7ece626SKatayama Hirofumi MZ #include <dlgs.h>
13ba53f72aSKatayama Hirofumi MZ #include <mapi.h>
14bf13ebdaSKatayama Hirofumi MZ #include <assert.h>
15ba53f72aSKatayama Hirofumi MZ 
16e8c7e300SKatayama Hirofumi MZ BOOL g_askBeforeEnlarging = FALSE;  // TODO: initialize from registry
17e8c7e300SKatayama Hirofumi MZ HINSTANCE g_hinstExe = NULL;
18640d67d1SKatayama Hirofumi MZ WCHAR g_szFileName[MAX_LONG_PATH] = { 0 };
19ba53f72aSKatayama Hirofumi MZ WCHAR g_szMailTempFile[MAX_LONG_PATH] = { 0 };
20e8c7e300SKatayama Hirofumi MZ BOOL g_isAFile = FALSE;
21e8c7e300SKatayama Hirofumi MZ BOOL g_imageSaved = FALSE;
22e8c7e300SKatayama Hirofumi MZ BOOL g_showGrid = FALSE;
23bf13ebdaSKatayama Hirofumi MZ HWND g_hStatusBar = NULL;
24c2c66affSColin Finck 
25c2c66affSColin Finck CMainWindow mainWindow;
2629e147beSKatayama Hirofumi MZ 
27bf13ebdaSKatayama Hirofumi MZ typedef HWND (WINAPI *FN_HtmlHelpW)(HWND, LPCWSTR, UINT, DWORD_PTR);
28bf13ebdaSKatayama Hirofumi MZ 
29bf13ebdaSKatayama Hirofumi MZ static HINSTANCE s_hHHCTRL_OCX = NULL; // HtmlHelpW needs "hhctrl.ocx"
30bf13ebdaSKatayama Hirofumi MZ static FN_HtmlHelpW s_pHtmlHelpW = NULL;
31bf13ebdaSKatayama Hirofumi MZ 
3229e147beSKatayama Hirofumi MZ /* FUNCTIONS ********************************************************/
33c2c66affSColin Finck 
ShowOutOfMemory(void)34ab199cc1SKatayama Hirofumi MZ void ShowOutOfMemory(void)
35ab199cc1SKatayama Hirofumi MZ {
36ab199cc1SKatayama Hirofumi MZ     WCHAR szText[256];
37ab199cc1SKatayama Hirofumi MZ     ::FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
38ab199cc1SKatayama Hirofumi MZ                      NULL,
39ab199cc1SKatayama Hirofumi MZ                      ERROR_OUTOFMEMORY,
40ab199cc1SKatayama Hirofumi MZ                      0,
41ab199cc1SKatayama Hirofumi MZ                      szText, _countof(szText),
42ab199cc1SKatayama Hirofumi MZ                      NULL);
43ab199cc1SKatayama Hirofumi MZ     mainWindow.MessageBox(szText, NULL, MB_ICONERROR);
44ab199cc1SKatayama Hirofumi MZ }
45ab199cc1SKatayama Hirofumi MZ 
46c2c66affSColin Finck // get file name extension from filter string
47c2c66affSColin Finck static BOOL
FileExtFromFilter(LPWSTR pExt,OPENFILENAME * pOFN)48640d67d1SKatayama Hirofumi MZ FileExtFromFilter(LPWSTR pExt, OPENFILENAME *pOFN)
49c2c66affSColin Finck {
50640d67d1SKatayama Hirofumi MZ     LPWSTR pchExt = pExt;
51c2c66affSColin Finck     *pchExt = 0;
52c2c66affSColin Finck 
53c2c66affSColin Finck     DWORD nIndex = 1;
54640d67d1SKatayama Hirofumi MZ     for (LPCWSTR pch = pOFN->lpstrFilter; *pch; ++nIndex)
55c2c66affSColin Finck     {
56c2c66affSColin Finck         pch += lstrlen(pch) + 1;
57c2c66affSColin Finck         if (pOFN->nFilterIndex == nIndex)
58c2c66affSColin Finck         {
59640d67d1SKatayama Hirofumi MZ             for (++pch; *pch && *pch != L';'; ++pch)
60c2c66affSColin Finck             {
61c2c66affSColin Finck                 *pchExt++ = *pch;
62c2c66affSColin Finck             }
63c2c66affSColin Finck             *pchExt = 0;
64c2c66affSColin Finck             CharLower(pExt);
65c2c66affSColin Finck             return TRUE;
66c2c66affSColin Finck         }
67d7ece626SKatayama Hirofumi MZ         pch += wcslen(pch) + 1;
68c2c66affSColin Finck     }
69c2c66affSColin Finck     return FALSE;
70c2c66affSColin Finck }
71c2c66affSColin Finck 
72c2c66affSColin Finck // Hook procedure for OPENFILENAME to change the file name extension
73c2c66affSColin Finck static UINT_PTR APIENTRY
OFNHookProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)74c2c66affSColin Finck OFNHookProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
75c2c66affSColin Finck {
76c2c66affSColin Finck     HWND hParent;
77640d67d1SKatayama Hirofumi MZ     OFNOTIFYW *pon;
78d7ece626SKatayama Hirofumi MZ     WCHAR Path[MAX_PATH];
79c2c66affSColin Finck     switch (uMsg)
80c2c66affSColin Finck     {
81c2c66affSColin Finck     case WM_NOTIFY:
82640d67d1SKatayama Hirofumi MZ         pon = (OFNOTIFYW *)lParam;
83c2c66affSColin Finck         if (pon->hdr.code == CDN_TYPECHANGE)
84c2c66affSColin Finck         {
85c2c66affSColin Finck             hParent = GetParent(hwnd);
86d7ece626SKatayama Hirofumi MZ             SendMessageW(hParent, CDM_GETFILEPATH, _countof(Path), (LPARAM)Path);
87d7ece626SKatayama Hirofumi MZ             FileExtFromFilter(PathFindExtensionW(Path), pon->lpOFN);
88d7ece626SKatayama Hirofumi MZ             SendMessageW(hParent, CDM_SETCONTROLTEXT, cmb13, (LPARAM)PathFindFileNameW(Path));
89d7ece626SKatayama Hirofumi MZ             StringCchCopyW(pon->lpOFN->lpstrFile, pon->lpOFN->nMaxFile, Path);
90c2c66affSColin Finck         }
91c2c66affSColin Finck         break;
92c2c66affSColin Finck     }
93c2c66affSColin Finck     return 0;
94c2c66affSColin Finck }
95c2c66affSColin Finck 
96ba53f72aSKatayama Hirofumi MZ typedef ULONG (WINAPI *FN_MAPISendMail)(LHANDLE, ULONG_PTR, lpMapiMessage, FLAGS, ULONG);
97ba53f72aSKatayama Hirofumi MZ typedef ULONG (WINAPI *FN_MAPISendMailW)(LHANDLE, ULONG_PTR, lpMapiMessageW, FLAGS, ULONG);
98ba53f72aSKatayama Hirofumi MZ 
OpenMailer(HWND hWnd,LPCWSTR pszPathName)99ba53f72aSKatayama Hirofumi MZ BOOL OpenMailer(HWND hWnd, LPCWSTR pszPathName)
100ba53f72aSKatayama Hirofumi MZ {
101ba53f72aSKatayama Hirofumi MZ     // Delete the temporary file if any
102ba53f72aSKatayama Hirofumi MZ     if (g_szMailTempFile[0])
103ba53f72aSKatayama Hirofumi MZ     {
104ba53f72aSKatayama Hirofumi MZ         ::DeleteFileW(g_szMailTempFile);
105ba53f72aSKatayama Hirofumi MZ         g_szMailTempFile[0] = UNICODE_NULL;
106ba53f72aSKatayama Hirofumi MZ     }
107ba53f72aSKatayama Hirofumi MZ 
108ba53f72aSKatayama Hirofumi MZ     CStringW strFileTitle;
109ba53f72aSKatayama Hirofumi MZ     if (PathFileExistsW(pszPathName) && imageModel.IsImageSaved())
110ba53f72aSKatayama Hirofumi MZ     {
111ba53f72aSKatayama Hirofumi MZ         strFileTitle = PathFindFileNameW(pszPathName);
112ba53f72aSKatayama Hirofumi MZ     }
113ba53f72aSKatayama Hirofumi MZ     else // Not existing or not saved
114ba53f72aSKatayama Hirofumi MZ     {
115ba53f72aSKatayama Hirofumi MZ         // Get the name of a temporary file
116ba53f72aSKatayama Hirofumi MZ         WCHAR szTempDir[MAX_PATH];
117ba53f72aSKatayama Hirofumi MZ         ::GetTempPathW(_countof(szTempDir), szTempDir);
118ba53f72aSKatayama Hirofumi MZ         if (!::GetTempFileNameW(szTempDir, L"afx", 0, g_szMailTempFile))
119ba53f72aSKatayama Hirofumi MZ             return FALSE; // Failure
120ba53f72aSKatayama Hirofumi MZ 
121ba53f72aSKatayama Hirofumi MZ         if (PathFileExistsW(g_szFileName))
122ba53f72aSKatayama Hirofumi MZ         {
123ba53f72aSKatayama Hirofumi MZ             // Set file title
124ba53f72aSKatayama Hirofumi MZ             strFileTitle = PathFindFileNameW(g_szFileName);
125ba53f72aSKatayama Hirofumi MZ 
126ba53f72aSKatayama Hirofumi MZ             // Copy to the temporary file
127ba53f72aSKatayama Hirofumi MZ             if (!::CopyFileW(g_szFileName, g_szMailTempFile, FALSE))
128ba53f72aSKatayama Hirofumi MZ             {
129ba53f72aSKatayama Hirofumi MZ                 g_szMailTempFile[0] = UNICODE_NULL;
130ba53f72aSKatayama Hirofumi MZ                 return FALSE; // Failure
131ba53f72aSKatayama Hirofumi MZ             }
132ba53f72aSKatayama Hirofumi MZ         }
133ba53f72aSKatayama Hirofumi MZ         else
134ba53f72aSKatayama Hirofumi MZ         {
135ba53f72aSKatayama Hirofumi MZ             // Set file title
136ba53f72aSKatayama Hirofumi MZ             strFileTitle.LoadString(IDS_DEFAULTFILENAME);
137ba53f72aSKatayama Hirofumi MZ             strFileTitle += L".png";
138ba53f72aSKatayama Hirofumi MZ 
139ba53f72aSKatayama Hirofumi MZ             // Save it to the temporary file
140bbb33a6eSKatayama Hirofumi MZ             HBITMAP hbmLocked = imageModel.LockBitmap();
141bbb33a6eSKatayama Hirofumi MZ             BOOL ret = SaveDIBToFile(hbmLocked, g_szMailTempFile, FALSE, Gdiplus::ImageFormatPNG);
142bbb33a6eSKatayama Hirofumi MZ             imageModel.UnlockBitmap(hbmLocked);
143ba53f72aSKatayama Hirofumi MZ             if (!ret)
144ba53f72aSKatayama Hirofumi MZ             {
145ba53f72aSKatayama Hirofumi MZ                 g_szMailTempFile[0] = UNICODE_NULL;
146ba53f72aSKatayama Hirofumi MZ                 return FALSE; // Failure
147ba53f72aSKatayama Hirofumi MZ             }
148ba53f72aSKatayama Hirofumi MZ         }
149ba53f72aSKatayama Hirofumi MZ 
150ba53f72aSKatayama Hirofumi MZ         // Use the temporary file
151ba53f72aSKatayama Hirofumi MZ         pszPathName = g_szMailTempFile;
152ba53f72aSKatayama Hirofumi MZ     }
153ba53f72aSKatayama Hirofumi MZ 
154ba53f72aSKatayama Hirofumi MZ     // Load "mapi32.dll"
155ba53f72aSKatayama Hirofumi MZ     HINSTANCE hMAPI = LoadLibraryW(L"mapi32.dll");
156ba53f72aSKatayama Hirofumi MZ     if (!hMAPI)
157ba53f72aSKatayama Hirofumi MZ         return FALSE; // Failure
158ba53f72aSKatayama Hirofumi MZ 
159ba53f72aSKatayama Hirofumi MZ     // Attachment
160ba53f72aSKatayama Hirofumi MZ     MapiFileDescW attachmentW = { 0 };
161ba53f72aSKatayama Hirofumi MZ     attachmentW.nPosition = (ULONG)-1;
162ba53f72aSKatayama Hirofumi MZ     attachmentW.lpszPathName = (LPWSTR)pszPathName;
163ba53f72aSKatayama Hirofumi MZ     attachmentW.lpszFileName = (LPWSTR)(LPCWSTR)strFileTitle;
164ba53f72aSKatayama Hirofumi MZ 
165ba53f72aSKatayama Hirofumi MZ     // Message with attachment
166ba53f72aSKatayama Hirofumi MZ     MapiMessageW messageW = { 0 };
167ba53f72aSKatayama Hirofumi MZ     messageW.lpszSubject = NULL;
168ba53f72aSKatayama Hirofumi MZ     messageW.nFileCount = 1;
169ba53f72aSKatayama Hirofumi MZ     messageW.lpFiles = &attachmentW;
170ba53f72aSKatayama Hirofumi MZ 
171ba53f72aSKatayama Hirofumi MZ     // First, try to open the mailer by the function of Unicode version
172ba53f72aSKatayama Hirofumi MZ     FN_MAPISendMailW pMAPISendMailW = (FN_MAPISendMailW)::GetProcAddress(hMAPI, "MAPISendMailW");
173ba53f72aSKatayama Hirofumi MZ     if (pMAPISendMailW)
174ba53f72aSKatayama Hirofumi MZ     {
175ba53f72aSKatayama Hirofumi MZ         pMAPISendMailW(0, (ULONG_PTR)hWnd, &messageW, MAPI_DIALOG | MAPI_LOGON_UI, 0);
176ba53f72aSKatayama Hirofumi MZ         ::FreeLibrary(hMAPI);
177ba53f72aSKatayama Hirofumi MZ         return TRUE; // MAPISendMailW will show an error message on failure
178ba53f72aSKatayama Hirofumi MZ     }
179ba53f72aSKatayama Hirofumi MZ 
180ba53f72aSKatayama Hirofumi MZ     // Convert to ANSI strings
181ba53f72aSKatayama Hirofumi MZ     CStringA szPathNameA(pszPathName), szFileTitleA(strFileTitle);
182ba53f72aSKatayama Hirofumi MZ 
183ba53f72aSKatayama Hirofumi MZ     MapiFileDesc attachment = { 0 };
184ba53f72aSKatayama Hirofumi MZ     attachment.nPosition = (ULONG)-1;
185ba53f72aSKatayama Hirofumi MZ     attachment.lpszPathName = (LPSTR)(LPCSTR)szPathNameA;
186ba53f72aSKatayama Hirofumi MZ     attachment.lpszFileName = (LPSTR)(LPCSTR)szFileTitleA;
187ba53f72aSKatayama Hirofumi MZ 
188ba53f72aSKatayama Hirofumi MZ     MapiMessage message = { 0 };
189ba53f72aSKatayama Hirofumi MZ     message.lpszSubject = NULL;
190ba53f72aSKatayama Hirofumi MZ     message.nFileCount = 1;
191ba53f72aSKatayama Hirofumi MZ     message.lpFiles = &attachment;
192ba53f72aSKatayama Hirofumi MZ 
193ba53f72aSKatayama Hirofumi MZ     // Try again but in ANSI version
194ba53f72aSKatayama Hirofumi MZ     FN_MAPISendMail pMAPISendMail = (FN_MAPISendMail)::GetProcAddress(hMAPI, "MAPISendMail");
195ba53f72aSKatayama Hirofumi MZ     if (pMAPISendMail)
196ba53f72aSKatayama Hirofumi MZ     {
197ba53f72aSKatayama Hirofumi MZ         pMAPISendMail(0, (ULONG_PTR)hWnd, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0);
198ba53f72aSKatayama Hirofumi MZ         ::FreeLibrary(hMAPI);
199ba53f72aSKatayama Hirofumi MZ         return TRUE; // MAPISendMail will show an error message on failure
200ba53f72aSKatayama Hirofumi MZ     }
201ba53f72aSKatayama Hirofumi MZ 
202ba53f72aSKatayama Hirofumi MZ     ::FreeLibrary(hMAPI);
203ba53f72aSKatayama Hirofumi MZ     return FALSE; // Failure
204ba53f72aSKatayama Hirofumi MZ }
205ba53f72aSKatayama Hirofumi MZ 
GetOpenFileName(IN OUT LPWSTR pszFile,INT cchMaxFile)206640d67d1SKatayama Hirofumi MZ BOOL CMainWindow::GetOpenFileName(IN OUT LPWSTR pszFile, INT cchMaxFile)
207c2c66affSColin Finck {
208640d67d1SKatayama Hirofumi MZ     static OPENFILENAMEW ofn = { 0 };
209640d67d1SKatayama Hirofumi MZ     static CStringW strFilter;
210c2c66affSColin Finck 
21129e147beSKatayama Hirofumi MZ     if (ofn.lStructSize == 0)
212c2c66affSColin Finck     {
21329e147beSKatayama Hirofumi MZ         // The "All Files" item text
214640d67d1SKatayama Hirofumi MZ         CStringW strAllPictureFiles;
215e8c7e300SKatayama Hirofumi MZ         strAllPictureFiles.LoadString(g_hinstExe, IDS_ALLPICTUREFILES);
21629e147beSKatayama Hirofumi MZ 
21729e147beSKatayama Hirofumi MZ         // Get the import filter
21829e147beSKatayama Hirofumi MZ         CSimpleArray<GUID> aguidFileTypesI;
21929e147beSKatayama Hirofumi MZ         CImage::GetImporterFilterString(strFilter, aguidFileTypesI, strAllPictureFiles,
220b69a7460SKatayama Hirofumi MZ                                         CImage::excludeDefaultLoad, L'|');
221b69a7460SKatayama Hirofumi MZ         strFilter.Replace(L'|', UNICODE_NULL);
22229e147beSKatayama Hirofumi MZ 
22329e147beSKatayama Hirofumi MZ         // Initializing the OPENFILENAME structure for GetOpenFileName
22429e147beSKatayama Hirofumi MZ         ZeroMemory(&ofn, sizeof(ofn));
22529e147beSKatayama Hirofumi MZ         ofn.lStructSize = sizeof(ofn);
22629e147beSKatayama Hirofumi MZ         ofn.hwndOwner   = m_hWnd;
227e8c7e300SKatayama Hirofumi MZ         ofn.hInstance   = g_hinstExe;
22829e147beSKatayama Hirofumi MZ         ofn.lpstrFilter = strFilter;
229bebdfda8SKatayama Hirofumi MZ         ofn.Flags       = OFN_EXPLORER | OFN_HIDEREADONLY;
2304e6e22e6SKatayama Hirofumi MZ         ofn.lpstrDefExt = L"png";
23129e147beSKatayama Hirofumi MZ     }
232c2c66affSColin Finck 
23329e147beSKatayama Hirofumi MZ     ofn.lpstrFile = pszFile;
23429e147beSKatayama Hirofumi MZ     ofn.nMaxFile  = cchMaxFile;
235640d67d1SKatayama Hirofumi MZ     return ::GetOpenFileNameW(&ofn);
23629e147beSKatayama Hirofumi MZ }
23729e147beSKatayama Hirofumi MZ 
GetSaveFileName(IN OUT LPWSTR pszFile,INT cchMaxFile)238640d67d1SKatayama Hirofumi MZ BOOL CMainWindow::GetSaveFileName(IN OUT LPWSTR pszFile, INT cchMaxFile)
23929e147beSKatayama Hirofumi MZ {
240640d67d1SKatayama Hirofumi MZ     static OPENFILENAMEW sfn = { 0 };
241640d67d1SKatayama Hirofumi MZ     static CStringW strFilter;
24229e147beSKatayama Hirofumi MZ 
24329e147beSKatayama Hirofumi MZ     if (sfn.lStructSize == 0)
24429e147beSKatayama Hirofumi MZ     {
24529e147beSKatayama Hirofumi MZ         // Get the export filter
246c2c66affSColin Finck         CSimpleArray<GUID> aguidFileTypesE;
24729e147beSKatayama Hirofumi MZ         CImage::GetExporterFilterString(strFilter, aguidFileTypesE, NULL,
248b69a7460SKatayama Hirofumi MZ                                         CImage::excludeDefaultSave, L'|');
249b69a7460SKatayama Hirofumi MZ         strFilter.Replace(L'|', UNICODE_NULL);
25029e147beSKatayama Hirofumi MZ 
25129e147beSKatayama Hirofumi MZ         // Initializing the OPENFILENAME structure for GetSaveFileName
25229e147beSKatayama Hirofumi MZ         ZeroMemory(&sfn, sizeof(sfn));
25329e147beSKatayama Hirofumi MZ         sfn.lStructSize = sizeof(sfn);
25429e147beSKatayama Hirofumi MZ         sfn.hwndOwner   = m_hWnd;
255e8c7e300SKatayama Hirofumi MZ         sfn.hInstance   = g_hinstExe;
25629e147beSKatayama Hirofumi MZ         sfn.lpstrFilter = strFilter;
25729e147beSKatayama Hirofumi MZ         sfn.Flags       = OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_ENABLEHOOK;
258c2c66affSColin Finck         sfn.lpfnHook    = OFNHookProc;
2594e6e22e6SKatayama Hirofumi MZ         sfn.lpstrDefExt = L"png";
26029e147beSKatayama Hirofumi MZ 
26119d88628SKatayama Hirofumi MZ         LPWSTR pchDotExt = PathFindExtensionW(pszFile);
26219d88628SKatayama Hirofumi MZ         if (*pchDotExt == UNICODE_NULL)
26319d88628SKatayama Hirofumi MZ         {
2644e6e22e6SKatayama Hirofumi MZ             // Choose PNG
265d7ece626SKatayama Hirofumi MZ             StringCchCatW(pszFile, cchMaxFile, L".png");
2664e6e22e6SKatayama Hirofumi MZ             for (INT i = 0; i < aguidFileTypesE.GetSize(); ++i)
2674e6e22e6SKatayama Hirofumi MZ             {
2684e6e22e6SKatayama Hirofumi MZ                 if (aguidFileTypesE[i] == Gdiplus::ImageFormatPNG)
2694e6e22e6SKatayama Hirofumi MZ                 {
2704e6e22e6SKatayama Hirofumi MZ                     sfn.nFilterIndex = i + 1;
2714e6e22e6SKatayama Hirofumi MZ                     break;
2724e6e22e6SKatayama Hirofumi MZ                 }
2734e6e22e6SKatayama Hirofumi MZ             }
274c2c66affSColin Finck         }
27519d88628SKatayama Hirofumi MZ     }
276c2c66affSColin Finck 
27729e147beSKatayama Hirofumi MZ     sfn.lpstrFile = pszFile;
27829e147beSKatayama Hirofumi MZ     sfn.nMaxFile  = cchMaxFile;
279640d67d1SKatayama Hirofumi MZ     return ::GetSaveFileNameW(&sfn);
28029e147beSKatayama Hirofumi MZ }
28129e147beSKatayama Hirofumi MZ 
ChooseColor(IN OUT COLORREF * prgbColor)28229e147beSKatayama Hirofumi MZ BOOL CMainWindow::ChooseColor(IN OUT COLORREF *prgbColor)
28329e147beSKatayama Hirofumi MZ {
28429e147beSKatayama Hirofumi MZ     static CHOOSECOLOR choosecolor = { 0 };
28529e147beSKatayama Hirofumi MZ     static COLORREF custColors[16] =
28629e147beSKatayama Hirofumi MZ     {
28729e147beSKatayama Hirofumi MZ         0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
28829e147beSKatayama Hirofumi MZ         0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
28929e147beSKatayama Hirofumi MZ     };
29029e147beSKatayama Hirofumi MZ 
29129e147beSKatayama Hirofumi MZ     if (choosecolor.lStructSize == 0)
29229e147beSKatayama Hirofumi MZ     {
29329e147beSKatayama Hirofumi MZ         // Initializing the CHOOSECOLOR structure for ChooseColor
29429e147beSKatayama Hirofumi MZ         ZeroMemory(&choosecolor, sizeof(choosecolor));
29529e147beSKatayama Hirofumi MZ         choosecolor.lStructSize  = sizeof(choosecolor);
29629e147beSKatayama Hirofumi MZ         choosecolor.hwndOwner    = m_hWnd;
29729e147beSKatayama Hirofumi MZ         choosecolor.lpCustColors = custColors;
29829e147beSKatayama Hirofumi MZ     }
29929e147beSKatayama Hirofumi MZ 
3000087ea65SKatayama Hirofumi MZ     choosecolor.Flags = CC_RGBINIT;
30129e147beSKatayama Hirofumi MZ     choosecolor.rgbResult = *prgbColor;
30229e147beSKatayama Hirofumi MZ     if (!::ChooseColor(&choosecolor))
30329e147beSKatayama Hirofumi MZ         return FALSE;
30429e147beSKatayama Hirofumi MZ 
30529e147beSKatayama Hirofumi MZ     *prgbColor = choosecolor.rgbResult;
30629e147beSKatayama Hirofumi MZ     return TRUE;
30729e147beSKatayama Hirofumi MZ }
30829e147beSKatayama Hirofumi MZ 
DoCreate()30929e147beSKatayama Hirofumi MZ HWND CMainWindow::DoCreate()
31029e147beSKatayama Hirofumi MZ {
311640d67d1SKatayama Hirofumi MZ     ::LoadStringW(g_hinstExe, IDS_DEFAULTFILENAME, g_szFileName, _countof(g_szFileName));
31229e147beSKatayama Hirofumi MZ 
313640d67d1SKatayama Hirofumi MZ     CStringW strTitle;
314e8c7e300SKatayama Hirofumi MZ     strTitle.Format(IDS_WINDOWTITLE, PathFindFileName(g_szFileName));
31529e147beSKatayama Hirofumi MZ 
31629e147beSKatayama Hirofumi MZ     RECT& rc = registrySettings.WindowPlacement.rcNormalPosition;
31729e147beSKatayama Hirofumi MZ     return Create(HWND_DESKTOP, rc, strTitle, WS_OVERLAPPEDWINDOW, WS_EX_ACCEPTFILES);
31829e147beSKatayama Hirofumi MZ }
31929e147beSKatayama Hirofumi MZ 
320bf13ebdaSKatayama Hirofumi MZ // A wrapper function for HtmlHelpW
DoHtmlHelpW(HWND hwndCaller,LPCWSTR pszFile,UINT uCommand,DWORD_PTR dwData)321bf13ebdaSKatayama Hirofumi MZ static HWND DoHtmlHelpW(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData)
322bf13ebdaSKatayama Hirofumi MZ {
323bf13ebdaSKatayama Hirofumi MZ     WCHAR szPath[MAX_PATH];
324bf13ebdaSKatayama Hirofumi MZ 
325bf13ebdaSKatayama Hirofumi MZ     if (!s_hHHCTRL_OCX && (uCommand != HH_CLOSE_ALL))
326bf13ebdaSKatayama Hirofumi MZ     {
327bf13ebdaSKatayama Hirofumi MZ         // The function loads the system library, not local
328bf13ebdaSKatayama Hirofumi MZ         GetSystemDirectoryW(szPath, _countof(szPath));
329bf13ebdaSKatayama Hirofumi MZ         StringCchCatW(szPath, _countof(szPath), L"\\hhctrl.ocx");
330bf13ebdaSKatayama Hirofumi MZ         s_hHHCTRL_OCX = LoadLibraryW(szPath);
331bf13ebdaSKatayama Hirofumi MZ         if (s_hHHCTRL_OCX)
332bf13ebdaSKatayama Hirofumi MZ             s_pHtmlHelpW = (FN_HtmlHelpW)GetProcAddress(s_hHHCTRL_OCX, "HtmlHelpW");
333bf13ebdaSKatayama Hirofumi MZ     }
334bf13ebdaSKatayama Hirofumi MZ 
335bf13ebdaSKatayama Hirofumi MZ     if (!s_pHtmlHelpW)
336bf13ebdaSKatayama Hirofumi MZ         return NULL;
337bf13ebdaSKatayama Hirofumi MZ 
338bf13ebdaSKatayama Hirofumi MZ     return s_pHtmlHelpW(hwndCaller, pszFile, uCommand, dwData);
339bf13ebdaSKatayama Hirofumi MZ }
340bf13ebdaSKatayama Hirofumi MZ 
alignChildrenToMainWindow()341bf13ebdaSKatayama Hirofumi MZ void CMainWindow::alignChildrenToMainWindow()
342bf13ebdaSKatayama Hirofumi MZ {
343bf13ebdaSKatayama Hirofumi MZ     RECT clientRect, rc;
344bf13ebdaSKatayama Hirofumi MZ     GetClientRect(&clientRect);
345bf13ebdaSKatayama Hirofumi MZ     RECT rcSpace = clientRect;
346bf13ebdaSKatayama Hirofumi MZ     const UINT uFlags = (SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOCOPYBITS);
347bf13ebdaSKatayama Hirofumi MZ 
348bf13ebdaSKatayama Hirofumi MZ     if (::IsWindowVisible(g_hStatusBar))
349bf13ebdaSKatayama Hirofumi MZ     {
350bf13ebdaSKatayama Hirofumi MZ         ::GetWindowRect(g_hStatusBar, &rc);
351bf13ebdaSKatayama Hirofumi MZ         rcSpace.bottom -= rc.bottom - rc.top;
352bf13ebdaSKatayama Hirofumi MZ     }
353bf13ebdaSKatayama Hirofumi MZ 
354bf13ebdaSKatayama Hirofumi MZ     HDWP hDWP = ::BeginDeferWindowPos(3);
355bf13ebdaSKatayama Hirofumi MZ 
356bf13ebdaSKatayama Hirofumi MZ     if (::IsWindowVisible(toolBoxContainer))
357bf13ebdaSKatayama Hirofumi MZ     {
358bf13ebdaSKatayama Hirofumi MZ         if (registrySettings.Bar2ID == BAR2ID_RIGHT)
359bf13ebdaSKatayama Hirofumi MZ         {
360bf13ebdaSKatayama Hirofumi MZ             hDWP = ::DeferWindowPos(hDWP, toolBoxContainer, NULL,
361bf13ebdaSKatayama Hirofumi MZ                                     rcSpace.right - CX_TOOLBAR, rcSpace.top,
362bf13ebdaSKatayama Hirofumi MZ                                     CX_TOOLBAR, rcSpace.bottom - rcSpace.top,
363bf13ebdaSKatayama Hirofumi MZ                                     uFlags);
364bf13ebdaSKatayama Hirofumi MZ             rcSpace.right -= CX_TOOLBAR;
365bf13ebdaSKatayama Hirofumi MZ         }
366bf13ebdaSKatayama Hirofumi MZ         else
367bf13ebdaSKatayama Hirofumi MZ         {
368bf13ebdaSKatayama Hirofumi MZ             hDWP = ::DeferWindowPos(hDWP, toolBoxContainer, NULL,
369bf13ebdaSKatayama Hirofumi MZ                                     rcSpace.left, rcSpace.top,
370bf13ebdaSKatayama Hirofumi MZ                                     CX_TOOLBAR, rcSpace.bottom - rcSpace.top,
371bf13ebdaSKatayama Hirofumi MZ                                     uFlags);
372bf13ebdaSKatayama Hirofumi MZ             rcSpace.left += CX_TOOLBAR;
373bf13ebdaSKatayama Hirofumi MZ         }
374bf13ebdaSKatayama Hirofumi MZ     }
375bf13ebdaSKatayama Hirofumi MZ 
376bf13ebdaSKatayama Hirofumi MZ     if (::IsWindowVisible(paletteWindow))
377bf13ebdaSKatayama Hirofumi MZ     {
378bf13ebdaSKatayama Hirofumi MZ         if (registrySettings.Bar1ID == BAR1ID_BOTTOM)
379bf13ebdaSKatayama Hirofumi MZ         {
380bf13ebdaSKatayama Hirofumi MZ             hDWP = ::DeferWindowPos(hDWP, paletteWindow, NULL,
381bf13ebdaSKatayama Hirofumi MZ                                     rcSpace.left, rcSpace.bottom - CY_PALETTE,
382bf13ebdaSKatayama Hirofumi MZ                                     rcSpace.right - rcSpace.left, CY_PALETTE,
383bf13ebdaSKatayama Hirofumi MZ                                     uFlags);
384bf13ebdaSKatayama Hirofumi MZ             rcSpace.bottom -= CY_PALETTE;
385bf13ebdaSKatayama Hirofumi MZ         }
386bf13ebdaSKatayama Hirofumi MZ         else
387bf13ebdaSKatayama Hirofumi MZ         {
388bf13ebdaSKatayama Hirofumi MZ             hDWP = ::DeferWindowPos(hDWP, paletteWindow, NULL,
389bf13ebdaSKatayama Hirofumi MZ                                     rcSpace.left, rcSpace.top,
390bf13ebdaSKatayama Hirofumi MZ                                     rcSpace.right - rcSpace.left, CY_PALETTE,
391bf13ebdaSKatayama Hirofumi MZ                                     uFlags);
392bf13ebdaSKatayama Hirofumi MZ             rcSpace.top += CY_PALETTE;
393bf13ebdaSKatayama Hirofumi MZ         }
394bf13ebdaSKatayama Hirofumi MZ     }
395bf13ebdaSKatayama Hirofumi MZ 
396bf13ebdaSKatayama Hirofumi MZ     if (canvasWindow.IsWindow())
397bf13ebdaSKatayama Hirofumi MZ     {
398bf13ebdaSKatayama Hirofumi MZ         hDWP = ::DeferWindowPos(hDWP, canvasWindow, NULL,
399bf13ebdaSKatayama Hirofumi MZ                                 rcSpace.left, rcSpace.top,
400bf13ebdaSKatayama Hirofumi MZ                                 rcSpace.right - rcSpace.left, rcSpace.bottom - rcSpace.top,
401bf13ebdaSKatayama Hirofumi MZ                                 uFlags);
402bf13ebdaSKatayama Hirofumi MZ     }
403bf13ebdaSKatayama Hirofumi MZ 
404bf13ebdaSKatayama Hirofumi MZ     ::EndDeferWindowPos(hDWP);
405bf13ebdaSKatayama Hirofumi MZ }
406bf13ebdaSKatayama Hirofumi MZ 
saveImage(BOOL overwrite)407bf13ebdaSKatayama Hirofumi MZ void CMainWindow::saveImage(BOOL overwrite)
408bf13ebdaSKatayama Hirofumi MZ {
409b8598e09SKatayama Hirofumi MZ     canvasWindow.OnEndDraw(FALSE);
410bf13ebdaSKatayama Hirofumi MZ 
411bf13ebdaSKatayama Hirofumi MZ     // Is the extension not supported?
412bf13ebdaSKatayama Hirofumi MZ     PWCHAR pchDotExt = PathFindExtensionW(g_szFileName);
413bf13ebdaSKatayama Hirofumi MZ     if (pchDotExt && *pchDotExt && !CImageDx::IsExtensionSupported(pchDotExt))
414bf13ebdaSKatayama Hirofumi MZ     {
415bf13ebdaSKatayama Hirofumi MZ         // Remove the extension
416bf13ebdaSKatayama Hirofumi MZ         PathRemoveExtensionW(g_szFileName);
417bf13ebdaSKatayama Hirofumi MZ         // No overwrite
418bf13ebdaSKatayama Hirofumi MZ         overwrite = FALSE;
419bf13ebdaSKatayama Hirofumi MZ     }
420bf13ebdaSKatayama Hirofumi MZ 
421bf13ebdaSKatayama Hirofumi MZ     if (g_isAFile && overwrite)
422bf13ebdaSKatayama Hirofumi MZ     {
423bf13ebdaSKatayama Hirofumi MZ         imageModel.SaveImage(g_szFileName);
424bf13ebdaSKatayama Hirofumi MZ     }
425bf13ebdaSKatayama Hirofumi MZ     else if (GetSaveFileName(g_szFileName, _countof(g_szFileName)))
426bf13ebdaSKatayama Hirofumi MZ     {
427bf13ebdaSKatayama Hirofumi MZ         imageModel.SaveImage(g_szFileName);
428bf13ebdaSKatayama Hirofumi MZ     }
429bf13ebdaSKatayama Hirofumi MZ }
430bf13ebdaSKatayama Hirofumi MZ 
InsertSelectionFromHBITMAP(HBITMAP bitmap,HWND window)431bf13ebdaSKatayama Hirofumi MZ void CMainWindow::InsertSelectionFromHBITMAP(HBITMAP bitmap, HWND window)
432bf13ebdaSKatayama Hirofumi MZ {
433bf13ebdaSKatayama Hirofumi MZ     int width = GetDIBWidth(bitmap);
434bf13ebdaSKatayama Hirofumi MZ     int height = GetDIBHeight(bitmap);
435bf13ebdaSKatayama Hirofumi MZ     int curWidth = imageModel.GetWidth();
436bf13ebdaSKatayama Hirofumi MZ     int curHeight = imageModel.GetHeight();
437bf13ebdaSKatayama Hirofumi MZ 
438bf13ebdaSKatayama Hirofumi MZ     if (width > curWidth || height > curHeight)
439bf13ebdaSKatayama Hirofumi MZ     {
440bf13ebdaSKatayama Hirofumi MZ         BOOL shouldEnlarge = TRUE;
441bf13ebdaSKatayama Hirofumi MZ 
442bf13ebdaSKatayama Hirofumi MZ         if (g_askBeforeEnlarging)
443bf13ebdaSKatayama Hirofumi MZ         {
444bf13ebdaSKatayama Hirofumi MZ             WCHAR programname[20];
445bf13ebdaSKatayama Hirofumi MZ             WCHAR shouldEnlargePromptText[100];
446bf13ebdaSKatayama Hirofumi MZ 
447bf13ebdaSKatayama Hirofumi MZ             ::LoadStringW(g_hinstExe, IDS_PROGRAMNAME, programname, _countof(programname));
448bf13ebdaSKatayama Hirofumi MZ             ::LoadStringW(g_hinstExe, IDS_ENLARGEPROMPTTEXT, shouldEnlargePromptText, _countof(shouldEnlargePromptText));
449bf13ebdaSKatayama Hirofumi MZ 
450bf13ebdaSKatayama Hirofumi MZ             switch (MessageBox(shouldEnlargePromptText, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
451bf13ebdaSKatayama Hirofumi MZ             {
452bf13ebdaSKatayama Hirofumi MZ                 case IDYES:
453bf13ebdaSKatayama Hirofumi MZ                     break;
454bf13ebdaSKatayama Hirofumi MZ                 case IDNO:
455bf13ebdaSKatayama Hirofumi MZ                     shouldEnlarge = FALSE;
456bf13ebdaSKatayama Hirofumi MZ                     break;
457bf13ebdaSKatayama Hirofumi MZ                 case IDCANCEL:
458bf13ebdaSKatayama Hirofumi MZ                     return;
459bf13ebdaSKatayama Hirofumi MZ             }
460bf13ebdaSKatayama Hirofumi MZ         }
461bf13ebdaSKatayama Hirofumi MZ 
462bf13ebdaSKatayama Hirofumi MZ         if (shouldEnlarge)
463bf13ebdaSKatayama Hirofumi MZ         {
464bf13ebdaSKatayama Hirofumi MZ             if (width > curWidth)
465bf13ebdaSKatayama Hirofumi MZ                 curWidth = width;
466bf13ebdaSKatayama Hirofumi MZ 
467bf13ebdaSKatayama Hirofumi MZ             if (height > curHeight)
468bf13ebdaSKatayama Hirofumi MZ                 curHeight = height;
469bf13ebdaSKatayama Hirofumi MZ 
470bf13ebdaSKatayama Hirofumi MZ             imageModel.Crop(curWidth, curHeight, 0, 0);
471bf13ebdaSKatayama Hirofumi MZ         }
472bf13ebdaSKatayama Hirofumi MZ     }
473bf13ebdaSKatayama Hirofumi MZ 
474bf13ebdaSKatayama Hirofumi MZ     toolsModel.SetActiveTool(TOOL_RECTSEL);
475bf13ebdaSKatayama Hirofumi MZ 
476bf13ebdaSKatayama Hirofumi MZ     selectionModel.InsertFromHBITMAP(bitmap, 0, 0);
477bf13ebdaSKatayama Hirofumi MZ     selectionModel.m_bShow = TRUE;
478bf13ebdaSKatayama Hirofumi MZ     imageModel.NotifyImageChanged();
479bf13ebdaSKatayama Hirofumi MZ }
480bf13ebdaSKatayama Hirofumi MZ 
OnMouseWheel(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)481bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
482bf13ebdaSKatayama Hirofumi MZ {
483bf13ebdaSKatayama Hirofumi MZ     INT zDelta = (SHORT)HIWORD(wParam);
484bf13ebdaSKatayama Hirofumi MZ 
485bf13ebdaSKatayama Hirofumi MZ     if (::GetKeyState(VK_CONTROL) < 0) // Ctrl+Wheel
486bf13ebdaSKatayama Hirofumi MZ     {
487bf13ebdaSKatayama Hirofumi MZ         if (zDelta < 0)
488bf13ebdaSKatayama Hirofumi MZ         {
489bf13ebdaSKatayama Hirofumi MZ             if (toolsModel.GetZoom() > MIN_ZOOM)
490bf13ebdaSKatayama Hirofumi MZ                 canvasWindow.zoomTo(toolsModel.GetZoom() / 2);
491bf13ebdaSKatayama Hirofumi MZ         }
492bf13ebdaSKatayama Hirofumi MZ         else if (zDelta > 0)
493bf13ebdaSKatayama Hirofumi MZ         {
494bf13ebdaSKatayama Hirofumi MZ             if (toolsModel.GetZoom() < MAX_ZOOM)
495bf13ebdaSKatayama Hirofumi MZ                 canvasWindow.zoomTo(toolsModel.GetZoom() * 2);
496bf13ebdaSKatayama Hirofumi MZ         }
497bf13ebdaSKatayama Hirofumi MZ     }
498bf13ebdaSKatayama Hirofumi MZ     else // Wheel only
499bf13ebdaSKatayama Hirofumi MZ     {
500bf13ebdaSKatayama Hirofumi MZ         UINT nCount = 3;
501bf13ebdaSKatayama Hirofumi MZ         if (::GetAsyncKeyState(VK_SHIFT) < 0)
502bf13ebdaSKatayama Hirofumi MZ         {
503bf13ebdaSKatayama Hirofumi MZ #ifndef SPI_GETWHEELSCROLLCHARS
504bf13ebdaSKatayama Hirofumi MZ     #define SPI_GETWHEELSCROLLCHARS 0x006C  // Needed for pre-NT6 PSDK
505bf13ebdaSKatayama Hirofumi MZ #endif
506bf13ebdaSKatayama Hirofumi MZ             SystemParametersInfoW(SPI_GETWHEELSCROLLCHARS, 0, &nCount, 0);
507bf13ebdaSKatayama Hirofumi MZ             for (UINT i = 0; i < nCount; ++i)
508bf13ebdaSKatayama Hirofumi MZ             {
509bf13ebdaSKatayama Hirofumi MZ                 if (zDelta < 0)
510bf13ebdaSKatayama Hirofumi MZ                     ::PostMessageW(canvasWindow, WM_HSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
511bf13ebdaSKatayama Hirofumi MZ                 else if (zDelta > 0)
512bf13ebdaSKatayama Hirofumi MZ                     ::PostMessageW(canvasWindow, WM_HSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
513bf13ebdaSKatayama Hirofumi MZ             }
514bf13ebdaSKatayama Hirofumi MZ         }
515bf13ebdaSKatayama Hirofumi MZ         else
516bf13ebdaSKatayama Hirofumi MZ         {
517bf13ebdaSKatayama Hirofumi MZ             SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &nCount, 0);
518bf13ebdaSKatayama Hirofumi MZ             for (UINT i = 0; i < nCount; ++i)
519bf13ebdaSKatayama Hirofumi MZ             {
520bf13ebdaSKatayama Hirofumi MZ                 if (zDelta < 0)
521bf13ebdaSKatayama Hirofumi MZ                     ::PostMessageW(canvasWindow, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
522bf13ebdaSKatayama Hirofumi MZ                 else if (zDelta > 0)
523bf13ebdaSKatayama Hirofumi MZ                     ::PostMessageW(canvasWindow, WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), 0);
524bf13ebdaSKatayama Hirofumi MZ             }
525bf13ebdaSKatayama Hirofumi MZ         }
526bf13ebdaSKatayama Hirofumi MZ     }
527bf13ebdaSKatayama Hirofumi MZ 
528bf13ebdaSKatayama Hirofumi MZ     return 0;
529bf13ebdaSKatayama Hirofumi MZ }
530bf13ebdaSKatayama Hirofumi MZ 
OnDropFiles(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)531bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnDropFiles(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
532bf13ebdaSKatayama Hirofumi MZ {
533bf13ebdaSKatayama Hirofumi MZ     WCHAR droppedfile[MAX_PATH];
534bf13ebdaSKatayama Hirofumi MZ 
535bf13ebdaSKatayama Hirofumi MZ     HDROP hDrop = (HDROP)wParam;
536bf13ebdaSKatayama Hirofumi MZ     DragQueryFile(hDrop, 0, droppedfile, _countof(droppedfile));
537bf13ebdaSKatayama Hirofumi MZ     DragFinish(hDrop);
538bf13ebdaSKatayama Hirofumi MZ 
539bf13ebdaSKatayama Hirofumi MZ     ConfirmSave() && DoLoadImageFile(m_hWnd, droppedfile, TRUE);
540bf13ebdaSKatayama Hirofumi MZ 
541bf13ebdaSKatayama Hirofumi MZ     return 0;
542bf13ebdaSKatayama Hirofumi MZ }
543bf13ebdaSKatayama Hirofumi MZ 
OnCreate(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)544bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
545bf13ebdaSKatayama Hirofumi MZ {
546bf13ebdaSKatayama Hirofumi MZ     // Loading and setting the window menu from resource
547bf13ebdaSKatayama Hirofumi MZ     m_hMenu = ::LoadMenuW(g_hinstExe, MAKEINTRESOURCEW(ID_MENU));
548bf13ebdaSKatayama Hirofumi MZ     SetMenu(m_hMenu);
549bf13ebdaSKatayama Hirofumi MZ 
550bf13ebdaSKatayama Hirofumi MZ     // Create the status bar
551bf13ebdaSKatayama Hirofumi MZ     DWORD style = SBARS_SIZEGRIP | WS_CHILD | (registrySettings.ShowStatusBar ? WS_VISIBLE : 0);
552bf13ebdaSKatayama Hirofumi MZ     g_hStatusBar = ::CreateWindowExW(0, STATUSCLASSNAME, NULL, style, 0, 0, 0, 0, m_hWnd,
553bf13ebdaSKatayama Hirofumi MZ                                      NULL, g_hinstExe, NULL);
554bf13ebdaSKatayama Hirofumi MZ     ::SendMessageW(g_hStatusBar, SB_SETMINHEIGHT, 21, 0);
555bf13ebdaSKatayama Hirofumi MZ 
556bf13ebdaSKatayama Hirofumi MZ     // Create the tool box
557bf13ebdaSKatayama Hirofumi MZ     toolBoxContainer.DoCreate(m_hWnd);
558bf13ebdaSKatayama Hirofumi MZ 
559bf13ebdaSKatayama Hirofumi MZ     // Create the palette window
560bf13ebdaSKatayama Hirofumi MZ     RECT rcEmpty = { 0, 0, 0, 0 }; // Rely on WM_SIZE
561bf13ebdaSKatayama Hirofumi MZ     style = WS_CHILD | (registrySettings.ShowPalette ? WS_VISIBLE : 0);
562bf13ebdaSKatayama Hirofumi MZ     paletteWindow.Create(m_hWnd, rcEmpty, NULL, style, WS_EX_STATICEDGE);
563bf13ebdaSKatayama Hirofumi MZ 
564bf13ebdaSKatayama Hirofumi MZ     // Create the canvas
565bf13ebdaSKatayama Hirofumi MZ     style = WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE;
566bf13ebdaSKatayama Hirofumi MZ     canvasWindow.Create(m_hWnd, rcEmpty, NULL, style, WS_EX_CLIENTEDGE);
567bf13ebdaSKatayama Hirofumi MZ 
568bf13ebdaSKatayama Hirofumi MZ     // Create and show the miniature if necessary
569bf13ebdaSKatayama Hirofumi MZ     if (registrySettings.ShowThumbnail)
570bf13ebdaSKatayama Hirofumi MZ     {
571bf13ebdaSKatayama Hirofumi MZ         miniature.DoCreate(m_hWnd);
572bf13ebdaSKatayama Hirofumi MZ         miniature.ShowWindow(SW_SHOWNOACTIVATE);
573bf13ebdaSKatayama Hirofumi MZ     }
574bf13ebdaSKatayama Hirofumi MZ 
575bf13ebdaSKatayama Hirofumi MZ     // Set icon
576bf13ebdaSKatayama Hirofumi MZ     SendMessage(WM_SETICON, ICON_BIG, (LPARAM)::LoadIconW(g_hinstExe, MAKEINTRESOURCEW(IDI_APPICON)));
577bf13ebdaSKatayama Hirofumi MZ     SendMessage(WM_SETICON, ICON_SMALL, (LPARAM)::LoadIconW(g_hinstExe, MAKEINTRESOURCEW(IDI_APPICON)));
578bf13ebdaSKatayama Hirofumi MZ 
579bf13ebdaSKatayama Hirofumi MZ     return 0;
580bf13ebdaSKatayama Hirofumi MZ }
581bf13ebdaSKatayama Hirofumi MZ 
OnDestroy(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)582bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnDestroy(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
583bf13ebdaSKatayama Hirofumi MZ {
584bf13ebdaSKatayama Hirofumi MZ     registrySettings.WindowPlacement.length = sizeof(WINDOWPLACEMENT);
585bf13ebdaSKatayama Hirofumi MZ     GetWindowPlacement(&(registrySettings.WindowPlacement));
586bf13ebdaSKatayama Hirofumi MZ 
587bf13ebdaSKatayama Hirofumi MZ     DoHtmlHelpW(NULL, NULL, HH_CLOSE_ALL, 0);
588bf13ebdaSKatayama Hirofumi MZ 
589bf13ebdaSKatayama Hirofumi MZ     if (s_hHHCTRL_OCX)
590bf13ebdaSKatayama Hirofumi MZ     {
591bf13ebdaSKatayama Hirofumi MZ         FreeLibrary(s_hHHCTRL_OCX);
592bf13ebdaSKatayama Hirofumi MZ         s_hHHCTRL_OCX = NULL;
593bf13ebdaSKatayama Hirofumi MZ         s_pHtmlHelpW = NULL;
594bf13ebdaSKatayama Hirofumi MZ     }
595bf13ebdaSKatayama Hirofumi MZ 
596bf13ebdaSKatayama Hirofumi MZ     SetMenu(NULL);
597bf13ebdaSKatayama Hirofumi MZ     if (m_hMenu)
598bf13ebdaSKatayama Hirofumi MZ     {
599bf13ebdaSKatayama Hirofumi MZ         ::DestroyMenu(m_hMenu);
600bf13ebdaSKatayama Hirofumi MZ         m_hMenu = NULL;
601bf13ebdaSKatayama Hirofumi MZ     }
602bf13ebdaSKatayama Hirofumi MZ 
603bf13ebdaSKatayama Hirofumi MZ     PostQuitMessage(0); /* send a WM_QUIT to the message queue */
604bf13ebdaSKatayama Hirofumi MZ     return 0;
605bf13ebdaSKatayama Hirofumi MZ }
606bf13ebdaSKatayama Hirofumi MZ 
ConfirmSave()607bf13ebdaSKatayama Hirofumi MZ BOOL CMainWindow::ConfirmSave()
608bf13ebdaSKatayama Hirofumi MZ {
609b8598e09SKatayama Hirofumi MZ     canvasWindow.OnEndDraw(FALSE);
610bf13ebdaSKatayama Hirofumi MZ 
611bf13ebdaSKatayama Hirofumi MZ     if (imageModel.IsImageSaved())
612bf13ebdaSKatayama Hirofumi MZ         return TRUE;
613bf13ebdaSKatayama Hirofumi MZ 
614bf13ebdaSKatayama Hirofumi MZ     CStringW strProgramName;
615bf13ebdaSKatayama Hirofumi MZ     strProgramName.LoadString(IDS_PROGRAMNAME);
616bf13ebdaSKatayama Hirofumi MZ 
617bf13ebdaSKatayama Hirofumi MZ     CStringW strSavePromptText;
618bf13ebdaSKatayama Hirofumi MZ     strSavePromptText.Format(IDS_SAVEPROMPTTEXT, PathFindFileName(g_szFileName));
619bf13ebdaSKatayama Hirofumi MZ 
620bf13ebdaSKatayama Hirofumi MZ     switch (MessageBox(strSavePromptText, strProgramName, MB_YESNOCANCEL | MB_ICONQUESTION))
621bf13ebdaSKatayama Hirofumi MZ     {
622bf13ebdaSKatayama Hirofumi MZ         case IDYES:
623bf13ebdaSKatayama Hirofumi MZ             saveImage(TRUE);
624bf13ebdaSKatayama Hirofumi MZ             return imageModel.IsImageSaved();
625bf13ebdaSKatayama Hirofumi MZ         case IDNO:
626bf13ebdaSKatayama Hirofumi MZ             return TRUE;
627bf13ebdaSKatayama Hirofumi MZ         case IDCANCEL:
628bf13ebdaSKatayama Hirofumi MZ             return FALSE;
629bf13ebdaSKatayama Hirofumi MZ     }
630bf13ebdaSKatayama Hirofumi MZ 
631bf13ebdaSKatayama Hirofumi MZ     return TRUE;
632bf13ebdaSKatayama Hirofumi MZ }
633bf13ebdaSKatayama Hirofumi MZ 
OnClose(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)634bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
635bf13ebdaSKatayama Hirofumi MZ {
636bf13ebdaSKatayama Hirofumi MZ     if (ConfirmSave())
637bf13ebdaSKatayama Hirofumi MZ     {
638bf13ebdaSKatayama Hirofumi MZ         DestroyWindow();
639bf13ebdaSKatayama Hirofumi MZ     }
640bf13ebdaSKatayama Hirofumi MZ     return 0;
641bf13ebdaSKatayama Hirofumi MZ }
642bf13ebdaSKatayama Hirofumi MZ 
ProcessFileMenu(HMENU hPopupMenu)643bf13ebdaSKatayama Hirofumi MZ void CMainWindow::ProcessFileMenu(HMENU hPopupMenu)
644bf13ebdaSKatayama Hirofumi MZ {
645bf13ebdaSKatayama Hirofumi MZ     for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem)
646bf13ebdaSKatayama Hirofumi MZ         RemoveMenu(hPopupMenu, IDM_FILE1 + iItem, MF_BYCOMMAND);
647bf13ebdaSKatayama Hirofumi MZ 
648bf13ebdaSKatayama Hirofumi MZ     if (registrySettings.strFiles[0].IsEmpty())
649bf13ebdaSKatayama Hirofumi MZ         return;
650bf13ebdaSKatayama Hirofumi MZ 
651bf13ebdaSKatayama Hirofumi MZ     RemoveMenu(hPopupMenu, IDM_FILEMOSTRECENTLYUSEDFILE, MF_BYCOMMAND);
652bf13ebdaSKatayama Hirofumi MZ 
653bf13ebdaSKatayama Hirofumi MZ     INT cMenuItems = GetMenuItemCount(hPopupMenu);
654bf13ebdaSKatayama Hirofumi MZ 
655bf13ebdaSKatayama Hirofumi MZ     for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem)
656bf13ebdaSKatayama Hirofumi MZ     {
657bf13ebdaSKatayama Hirofumi MZ         CStringW& strFile = registrySettings.strFiles[iItem];
658bf13ebdaSKatayama Hirofumi MZ         if (strFile.IsEmpty())
659bf13ebdaSKatayama Hirofumi MZ             break;
660bf13ebdaSKatayama Hirofumi MZ 
661bf13ebdaSKatayama Hirofumi MZ         // Condense the lengthy pathname by using '...'
662bf13ebdaSKatayama Hirofumi MZ #define MAX_RECENT_PATHNAME_DISPLAY 30
663bf13ebdaSKatayama Hirofumi MZ         CPath pathFile(strFile);
664bf13ebdaSKatayama Hirofumi MZ         pathFile.CompactPathEx(MAX_RECENT_PATHNAME_DISPLAY);
665bf13ebdaSKatayama Hirofumi MZ         assert(wcslen((LPCWSTR)pathFile) <= MAX_RECENT_PATHNAME_DISPLAY);
666bf13ebdaSKatayama Hirofumi MZ 
667bf13ebdaSKatayama Hirofumi MZ         // Add an accelerator (by '&') to the item number for quick access
668bf13ebdaSKatayama Hirofumi MZ         WCHAR szText[4 + MAX_RECENT_PATHNAME_DISPLAY + 1];
669bf13ebdaSKatayama Hirofumi MZ         StringCchPrintfW(szText, _countof(szText), L"&%u %s", iItem + 1, (LPCWSTR)pathFile);
670bf13ebdaSKatayama Hirofumi MZ 
671bf13ebdaSKatayama Hirofumi MZ         INT iMenuItem = (cMenuItems - 2) + iItem;
672bf13ebdaSKatayama Hirofumi MZ         InsertMenu(hPopupMenu, iMenuItem, MF_BYPOSITION | MF_STRING, IDM_FILE1 + iItem, szText);
673bf13ebdaSKatayama Hirofumi MZ     }
674bf13ebdaSKatayama Hirofumi MZ }
675bf13ebdaSKatayama Hirofumi MZ 
CanUndo() const676bf13ebdaSKatayama Hirofumi MZ BOOL CMainWindow::CanUndo() const
677bf13ebdaSKatayama Hirofumi MZ {
678bf13ebdaSKatayama Hirofumi MZ     if (toolsModel.GetActiveTool() == TOOL_TEXT && ::IsWindowVisible(textEditWindow))
679bf13ebdaSKatayama Hirofumi MZ         return (BOOL)textEditWindow.SendMessage(EM_CANUNDO);
680bf13ebdaSKatayama Hirofumi MZ     if (selectionModel.m_bShow && toolsModel.IsSelection())
681bf13ebdaSKatayama Hirofumi MZ         return TRUE;
682bf13ebdaSKatayama Hirofumi MZ     return imageModel.CanUndo();
683bf13ebdaSKatayama Hirofumi MZ }
684bf13ebdaSKatayama Hirofumi MZ 
CanRedo() const685bf13ebdaSKatayama Hirofumi MZ BOOL CMainWindow::CanRedo() const
686bf13ebdaSKatayama Hirofumi MZ {
687bf13ebdaSKatayama Hirofumi MZ     if (toolsModel.GetActiveTool() == TOOL_TEXT && ::IsWindowVisible(textEditWindow))
688bf13ebdaSKatayama Hirofumi MZ         return FALSE; // There is no "WM_REDO" in EDIT control
689bf13ebdaSKatayama Hirofumi MZ     return imageModel.CanRedo();
690bf13ebdaSKatayama Hirofumi MZ }
691bf13ebdaSKatayama Hirofumi MZ 
CanPaste() const692bf13ebdaSKatayama Hirofumi MZ BOOL CMainWindow::CanPaste() const
693bf13ebdaSKatayama Hirofumi MZ {
694bf13ebdaSKatayama Hirofumi MZ     if (toolsModel.GetActiveTool() == TOOL_TEXT && ::IsWindowVisible(textEditWindow))
695bf13ebdaSKatayama Hirofumi MZ         return ::IsClipboardFormatAvailable(CF_UNICODETEXT);
696bf13ebdaSKatayama Hirofumi MZ 
697bf13ebdaSKatayama Hirofumi MZ     return (::IsClipboardFormatAvailable(CF_ENHMETAFILE) ||
698bf13ebdaSKatayama Hirofumi MZ             ::IsClipboardFormatAvailable(CF_DIB) ||
699bf13ebdaSKatayama Hirofumi MZ             ::IsClipboardFormatAvailable(CF_BITMAP));
700bf13ebdaSKatayama Hirofumi MZ }
701bf13ebdaSKatayama Hirofumi MZ 
OnInitMenuPopup(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)702bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnInitMenuPopup(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
703bf13ebdaSKatayama Hirofumi MZ {
704bf13ebdaSKatayama Hirofumi MZ     HMENU menu = (HMENU)wParam;
705bf13ebdaSKatayama Hirofumi MZ     BOOL trueSelection = (selectionModel.m_bShow && toolsModel.IsSelection());
706bf13ebdaSKatayama Hirofumi MZ     BOOL textShown = (toolsModel.GetActiveTool() == TOOL_TEXT && ::IsWindowVisible(textEditWindow));
707bf13ebdaSKatayama Hirofumi MZ     DWORD dwStart = 0, dwEnd = 0;
708bf13ebdaSKatayama Hirofumi MZ     if (textShown)
709bf13ebdaSKatayama Hirofumi MZ         textEditWindow.SendMessage(EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
710bf13ebdaSKatayama Hirofumi MZ     BOOL hasTextSel = (dwStart < dwEnd);
711bf13ebdaSKatayama Hirofumi MZ 
712bf13ebdaSKatayama Hirofumi MZ     //
713bf13ebdaSKatayama Hirofumi MZ     // File menu
714bf13ebdaSKatayama Hirofumi MZ     //
715bf13ebdaSKatayama Hirofumi MZ     if (::GetSubMenu(GetMenu(), 0) == menu)
716bf13ebdaSKatayama Hirofumi MZ     {
717bf13ebdaSKatayama Hirofumi MZ         ProcessFileMenu(menu);
718bf13ebdaSKatayama Hirofumi MZ     }
719bf13ebdaSKatayama Hirofumi MZ 
720bf13ebdaSKatayama Hirofumi MZ     //
721bf13ebdaSKatayama Hirofumi MZ     // Edit menu
722bf13ebdaSKatayama Hirofumi MZ     //
723bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITUNDO, ENABLED_IF(CanUndo()));
724bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITREDO, ENABLED_IF(CanRedo()));
725bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITCUT, ENABLED_IF(textShown ? hasTextSel : trueSelection));
726bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITCOPY, ENABLED_IF(textShown ? hasTextSel : trueSelection));
727bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITDELETESELECTION,
728bf13ebdaSKatayama Hirofumi MZ                    ENABLED_IF(textShown ? hasTextSel : trueSelection));
729bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITINVERTSELECTION, ENABLED_IF(trueSelection));
730bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITCOPYTO, ENABLED_IF(trueSelection));
731bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_EDITPASTE, ENABLED_IF(CanPaste()));
732f53d7eebSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_CROPSELECTION, ENABLED_IF(trueSelection));
733bf13ebdaSKatayama Hirofumi MZ 
734bf13ebdaSKatayama Hirofumi MZ     //
735bf13ebdaSKatayama Hirofumi MZ     // View menu
736bf13ebdaSKatayama Hirofumi MZ     //
737bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWTOOLBOX, CHECKED_IF(::IsWindowVisible(toolBoxContainer)));
738bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWCOLORPALETTE, CHECKED_IF(::IsWindowVisible(paletteWindow)));
739bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWSTATUSBAR,    CHECKED_IF(::IsWindowVisible(g_hStatusBar)));
740bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_FORMATICONBAR, CHECKED_IF(::IsWindowVisible(fontsDialog)));
741bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_FORMATICONBAR, ENABLED_IF(toolsModel.GetActiveTool() == TOOL_TEXT));
742bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM125, CHECKED_IF(toolsModel.GetZoom() == 125));
743bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM25,  CHECKED_IF(toolsModel.GetZoom() == 250));
744bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM50,  CHECKED_IF(toolsModel.GetZoom() == 500));
745bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM100, CHECKED_IF(toolsModel.GetZoom() == 1000));
746bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM200, CHECKED_IF(toolsModel.GetZoom() == 2000));
747bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM400, CHECKED_IF(toolsModel.GetZoom() == 4000));
748bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWZOOM800, CHECKED_IF(toolsModel.GetZoom() == 8000));
749bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWSHOWGRID,      CHECKED_IF(g_showGrid));
750bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_VIEWSHOWMINIATURE, CHECKED_IF(registrySettings.ShowThumbnail));
751bf13ebdaSKatayama Hirofumi MZ 
752bf13ebdaSKatayama Hirofumi MZ     //
753bf13ebdaSKatayama Hirofumi MZ     // Image menu
754bf13ebdaSKatayama Hirofumi MZ     //
755bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_IMAGECROP, ENABLED_IF(selectionModel.m_bShow));
756bf13ebdaSKatayama Hirofumi MZ     EnableMenuItem(menu, IDM_IMAGEDELETEIMAGE, ENABLED_IF(!selectionModel.m_bShow));
757bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_IMAGEDRAWOPAQUE, CHECKED_IF(!toolsModel.IsBackgroundTransparent()));
758bf13ebdaSKatayama Hirofumi MZ 
759bf13ebdaSKatayama Hirofumi MZ     //
760bf13ebdaSKatayama Hirofumi MZ     // Palette menu
761bf13ebdaSKatayama Hirofumi MZ     //
762bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_COLORSMODERNPALETTE, CHECKED_IF(paletteModel.SelectedPalette() == PAL_MODERN));
763bf13ebdaSKatayama Hirofumi MZ     CheckMenuItem(menu, IDM_COLORSOLDPALETTE,    CHECKED_IF(paletteModel.SelectedPalette() == PAL_OLDTYPE));
764bf13ebdaSKatayama Hirofumi MZ     return 0;
765bf13ebdaSKatayama Hirofumi MZ }
766bf13ebdaSKatayama Hirofumi MZ 
OnSize(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)767bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
768bf13ebdaSKatayama Hirofumi MZ {
769bf13ebdaSKatayama Hirofumi MZ     int test[] = { LOWORD(lParam) - 260, LOWORD(lParam) - 140, LOWORD(lParam) - 20 };
770bf13ebdaSKatayama Hirofumi MZ     if (::IsWindow(g_hStatusBar))
771bf13ebdaSKatayama Hirofumi MZ     {
772bf13ebdaSKatayama Hirofumi MZ         ::SendMessageW(g_hStatusBar, WM_SIZE, 0, 0);
773bf13ebdaSKatayama Hirofumi MZ         ::SendMessageW(g_hStatusBar, SB_SETPARTS, 3, (LPARAM)&test);
774bf13ebdaSKatayama Hirofumi MZ     }
775bf13ebdaSKatayama Hirofumi MZ     alignChildrenToMainWindow();
776bf13ebdaSKatayama Hirofumi MZ     return 0;
777bf13ebdaSKatayama Hirofumi MZ }
778bf13ebdaSKatayama Hirofumi MZ 
OnGetMinMaxInfo(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)779bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
780bf13ebdaSKatayama Hirofumi MZ {
781bf13ebdaSKatayama Hirofumi MZ     MINMAXINFO *mm = (MINMAXINFO*)lParam;
782bf13ebdaSKatayama Hirofumi MZ     mm->ptMinTrackSize = { 330, 360 };
783bf13ebdaSKatayama Hirofumi MZ     return 0;
784bf13ebdaSKatayama Hirofumi MZ }
785bf13ebdaSKatayama Hirofumi MZ 
OnKeyDown(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)786bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
787bf13ebdaSKatayama Hirofumi MZ {
788bf13ebdaSKatayama Hirofumi MZ     switch (wParam)
789bf13ebdaSKatayama Hirofumi MZ     {
790bf13ebdaSKatayama Hirofumi MZ         case VK_ESCAPE:
791b8598e09SKatayama Hirofumi MZ             canvasWindow.PostMessage(nMsg, wParam, lParam);
792bf13ebdaSKatayama Hirofumi MZ             break;
793bf13ebdaSKatayama Hirofumi MZ         case VK_LEFT:
794bf13ebdaSKatayama Hirofumi MZ             selectionModel.moveSelection(-1, 0);
795bf13ebdaSKatayama Hirofumi MZ             break;
796bf13ebdaSKatayama Hirofumi MZ         case VK_RIGHT:
797bf13ebdaSKatayama Hirofumi MZ             selectionModel.moveSelection(+1, 0);
798bf13ebdaSKatayama Hirofumi MZ             break;
799bf13ebdaSKatayama Hirofumi MZ         case VK_UP:
800bf13ebdaSKatayama Hirofumi MZ             selectionModel.moveSelection(0, -1);
801bf13ebdaSKatayama Hirofumi MZ             break;
802bf13ebdaSKatayama Hirofumi MZ         case VK_DOWN:
803bf13ebdaSKatayama Hirofumi MZ             selectionModel.moveSelection(0, +1);
804bf13ebdaSKatayama Hirofumi MZ             break;
805bf13ebdaSKatayama Hirofumi MZ         default:
806bf13ebdaSKatayama Hirofumi MZ             break;
807bf13ebdaSKatayama Hirofumi MZ     }
808bf13ebdaSKatayama Hirofumi MZ     return 0;
809bf13ebdaSKatayama Hirofumi MZ }
810bf13ebdaSKatayama Hirofumi MZ 
OnSysColorChange(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)811bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnSysColorChange(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
812bf13ebdaSKatayama Hirofumi MZ {
813bf13ebdaSKatayama Hirofumi MZ     /* Redirect message to common controls */
814bf13ebdaSKatayama Hirofumi MZ     HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
815bf13ebdaSKatayama Hirofumi MZ     ::SendMessageW(hToolbar, WM_SYSCOLORCHANGE, 0, 0);
816bf13ebdaSKatayama Hirofumi MZ     return 0;
817bf13ebdaSKatayama Hirofumi MZ }
818bf13ebdaSKatayama Hirofumi MZ 
OnCommand(UINT nMsg,WPARAM wParam,LPARAM lParam,BOOL & bHandled)819bf13ebdaSKatayama Hirofumi MZ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
820bf13ebdaSKatayama Hirofumi MZ {
821bf13ebdaSKatayama Hirofumi MZ     // Disable commands while dragging mouse
822bf13ebdaSKatayama Hirofumi MZ     if (canvasWindow.m_drawing && ::GetCapture())
823bf13ebdaSKatayama Hirofumi MZ     {
824bf13ebdaSKatayama Hirofumi MZ         ATLTRACE("locking!\n");
825bf13ebdaSKatayama Hirofumi MZ         return 0;
826bf13ebdaSKatayama Hirofumi MZ     }
827bf13ebdaSKatayama Hirofumi MZ 
828bf13ebdaSKatayama Hirofumi MZ     BOOL textShown = (toolsModel.GetActiveTool() == TOOL_TEXT && ::IsWindowVisible(textEditWindow));
829bf13ebdaSKatayama Hirofumi MZ     switch (LOWORD(wParam))
830bf13ebdaSKatayama Hirofumi MZ     {
831bf13ebdaSKatayama Hirofumi MZ         case IDM_HELPINFO:
832bf13ebdaSKatayama Hirofumi MZ         {
833bf13ebdaSKatayama Hirofumi MZ             WCHAR infotitle[100], infotext[200];
834bf13ebdaSKatayama Hirofumi MZ             ::LoadStringW(g_hinstExe, IDS_INFOTITLE, infotitle, _countof(infotitle));
835bf13ebdaSKatayama Hirofumi MZ             ::LoadStringW(g_hinstExe, IDS_INFOTEXT, infotext, _countof(infotext));
836bf13ebdaSKatayama Hirofumi MZ             ::ShellAboutW(m_hWnd, infotitle, infotext,
837bf13ebdaSKatayama Hirofumi MZ                           LoadIconW(g_hinstExe, MAKEINTRESOURCEW(IDI_APPICON)));
838bf13ebdaSKatayama Hirofumi MZ             break;
839bf13ebdaSKatayama Hirofumi MZ         }
840bf13ebdaSKatayama Hirofumi MZ         case IDM_HELPHELPTOPICS:
841bf13ebdaSKatayama Hirofumi MZ             DoHtmlHelpW(m_hWnd, L"%SystemRoot%\\Help\\mspaint.chm", HH_DISPLAY_TOPIC, 0);
842bf13ebdaSKatayama Hirofumi MZ             break;
843bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEEXIT:
844bf13ebdaSKatayama Hirofumi MZ             SendMessage(WM_CLOSE, wParam, lParam);
845bf13ebdaSKatayama Hirofumi MZ             break;
846bf13ebdaSKatayama Hirofumi MZ         case IDM_FILENEW:
847bf13ebdaSKatayama Hirofumi MZ             if (ConfirmSave())
848bf13ebdaSKatayama Hirofumi MZ             {
849bf13ebdaSKatayama Hirofumi MZ                 InitializeImage(NULL, NULL, FALSE);
850bf13ebdaSKatayama Hirofumi MZ             }
851bf13ebdaSKatayama Hirofumi MZ             break;
852bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEOPEN:
853bf13ebdaSKatayama Hirofumi MZ             {
854bf13ebdaSKatayama Hirofumi MZ                 WCHAR szFileName[MAX_LONG_PATH] = L"";
855bf13ebdaSKatayama Hirofumi MZ                 if (ConfirmSave() && GetOpenFileName(szFileName, _countof(szFileName)))
856bf13ebdaSKatayama Hirofumi MZ                 {
857bf13ebdaSKatayama Hirofumi MZ                     DoLoadImageFile(m_hWnd, szFileName, TRUE);
858bf13ebdaSKatayama Hirofumi MZ                 }
859bf13ebdaSKatayama Hirofumi MZ                 break;
860bf13ebdaSKatayama Hirofumi MZ             }
861bf13ebdaSKatayama Hirofumi MZ         case IDM_FILESAVE:
862bf13ebdaSKatayama Hirofumi MZ             saveImage(TRUE);
863bf13ebdaSKatayama Hirofumi MZ             break;
864bf13ebdaSKatayama Hirofumi MZ         case IDM_FILESAVEAS:
865bf13ebdaSKatayama Hirofumi MZ             saveImage(FALSE);
866bf13ebdaSKatayama Hirofumi MZ             break;
867bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEPAGESETUP:
868bf13ebdaSKatayama Hirofumi MZ             // DUMMY: Shows the dialog only, no functionality
869bf13ebdaSKatayama Hirofumi MZ             PAGESETUPDLG psd;
870bf13ebdaSKatayama Hirofumi MZ             ZeroMemory(&psd, sizeof(psd));
871bf13ebdaSKatayama Hirofumi MZ             psd.lStructSize = sizeof(psd);
872bf13ebdaSKatayama Hirofumi MZ             psd.hwndOwner = m_hWnd;
873bf13ebdaSKatayama Hirofumi MZ             PageSetupDlg(&psd);
874bf13ebdaSKatayama Hirofumi MZ             break;
875bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEPRINT:
876bf13ebdaSKatayama Hirofumi MZ             // TODO: Test whether it actually works
877bf13ebdaSKatayama Hirofumi MZ             PRINTDLG pd;
878bf13ebdaSKatayama Hirofumi MZ             ZeroMemory(&pd, sizeof(pd));
879bf13ebdaSKatayama Hirofumi MZ             pd.lStructSize = sizeof(pd);
880bf13ebdaSKatayama Hirofumi MZ             pd.hwndOwner = m_hWnd;
881bf13ebdaSKatayama Hirofumi MZ             pd.hDevMode = NULL;  // freed by user
882bf13ebdaSKatayama Hirofumi MZ             pd.hDevNames = NULL;  // freed by user
883bf13ebdaSKatayama Hirofumi MZ             pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
884bf13ebdaSKatayama Hirofumi MZ             pd.nCopies = 1;
885bf13ebdaSKatayama Hirofumi MZ             pd.nFromPage = 0xffff;
886bf13ebdaSKatayama Hirofumi MZ             pd.nToPage = 0xffff;
887bf13ebdaSKatayama Hirofumi MZ             pd.nMinPage = 1;
888bf13ebdaSKatayama Hirofumi MZ             pd.nMaxPage = 0xffff;
889bf13ebdaSKatayama Hirofumi MZ             if (PrintDlg(&pd) == TRUE)
890bf13ebdaSKatayama Hirofumi MZ             {
891bf13ebdaSKatayama Hirofumi MZ                 ::BitBlt(pd.hDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), imageModel.GetDC(), 0, 0, SRCCOPY);
892bf13ebdaSKatayama Hirofumi MZ                 DeleteDC(pd.hDC);
893bf13ebdaSKatayama Hirofumi MZ             }
894bf13ebdaSKatayama Hirofumi MZ             if (pd.hDevMode)
895bf13ebdaSKatayama Hirofumi MZ                 GlobalFree(pd.hDevMode);
896bf13ebdaSKatayama Hirofumi MZ             if (pd.hDevNames)
897bf13ebdaSKatayama Hirofumi MZ                 GlobalFree(pd.hDevNames);
898bf13ebdaSKatayama Hirofumi MZ             break;
899bf13ebdaSKatayama Hirofumi MZ         case IDM_FILESEND:
900b8598e09SKatayama Hirofumi MZ             canvasWindow.OnEndDraw(FALSE);
901bf13ebdaSKatayama Hirofumi MZ             if (!OpenMailer(m_hWnd, g_szFileName))
902bf13ebdaSKatayama Hirofumi MZ             {
903bf13ebdaSKatayama Hirofumi MZ                 ShowError(IDS_CANTSENDMAIL);
904bf13ebdaSKatayama Hirofumi MZ             }
905bf13ebdaSKatayama Hirofumi MZ             break;
906bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEASWALLPAPERPLANE:
907bf13ebdaSKatayama Hirofumi MZ             RegistrySettings::SetWallpaper(g_szFileName, RegistrySettings::TILED);
908bf13ebdaSKatayama Hirofumi MZ             break;
909bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEASWALLPAPERCENTERED:
910bf13ebdaSKatayama Hirofumi MZ             RegistrySettings::SetWallpaper(g_szFileName, RegistrySettings::CENTERED);
911bf13ebdaSKatayama Hirofumi MZ             break;
912bf13ebdaSKatayama Hirofumi MZ         case IDM_FILEASWALLPAPERSTRETCHED:
913bf13ebdaSKatayama Hirofumi MZ             RegistrySettings::SetWallpaper(g_szFileName, RegistrySettings::STRETCHED);
914bf13ebdaSKatayama Hirofumi MZ             break;
915bf13ebdaSKatayama Hirofumi MZ         case IDM_FILE1:
916bf13ebdaSKatayama Hirofumi MZ         case IDM_FILE2:
917bf13ebdaSKatayama Hirofumi MZ         case IDM_FILE3:
918bf13ebdaSKatayama Hirofumi MZ         case IDM_FILE4:
919bf13ebdaSKatayama Hirofumi MZ         {
920bf13ebdaSKatayama Hirofumi MZ             INT iFile = LOWORD(wParam) - IDM_FILE1;
921bf13ebdaSKatayama Hirofumi MZ             if (ConfirmSave())
922bf13ebdaSKatayama Hirofumi MZ                 DoLoadImageFile(m_hWnd, registrySettings.strFiles[iFile], TRUE);
923bf13ebdaSKatayama Hirofumi MZ             break;
924bf13ebdaSKatayama Hirofumi MZ         }
925bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITUNDO:
926bf13ebdaSKatayama Hirofumi MZ             if (textShown)
927bf13ebdaSKatayama Hirofumi MZ             {
928bf13ebdaSKatayama Hirofumi MZ                 textEditWindow.PostMessage(WM_UNDO, 0, 0);
929bf13ebdaSKatayama Hirofumi MZ                 break;
930bf13ebdaSKatayama Hirofumi MZ             }
931b8598e09SKatayama Hirofumi MZ             canvasWindow.OnEndDraw(FALSE);
932bf13ebdaSKatayama Hirofumi MZ             imageModel.Undo();
933bf13ebdaSKatayama Hirofumi MZ             break;
934bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITREDO:
935bf13ebdaSKatayama Hirofumi MZ             if (textShown)
936bf13ebdaSKatayama Hirofumi MZ             {
937bf13ebdaSKatayama Hirofumi MZ                 // There is no "WM_REDO" in EDIT control
938bf13ebdaSKatayama Hirofumi MZ                 break;
939bf13ebdaSKatayama Hirofumi MZ             }
940b8598e09SKatayama Hirofumi MZ             canvasWindow.OnEndDraw(FALSE);
941bf13ebdaSKatayama Hirofumi MZ             imageModel.Redo();
942bf13ebdaSKatayama Hirofumi MZ             break;
943bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITCOPY:
944bf13ebdaSKatayama Hirofumi MZ             if (textShown)
945bf13ebdaSKatayama Hirofumi MZ             {
946bf13ebdaSKatayama Hirofumi MZ                 textEditWindow.SendMessage(WM_COPY);
947bf13ebdaSKatayama Hirofumi MZ                 break;
948bf13ebdaSKatayama Hirofumi MZ             }
949bf13ebdaSKatayama Hirofumi MZ             if (!selectionModel.m_bShow || !OpenClipboard())
950bf13ebdaSKatayama Hirofumi MZ                 break;
951bf13ebdaSKatayama Hirofumi MZ 
952bf13ebdaSKatayama Hirofumi MZ             EmptyClipboard();
953bf13ebdaSKatayama Hirofumi MZ 
954bf13ebdaSKatayama Hirofumi MZ             selectionModel.TakeOff();
955bf13ebdaSKatayama Hirofumi MZ 
956bf13ebdaSKatayama Hirofumi MZ             {
957bf13ebdaSKatayama Hirofumi MZ                 HBITMAP hbmCopy = selectionModel.GetSelectionContents();
958bf13ebdaSKatayama Hirofumi MZ                 HGLOBAL hGlobal = BitmapToClipboardDIB(hbmCopy);
959bf13ebdaSKatayama Hirofumi MZ                 if (hGlobal)
960bf13ebdaSKatayama Hirofumi MZ                     ::SetClipboardData(CF_DIB, hGlobal);
961bf13ebdaSKatayama Hirofumi MZ                 else
962bf13ebdaSKatayama Hirofumi MZ                     ShowOutOfMemory();
963bf13ebdaSKatayama Hirofumi MZ                 ::DeleteObject(hbmCopy);
964bf13ebdaSKatayama Hirofumi MZ             }
965bf13ebdaSKatayama Hirofumi MZ 
966bf13ebdaSKatayama Hirofumi MZ             CloseClipboard();
967bf13ebdaSKatayama Hirofumi MZ             break;
968bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITCUT:
969bf13ebdaSKatayama Hirofumi MZ             if (textShown)
970bf13ebdaSKatayama Hirofumi MZ             {
971bf13ebdaSKatayama Hirofumi MZ                 textEditWindow.SendMessage(WM_CUT);
972bf13ebdaSKatayama Hirofumi MZ                 break;
973bf13ebdaSKatayama Hirofumi MZ             }
974bf13ebdaSKatayama Hirofumi MZ             /* Copy */
975bf13ebdaSKatayama Hirofumi MZ             SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
976bf13ebdaSKatayama Hirofumi MZ             /* Delete selection */
977bf13ebdaSKatayama Hirofumi MZ             SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
978bf13ebdaSKatayama Hirofumi MZ             break;
979bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITPASTE:
980bf13ebdaSKatayama Hirofumi MZ             if (textShown)
981bf13ebdaSKatayama Hirofumi MZ             {
982bf13ebdaSKatayama Hirofumi MZ                 textEditWindow.SendMessage(WM_PASTE);
983bf13ebdaSKatayama Hirofumi MZ                 break;
984bf13ebdaSKatayama Hirofumi MZ             }
985bf13ebdaSKatayama Hirofumi MZ 
986bf13ebdaSKatayama Hirofumi MZ             if (!OpenClipboard())
987bf13ebdaSKatayama Hirofumi MZ                 break;
988bf13ebdaSKatayama Hirofumi MZ 
989bf13ebdaSKatayama Hirofumi MZ             // In many cases, CF_ENHMETAFILE provides a better image than CF_DIB
990bf13ebdaSKatayama Hirofumi MZ             if (::IsClipboardFormatAvailable(CF_ENHMETAFILE))
991bf13ebdaSKatayama Hirofumi MZ             {
992bf13ebdaSKatayama Hirofumi MZ                 HENHMETAFILE hEMF = (HENHMETAFILE)::GetClipboardData(CF_ENHMETAFILE);
993bf13ebdaSKatayama Hirofumi MZ                 if (hEMF)
994bf13ebdaSKatayama Hirofumi MZ                 {
995bf13ebdaSKatayama Hirofumi MZ                     HBITMAP hbm = BitmapFromHEMF(hEMF);
996bf13ebdaSKatayama Hirofumi MZ                     ::DeleteEnhMetaFile(hEMF);
997bf13ebdaSKatayama Hirofumi MZ                     if (hbm)
998bf13ebdaSKatayama Hirofumi MZ                     {
999bf13ebdaSKatayama Hirofumi MZ                         InsertSelectionFromHBITMAP(hbm, m_hWnd);
1000bf13ebdaSKatayama Hirofumi MZ                         CloseClipboard();
1001bf13ebdaSKatayama Hirofumi MZ                         break;
1002bf13ebdaSKatayama Hirofumi MZ                     }
1003bf13ebdaSKatayama Hirofumi MZ                 }
1004bf13ebdaSKatayama Hirofumi MZ             }
1005bf13ebdaSKatayama Hirofumi MZ 
1006bf13ebdaSKatayama Hirofumi MZ             // In many cases, CF_DIB provides a better image than CF_BITMAP
1007bf13ebdaSKatayama Hirofumi MZ             if (::IsClipboardFormatAvailable(CF_DIB))
1008bf13ebdaSKatayama Hirofumi MZ             {
1009bf13ebdaSKatayama Hirofumi MZ                 HBITMAP hbm = BitmapFromClipboardDIB(::GetClipboardData(CF_DIB));
1010bf13ebdaSKatayama Hirofumi MZ                 if (hbm)
1011bf13ebdaSKatayama Hirofumi MZ                 {
1012bf13ebdaSKatayama Hirofumi MZ                     InsertSelectionFromHBITMAP(hbm, m_hWnd);
1013bf13ebdaSKatayama Hirofumi MZ                     CloseClipboard();
1014bf13ebdaSKatayama Hirofumi MZ                     break;
1015bf13ebdaSKatayama Hirofumi MZ                 }
1016bf13ebdaSKatayama Hirofumi MZ             }
1017bf13ebdaSKatayama Hirofumi MZ 
1018bf13ebdaSKatayama Hirofumi MZ             // The last resort
1019bf13ebdaSKatayama Hirofumi MZ             if (::IsClipboardFormatAvailable(CF_BITMAP))
1020bf13ebdaSKatayama Hirofumi MZ             {
1021bf13ebdaSKatayama Hirofumi MZ                 HBITMAP hbm = (HBITMAP)::GetClipboardData(CF_BITMAP);
1022bf13ebdaSKatayama Hirofumi MZ                 if (hbm)
1023bf13ebdaSKatayama Hirofumi MZ                 {
1024bf13ebdaSKatayama Hirofumi MZ                     InsertSelectionFromHBITMAP(hbm, m_hWnd);
1025bf13ebdaSKatayama Hirofumi MZ                     CloseClipboard();
1026bf13ebdaSKatayama Hirofumi MZ                     break;
1027bf13ebdaSKatayama Hirofumi MZ                 }
1028bf13ebdaSKatayama Hirofumi MZ             }
1029bf13ebdaSKatayama Hirofumi MZ 
1030bf13ebdaSKatayama Hirofumi MZ             // Failed to paste
1031bf13ebdaSKatayama Hirofumi MZ             {
1032bf13ebdaSKatayama Hirofumi MZ                 CStringW strText, strTitle;
1033bf13ebdaSKatayama Hirofumi MZ                 strText.LoadString(IDS_CANTPASTE);
1034bf13ebdaSKatayama Hirofumi MZ                 strTitle.LoadString(IDS_PROGRAMNAME);
1035bf13ebdaSKatayama Hirofumi MZ                 MessageBox(strText, strTitle, MB_ICONINFORMATION);
1036bf13ebdaSKatayama Hirofumi MZ             }
1037bf13ebdaSKatayama Hirofumi MZ 
1038bf13ebdaSKatayama Hirofumi MZ             CloseClipboard();
1039bf13ebdaSKatayama Hirofumi MZ             break;
1040f53d7eebSKatayama Hirofumi MZ         case IDM_CROPSELECTION:
1041f53d7eebSKatayama Hirofumi MZ         {
1042f53d7eebSKatayama Hirofumi MZ             HBITMAP hbmSelection = selectionModel.GetSelectionContents();
1043f53d7eebSKatayama Hirofumi MZ             if (hbmSelection)
1044f53d7eebSKatayama Hirofumi MZ             {
1045f53d7eebSKatayama Hirofumi MZ                 imageModel.PushImageForUndo(hbmSelection);
1046*e928b427SKatayama Hirofumi MZ                 selectionModel.HideSelection();
1047f53d7eebSKatayama Hirofumi MZ                 imageModel.NotifyImageChanged();
1048f53d7eebSKatayama Hirofumi MZ             }
1049f53d7eebSKatayama Hirofumi MZ             break;
1050f53d7eebSKatayama Hirofumi MZ         }
1051bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITDELETESELECTION:
1052bf13ebdaSKatayama Hirofumi MZ         {
1053bf13ebdaSKatayama Hirofumi MZ             if (textShown)
1054bf13ebdaSKatayama Hirofumi MZ             {
1055bf13ebdaSKatayama Hirofumi MZ                 textEditWindow.SendMessage(WM_CLEAR);
1056bf13ebdaSKatayama Hirofumi MZ                 break;
1057bf13ebdaSKatayama Hirofumi MZ             }
1058bf13ebdaSKatayama Hirofumi MZ             switch (toolsModel.GetActiveTool())
1059bf13ebdaSKatayama Hirofumi MZ             {
1060bf13ebdaSKatayama Hirofumi MZ                 case TOOL_FREESEL:
1061bf13ebdaSKatayama Hirofumi MZ                 case TOOL_RECTSEL:
1062bf13ebdaSKatayama Hirofumi MZ                     selectionModel.DeleteSelection();
1063bf13ebdaSKatayama Hirofumi MZ                     break;
1064bf13ebdaSKatayama Hirofumi MZ 
1065bf13ebdaSKatayama Hirofumi MZ                 case TOOL_TEXT:
1066b8598e09SKatayama Hirofumi MZ                     canvasWindow.OnEndDraw(TRUE);
1067bf13ebdaSKatayama Hirofumi MZ                     break;
1068bf13ebdaSKatayama Hirofumi MZ                 default:
1069bf13ebdaSKatayama Hirofumi MZ                     break;
1070bf13ebdaSKatayama Hirofumi MZ             }
1071bf13ebdaSKatayama Hirofumi MZ             break;
1072bf13ebdaSKatayama Hirofumi MZ         }
1073bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITSELECTALL:
1074bf13ebdaSKatayama Hirofumi MZ         {
1075bf13ebdaSKatayama Hirofumi MZ             if (textShown)
1076bf13ebdaSKatayama Hirofumi MZ             {
1077bf13ebdaSKatayama Hirofumi MZ                 textEditWindow.SendMessage(EM_SETSEL, 0, -1);
1078bf13ebdaSKatayama Hirofumi MZ                 break;
1079bf13ebdaSKatayama Hirofumi MZ             }
1080bf13ebdaSKatayama Hirofumi MZ             HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
1081bf13ebdaSKatayama Hirofumi MZ             ::SendMessageW(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
1082bf13ebdaSKatayama Hirofumi MZ             toolsModel.selectAll();
1083bf13ebdaSKatayama Hirofumi MZ             canvasWindow.Invalidate(TRUE);
1084bf13ebdaSKatayama Hirofumi MZ             break;
1085bf13ebdaSKatayama Hirofumi MZ         }
1086bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITCOPYTO:
1087bf13ebdaSKatayama Hirofumi MZ         {
1088bf13ebdaSKatayama Hirofumi MZ             WCHAR szFileName[MAX_LONG_PATH];
1089bf13ebdaSKatayama Hirofumi MZ             ::LoadStringW(g_hinstExe, IDS_DEFAULTFILENAME, szFileName, _countof(szFileName));
1090bf13ebdaSKatayama Hirofumi MZ             if (GetSaveFileName(szFileName, _countof(szFileName)))
1091bf13ebdaSKatayama Hirofumi MZ             {
1092bf13ebdaSKatayama Hirofumi MZ                 HBITMAP hbmSelection = selectionModel.GetSelectionContents();
1093bf13ebdaSKatayama Hirofumi MZ                 if (!hbmSelection)
1094bf13ebdaSKatayama Hirofumi MZ                 {
1095bf13ebdaSKatayama Hirofumi MZ                     ShowOutOfMemory();
1096bf13ebdaSKatayama Hirofumi MZ                     break;
1097bf13ebdaSKatayama Hirofumi MZ                 }
1098bf13ebdaSKatayama Hirofumi MZ                 SaveDIBToFile(hbmSelection, szFileName, FALSE);
1099bf13ebdaSKatayama Hirofumi MZ                 DeleteObject(hbmSelection);
1100bf13ebdaSKatayama Hirofumi MZ             }
1101bf13ebdaSKatayama Hirofumi MZ             break;
1102bf13ebdaSKatayama Hirofumi MZ         }
1103bf13ebdaSKatayama Hirofumi MZ         case IDM_EDITPASTEFROM:
1104bf13ebdaSKatayama Hirofumi MZ         {
1105bf13ebdaSKatayama Hirofumi MZ             WCHAR szFileName[MAX_LONG_PATH] = L"";
1106bf13ebdaSKatayama Hirofumi MZ             if (GetOpenFileName(szFileName, _countof(szFileName)))
1107bf13ebdaSKatayama Hirofumi MZ             {
1108bf13ebdaSKatayama Hirofumi MZ                 HBITMAP hbmNew = DoLoadImageFile(m_hWnd, szFileName, FALSE);
1109bf13ebdaSKatayama Hirofumi MZ                 if (hbmNew)
1110bf13ebdaSKatayama Hirofumi MZ                     InsertSelectionFromHBITMAP(hbmNew, m_hWnd);
1111bf13ebdaSKatayama Hirofumi MZ             }
1112bf13ebdaSKatayama Hirofumi MZ             break;
1113bf13ebdaSKatayama Hirofumi MZ         }
1114bf13ebdaSKatayama Hirofumi MZ         case IDM_COLORSEDITPALETTE:
1115bf13ebdaSKatayama Hirofumi MZ         {
1116bf13ebdaSKatayama Hirofumi MZ             COLORREF rgbColor = paletteModel.GetFgColor();
1117bf13ebdaSKatayama Hirofumi MZ             if (ChooseColor(&rgbColor))
1118bf13ebdaSKatayama Hirofumi MZ                 paletteModel.SetFgColor(rgbColor);
1119bf13ebdaSKatayama Hirofumi MZ             break;
1120bf13ebdaSKatayama Hirofumi MZ         }
1121bf13ebdaSKatayama Hirofumi MZ         case IDM_COLORSMODERNPALETTE:
1122bf13ebdaSKatayama Hirofumi MZ             paletteModel.SelectPalette(PAL_MODERN);
1123bf13ebdaSKatayama Hirofumi MZ             break;
1124bf13ebdaSKatayama Hirofumi MZ         case IDM_COLORSOLDPALETTE:
1125bf13ebdaSKatayama Hirofumi MZ             paletteModel.SelectPalette(PAL_OLDTYPE);
1126bf13ebdaSKatayama Hirofumi MZ             break;
1127bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGEINVERTCOLORS:
1128bf13ebdaSKatayama Hirofumi MZ         {
1129bf13ebdaSKatayama Hirofumi MZ             if (selectionModel.m_bShow)
1130bf13ebdaSKatayama Hirofumi MZ                 selectionModel.InvertSelection();
1131bf13ebdaSKatayama Hirofumi MZ             else
1132bf13ebdaSKatayama Hirofumi MZ                 imageModel.InvertColors();
1133bf13ebdaSKatayama Hirofumi MZ             break;
1134bf13ebdaSKatayama Hirofumi MZ         }
1135bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGEDELETEIMAGE:
1136bf13ebdaSKatayama Hirofumi MZ             imageModel.PushImageForUndo();
1137bf13ebdaSKatayama Hirofumi MZ             Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
1138bf13ebdaSKatayama Hirofumi MZ             imageModel.NotifyImageChanged();
1139bf13ebdaSKatayama Hirofumi MZ             break;
1140bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGEROTATEMIRROR:
1141bf13ebdaSKatayama Hirofumi MZ             {
1142bf13ebdaSKatayama Hirofumi MZ                 CWaitCursor waitCursor;
1143bf13ebdaSKatayama Hirofumi MZ                 canvasWindow.updateScrollPos();
1144bf13ebdaSKatayama Hirofumi MZ                 switch (mirrorRotateDialog.DoModal(mainWindow.m_hWnd))
1145bf13ebdaSKatayama Hirofumi MZ                 {
1146bf13ebdaSKatayama Hirofumi MZ                     case 1: /* flip horizontally */
1147bf13ebdaSKatayama Hirofumi MZ                     {
1148bf13ebdaSKatayama Hirofumi MZ                         if (selectionModel.m_bShow)
1149bf13ebdaSKatayama Hirofumi MZ                             selectionModel.FlipHorizontally();
1150bf13ebdaSKatayama Hirofumi MZ                         else
1151bf13ebdaSKatayama Hirofumi MZ                             imageModel.FlipHorizontally();
1152bf13ebdaSKatayama Hirofumi MZ                         break;
1153bf13ebdaSKatayama Hirofumi MZ                     }
1154bf13ebdaSKatayama Hirofumi MZ                     case 2: /* flip vertically */
1155bf13ebdaSKatayama Hirofumi MZ                     {
1156bf13ebdaSKatayama Hirofumi MZ                         if (selectionModel.m_bShow)
1157bf13ebdaSKatayama Hirofumi MZ                             selectionModel.FlipVertically();
1158bf13ebdaSKatayama Hirofumi MZ                         else
1159bf13ebdaSKatayama Hirofumi MZ                             imageModel.FlipVertically();
1160bf13ebdaSKatayama Hirofumi MZ                         break;
1161bf13ebdaSKatayama Hirofumi MZ                     }
1162bf13ebdaSKatayama Hirofumi MZ                     case 3: /* rotate 90 degrees */
1163bf13ebdaSKatayama Hirofumi MZ                     {
1164bf13ebdaSKatayama Hirofumi MZ                         if (selectionModel.m_bShow)
1165bf13ebdaSKatayama Hirofumi MZ                             selectionModel.RotateNTimes90Degrees(1);
1166bf13ebdaSKatayama Hirofumi MZ                         else
1167bf13ebdaSKatayama Hirofumi MZ                             imageModel.RotateNTimes90Degrees(1);
1168bf13ebdaSKatayama Hirofumi MZ                         break;
1169bf13ebdaSKatayama Hirofumi MZ                     }
1170bf13ebdaSKatayama Hirofumi MZ                     case 4: /* rotate 180 degrees */
1171bf13ebdaSKatayama Hirofumi MZ                     {
1172bf13ebdaSKatayama Hirofumi MZ                         if (selectionModel.m_bShow)
1173bf13ebdaSKatayama Hirofumi MZ                             selectionModel.RotateNTimes90Degrees(2);
1174bf13ebdaSKatayama Hirofumi MZ                         else
1175bf13ebdaSKatayama Hirofumi MZ                             imageModel.RotateNTimes90Degrees(2);
1176bf13ebdaSKatayama Hirofumi MZ                         break;
1177bf13ebdaSKatayama Hirofumi MZ                     }
1178bf13ebdaSKatayama Hirofumi MZ                     case 5: /* rotate 270 degrees */
1179bf13ebdaSKatayama Hirofumi MZ                     {
1180bf13ebdaSKatayama Hirofumi MZ                         if (selectionModel.m_bShow)
1181bf13ebdaSKatayama Hirofumi MZ                             selectionModel.RotateNTimes90Degrees(3);
1182bf13ebdaSKatayama Hirofumi MZ                         else
1183bf13ebdaSKatayama Hirofumi MZ                             imageModel.RotateNTimes90Degrees(3);
1184bf13ebdaSKatayama Hirofumi MZ                         break;
1185bf13ebdaSKatayama Hirofumi MZ                     }
1186bf13ebdaSKatayama Hirofumi MZ                 }
1187bf13ebdaSKatayama Hirofumi MZ             }
1188bf13ebdaSKatayama Hirofumi MZ             break;
1189bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGEATTRIBUTES:
1190bf13ebdaSKatayama Hirofumi MZ         {
1191bf13ebdaSKatayama Hirofumi MZ             if (attributesDialog.DoModal(mainWindow.m_hWnd))
1192bf13ebdaSKatayama Hirofumi MZ             {
1193bf13ebdaSKatayama Hirofumi MZ                 CWaitCursor waitCursor;
1194bf13ebdaSKatayama Hirofumi MZ                 if (attributesDialog.m_bBlackAndWhite && !imageModel.IsBlackAndWhite())
1195bf13ebdaSKatayama Hirofumi MZ                 {
1196bf13ebdaSKatayama Hirofumi MZ                     CStringW strText(MAKEINTRESOURCEW(IDS_LOSECOLOR));
1197bf13ebdaSKatayama Hirofumi MZ                     CStringW strTitle(MAKEINTRESOURCEW(IDS_PROGRAMNAME));
1198bf13ebdaSKatayama Hirofumi MZ                     INT id = MessageBox(strText, strTitle, MB_ICONINFORMATION | MB_YESNOCANCEL);
1199bf13ebdaSKatayama Hirofumi MZ                     if (id != IDYES)
1200bf13ebdaSKatayama Hirofumi MZ                         break;
1201bf13ebdaSKatayama Hirofumi MZ 
1202bf13ebdaSKatayama Hirofumi MZ                     imageModel.PushBlackAndWhite();
1203bf13ebdaSKatayama Hirofumi MZ                 }
1204bf13ebdaSKatayama Hirofumi MZ 
1205bf13ebdaSKatayama Hirofumi MZ                 if (imageModel.GetWidth() != attributesDialog.newWidth ||
1206bf13ebdaSKatayama Hirofumi MZ                     imageModel.GetHeight() != attributesDialog.newHeight)
1207bf13ebdaSKatayama Hirofumi MZ                 {
1208bf13ebdaSKatayama Hirofumi MZ                     imageModel.Crop(attributesDialog.newWidth, attributesDialog.newHeight);
1209bf13ebdaSKatayama Hirofumi MZ                 }
1210bf13ebdaSKatayama Hirofumi MZ             }
1211bf13ebdaSKatayama Hirofumi MZ             break;
1212bf13ebdaSKatayama Hirofumi MZ         }
1213bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGESTRETCHSKEW:
1214bf13ebdaSKatayama Hirofumi MZ         {
1215bf13ebdaSKatayama Hirofumi MZ             if (stretchSkewDialog.DoModal(mainWindow.m_hWnd))
1216bf13ebdaSKatayama Hirofumi MZ             {
1217bf13ebdaSKatayama Hirofumi MZ                 CWaitCursor waitCursor;
1218bf13ebdaSKatayama Hirofumi MZ                 if (selectionModel.m_bShow)
1219bf13ebdaSKatayama Hirofumi MZ                 {
1220bf13ebdaSKatayama Hirofumi MZ                     selectionModel.StretchSkew(stretchSkewDialog.percentage.x, stretchSkewDialog.percentage.y,
1221bf13ebdaSKatayama Hirofumi MZ                                                stretchSkewDialog.angle.x, stretchSkewDialog.angle.y);
1222bf13ebdaSKatayama Hirofumi MZ                 }
1223bf13ebdaSKatayama Hirofumi MZ                 else
1224bf13ebdaSKatayama Hirofumi MZ                 {
1225bf13ebdaSKatayama Hirofumi MZ                     imageModel.StretchSkew(stretchSkewDialog.percentage.x, stretchSkewDialog.percentage.y,
1226bf13ebdaSKatayama Hirofumi MZ                                            stretchSkewDialog.angle.x, stretchSkewDialog.angle.y);
1227bf13ebdaSKatayama Hirofumi MZ                 }
1228bf13ebdaSKatayama Hirofumi MZ             }
1229bf13ebdaSKatayama Hirofumi MZ             break;
1230bf13ebdaSKatayama Hirofumi MZ         }
1231bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGEDRAWOPAQUE:
1232bf13ebdaSKatayama Hirofumi MZ             toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
1233bf13ebdaSKatayama Hirofumi MZ             break;
1234bf13ebdaSKatayama Hirofumi MZ         case IDM_IMAGECROP:
1235bf13ebdaSKatayama Hirofumi MZ         {
1236bf13ebdaSKatayama Hirofumi MZ             HBITMAP hbmCopy = selectionModel.GetSelectionContents();
1237bf13ebdaSKatayama Hirofumi MZ             imageModel.PushImageForUndo(hbmCopy);
1238bf13ebdaSKatayama Hirofumi MZ             selectionModel.HideSelection();
1239bf13ebdaSKatayama Hirofumi MZ             break;
1240bf13ebdaSKatayama Hirofumi MZ         }
1241bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWTOOLBOX:
1242bf13ebdaSKatayama Hirofumi MZ             registrySettings.ShowToolBox = !toolBoxContainer.IsWindowVisible();
1243bf13ebdaSKatayama Hirofumi MZ             toolBoxContainer.ShowWindow(registrySettings.ShowToolBox ? SW_SHOWNOACTIVATE : SW_HIDE);
1244bf13ebdaSKatayama Hirofumi MZ             alignChildrenToMainWindow();
1245bf13ebdaSKatayama Hirofumi MZ             break;
1246bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWCOLORPALETTE:
1247bf13ebdaSKatayama Hirofumi MZ             registrySettings.ShowPalette = !paletteWindow.IsWindowVisible();
1248bf13ebdaSKatayama Hirofumi MZ             paletteWindow.ShowWindow(registrySettings.ShowPalette ? SW_SHOWNOACTIVATE : SW_HIDE);
1249bf13ebdaSKatayama Hirofumi MZ             alignChildrenToMainWindow();
1250bf13ebdaSKatayama Hirofumi MZ             break;
1251bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWSTATUSBAR:
1252bf13ebdaSKatayama Hirofumi MZ             registrySettings.ShowStatusBar = !::IsWindowVisible(g_hStatusBar);
1253bf13ebdaSKatayama Hirofumi MZ             ::ShowWindow(g_hStatusBar, (registrySettings.ShowStatusBar ? SW_SHOWNOACTIVATE : SW_HIDE));
1254bf13ebdaSKatayama Hirofumi MZ             alignChildrenToMainWindow();
1255bf13ebdaSKatayama Hirofumi MZ             break;
1256bf13ebdaSKatayama Hirofumi MZ         case IDM_FORMATICONBAR:
1257bf13ebdaSKatayama Hirofumi MZ             if (toolsModel.GetActiveTool() == TOOL_TEXT)
1258bf13ebdaSKatayama Hirofumi MZ             {
1259bf13ebdaSKatayama Hirofumi MZ                 if (!fontsDialog.IsWindow())
1260bf13ebdaSKatayama Hirofumi MZ                 {
1261bf13ebdaSKatayama Hirofumi MZ                     fontsDialog.Create(mainWindow);
1262bf13ebdaSKatayama Hirofumi MZ                 }
1263bf13ebdaSKatayama Hirofumi MZ                 registrySettings.ShowTextTool = !::IsWindowVisible(fontsDialog);
1264bf13ebdaSKatayama Hirofumi MZ                 fontsDialog.ShowWindow(registrySettings.ShowTextTool ? SW_SHOW : SW_HIDE);
1265bf13ebdaSKatayama Hirofumi MZ                 fontsDialog.SendMessage(DM_REPOSITION, 0, 0);
1266bf13ebdaSKatayama Hirofumi MZ             }
1267bf13ebdaSKatayama Hirofumi MZ             break;
1268bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWSHOWGRID:
1269bf13ebdaSKatayama Hirofumi MZ             g_showGrid = !g_showGrid;
1270bf13ebdaSKatayama Hirofumi MZ             canvasWindow.Invalidate(FALSE);
1271bf13ebdaSKatayama Hirofumi MZ             break;
1272bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWSHOWMINIATURE:
1273bf13ebdaSKatayama Hirofumi MZ             registrySettings.ShowThumbnail = !::IsWindowVisible(miniature);
1274bf13ebdaSKatayama Hirofumi MZ             miniature.DoCreate(m_hWnd);
1275bf13ebdaSKatayama Hirofumi MZ             miniature.ShowWindow(registrySettings.ShowThumbnail ? SW_SHOWNOACTIVATE : SW_HIDE);
1276bf13ebdaSKatayama Hirofumi MZ             break;
1277bf13ebdaSKatayama Hirofumi MZ 
1278bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM125:
1279bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(125);
1280bf13ebdaSKatayama Hirofumi MZ             break;
1281bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM25:
1282bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(250);
1283bf13ebdaSKatayama Hirofumi MZ             break;
1284bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM50:
1285bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(500);
1286bf13ebdaSKatayama Hirofumi MZ             break;
1287bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM100:
1288bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(1000);
1289bf13ebdaSKatayama Hirofumi MZ             break;
1290bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM200:
1291bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(2000);
1292bf13ebdaSKatayama Hirofumi MZ             break;
1293bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM400:
1294bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(4000);
1295bf13ebdaSKatayama Hirofumi MZ             break;
1296bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWZOOM800:
1297bf13ebdaSKatayama Hirofumi MZ             canvasWindow.zoomTo(8000);
1298bf13ebdaSKatayama Hirofumi MZ             break;
1299bf13ebdaSKatayama Hirofumi MZ 
1300bf13ebdaSKatayama Hirofumi MZ         case IDM_VIEWFULLSCREEN:
1301bf13ebdaSKatayama Hirofumi MZ             // Create and show the fullscreen window
1302bf13ebdaSKatayama Hirofumi MZ             fullscreenWindow.DoCreate();
1303bf13ebdaSKatayama Hirofumi MZ             fullscreenWindow.ShowWindow(SW_SHOWMAXIMIZED);
1304bf13ebdaSKatayama Hirofumi MZ             break;
1305bf13ebdaSKatayama Hirofumi MZ 
1306bf13ebdaSKatayama Hirofumi MZ         case IDM_CTRL_PLUS:
1307bf13ebdaSKatayama Hirofumi MZ             toolsModel.SpecialTweak(FALSE);
1308bf13ebdaSKatayama Hirofumi MZ             break;
1309bf13ebdaSKatayama Hirofumi MZ         case IDM_CTRL_MINUS:
1310bf13ebdaSKatayama Hirofumi MZ             toolsModel.SpecialTweak(TRUE);
1311bf13ebdaSKatayama Hirofumi MZ             break;
1312bf13ebdaSKatayama Hirofumi MZ     }
1313bf13ebdaSKatayama Hirofumi MZ     return 0;
1314bf13ebdaSKatayama Hirofumi MZ }
1315bf13ebdaSKatayama Hirofumi MZ 
TrackPopupMenu(POINT ptScreen,INT iSubMenu)1316bf13ebdaSKatayama Hirofumi MZ VOID CMainWindow::TrackPopupMenu(POINT ptScreen, INT iSubMenu)
1317bf13ebdaSKatayama Hirofumi MZ {
1318bf13ebdaSKatayama Hirofumi MZ     HMENU hMenu = ::LoadMenuW(g_hinstExe, MAKEINTRESOURCEW(ID_POPUPMENU));
1319bf13ebdaSKatayama Hirofumi MZ     HMENU hSubMenu = ::GetSubMenu(hMenu, iSubMenu);
1320bf13ebdaSKatayama Hirofumi MZ 
1321bf13ebdaSKatayama Hirofumi MZ     ::SetForegroundWindow(m_hWnd);
1322bf13ebdaSKatayama Hirofumi MZ     INT_PTR id = ::TrackPopupMenu(hSubMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD,
1323bf13ebdaSKatayama Hirofumi MZ                                   ptScreen.x, ptScreen.y, 0, m_hWnd, NULL);
1324bf13ebdaSKatayama Hirofumi MZ     PostMessage(WM_NULL);
1325bf13ebdaSKatayama Hirofumi MZ     if (id != 0)
1326bf13ebdaSKatayama Hirofumi MZ         PostMessage(WM_COMMAND, id);
1327bf13ebdaSKatayama Hirofumi MZ 
1328bf13ebdaSKatayama Hirofumi MZ     ::DestroyMenu(hMenu);
1329bf13ebdaSKatayama Hirofumi MZ }
1330bf13ebdaSKatayama Hirofumi MZ 
133129e147beSKatayama Hirofumi MZ // entry point
133229e147beSKatayama Hirofumi MZ INT WINAPI
wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPWSTR lpCmdLine,INT nCmdShow)1333640d67d1SKatayama Hirofumi MZ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nCmdShow)
133429e147beSKatayama Hirofumi MZ {
1335e8c7e300SKatayama Hirofumi MZ     g_hinstExe = hInstance;
133629e147beSKatayama Hirofumi MZ 
133729e147beSKatayama Hirofumi MZ     // Initialize common controls library
133829e147beSKatayama Hirofumi MZ     INITCOMMONCONTROLSEX iccx;
133929e147beSKatayama Hirofumi MZ     iccx.dwSize = sizeof(iccx);
134029e147beSKatayama Hirofumi MZ     iccx.dwICC = ICC_STANDARD_CLASSES | ICC_USEREX_CLASSES | ICC_BAR_CLASSES;
134129e147beSKatayama Hirofumi MZ     InitCommonControlsEx(&iccx);
134229e147beSKatayama Hirofumi MZ 
134329e147beSKatayama Hirofumi MZ     // Load settings from registry
134429e147beSKatayama Hirofumi MZ     registrySettings.Load(nCmdShow);
134529e147beSKatayama Hirofumi MZ 
134629e147beSKatayama Hirofumi MZ     // Create the main window
134729e147beSKatayama Hirofumi MZ     if (!mainWindow.DoCreate())
134829e147beSKatayama Hirofumi MZ     {
1349640d67d1SKatayama Hirofumi MZ         MessageBox(NULL, L"Failed to create main window.", NULL, MB_ICONERROR);
135029e147beSKatayama Hirofumi MZ         return 1;
135129e147beSKatayama Hirofumi MZ     }
135229e147beSKatayama Hirofumi MZ 
135329e147beSKatayama Hirofumi MZ     // Initialize imageModel
13543e23cdf9SKatayama Hirofumi MZ     if (__argc < 2 || !DoLoadImageFile(mainWindow, __targv[1], TRUE))
13553e23cdf9SKatayama Hirofumi MZ         InitializeImage(NULL, NULL, FALSE);
135629e147beSKatayama Hirofumi MZ 
135729e147beSKatayama Hirofumi MZ     // Make the window visible on the screen
135829e147beSKatayama Hirofumi MZ     mainWindow.ShowWindow(registrySettings.WindowPlacement.showCmd);
135929e147beSKatayama Hirofumi MZ 
136029e147beSKatayama Hirofumi MZ     // Load the access keys
1361640d67d1SKatayama Hirofumi MZ     HACCEL hAccel = ::LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(800));
136229e147beSKatayama Hirofumi MZ 
136329e147beSKatayama Hirofumi MZ     // The message loop
136429e147beSKatayama Hirofumi MZ     MSG msg;
136529e147beSKatayama Hirofumi MZ     while (::GetMessage(&msg, NULL, 0, 0))
136629e147beSKatayama Hirofumi MZ     {
136729e147beSKatayama Hirofumi MZ         if (fontsDialog.IsWindow() && fontsDialog.IsDialogMessage(&msg))
136829e147beSKatayama Hirofumi MZ             continue;
136929e147beSKatayama Hirofumi MZ 
1370640d67d1SKatayama Hirofumi MZ         if (::TranslateAcceleratorW(mainWindow, hAccel, &msg))
137129e147beSKatayama Hirofumi MZ             continue;
137229e147beSKatayama Hirofumi MZ 
137329e147beSKatayama Hirofumi MZ         ::TranslateMessage(&msg);
137429e147beSKatayama Hirofumi MZ         ::DispatchMessage(&msg);
137529e147beSKatayama Hirofumi MZ     }
137629e147beSKatayama Hirofumi MZ 
137729e147beSKatayama Hirofumi MZ     // Unload the access keys
137829e147beSKatayama Hirofumi MZ     ::DestroyAcceleratorTable(hAccel);
137929e147beSKatayama Hirofumi MZ 
138029e147beSKatayama Hirofumi MZ     // Write back settings to registry
1381c2c66affSColin Finck     registrySettings.Store();
1382c2c66affSColin Finck 
1383ba53f72aSKatayama Hirofumi MZ     if (g_szMailTempFile[0])
1384ba53f72aSKatayama Hirofumi MZ         ::DeleteFileW(g_szMailTempFile);
1385ba53f72aSKatayama Hirofumi MZ 
138629e147beSKatayama Hirofumi MZ     // Return the value that PostQuitMessage() gave
138729e147beSKatayama Hirofumi MZ     return (INT)msg.wParam;
1388c2c66affSColin Finck }
1389