Drop logically dead code
[TortoiseGit.git] / src / TortoiseIDiff / MainWindow.cpp
blob8cd3ec0682dc396dcaed12f6dc9e62a237bed33b
1 // TortoiseIDiff - an image diff viewer in TortoiseSVN
3 // Copyright (C) 2006-2013 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include <CommCtrl.h>
21 #include <Commdlg.h>
22 #include "TortoiseIDiff.h"
23 #include "MainWindow.h"
24 #include "AboutDlg.h"
25 #include "TaskbarUUID.h"
27 #pragma comment(lib, "comctl32.lib")
29 tstring CMainWindow::leftpicpath;
30 tstring CMainWindow::leftpictitle;
32 tstring CMainWindow::rightpicpath;
33 tstring CMainWindow::rightpictitle;
35 const UINT TaskBarButtonCreated = RegisterWindowMessage(L"TaskbarButtonCreated");
37 bool CMainWindow::RegisterAndCreateWindow()
39 WNDCLASSEX wcx;
41 // Fill in the window class structure with default parameters
42 wcx.cbSize = sizeof(WNDCLASSEX);
43 wcx.style = CS_HREDRAW | CS_VREDRAW;
44 wcx.lpfnWndProc = CWindow::stWinMsgHandler;
45 wcx.cbClsExtra = 0;
46 wcx.cbWndExtra = 0;
47 wcx.hInstance = hResource;
48 wcx.hCursor = LoadCursor(NULL, IDC_SIZEWE);
49 ResString clsname(hResource, IDS_APP_TITLE);
50 wcx.lpszClassName = clsname;
51 wcx.hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_TORTOISEIDIFF));
52 wcx.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
53 if (selectionPaths.empty())
54 wcx.lpszMenuName = MAKEINTRESOURCE(IDC_TORTOISEIDIFF);
55 else
56 wcx.lpszMenuName = MAKEINTRESOURCE(IDC_TORTOISEIDIFF2);
57 wcx.hIconSm = LoadIcon(wcx.hInstance, MAKEINTRESOURCE(IDI_TORTOISEIDIFF));
58 if (RegisterWindow(&wcx))
60 if (Create(WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VISIBLE, NULL))
62 UpdateWindow(m_hwnd);
63 return true;
66 return false;
69 void CMainWindow::PositionChildren(RECT * clientrect /* = NULL */)
71 RECT tbRect;
72 if (clientrect == NULL)
73 return;
74 SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);
75 GetWindowRect(hwndTB, &tbRect);
76 LONG tbHeight = tbRect.bottom-tbRect.top-1;
77 HDWP hdwp = BeginDeferWindowPos(3);
78 if (bOverlap && selectionPaths.empty())
80 SetWindowPos(picWindow1, NULL, clientrect->left, clientrect->top+tbHeight, clientrect->right-clientrect->left, clientrect->bottom-clientrect->top-tbHeight, SWP_SHOWWINDOW);
82 else
84 if (bVertical)
86 if (selectionPaths.size() != 3)
88 // two image windows
89 RECT child;
90 child.left = clientrect->left;
91 child.top = clientrect->top+tbHeight;
92 child.right = clientrect->right;
93 child.bottom = nSplitterPos-(SPLITTER_BORDER/2);
94 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow1, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
95 child.top = nSplitterPos+(SPLITTER_BORDER/2);
96 child.bottom = clientrect->bottom;
97 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow2, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
99 else
101 // three image windows
102 RECT child;
103 child.left = clientrect->left;
104 child.top = clientrect->top+tbHeight;
105 child.right = clientrect->right;
106 child.bottom = nSplitterPos-(SPLITTER_BORDER/2);
107 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow1, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
108 child.top = nSplitterPos+(SPLITTER_BORDER/2);
109 child.bottom = nSplitterPos2-(SPLITTER_BORDER/2);
110 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow2, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
111 child.top = nSplitterPos2+(SPLITTER_BORDER/2);
112 child.bottom = clientrect->bottom;
113 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow3, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
116 else
118 if (selectionPaths.size() != 3)
120 // two image windows
121 RECT child;
122 child.left = clientrect->left;
123 child.top = clientrect->top+tbHeight;
124 child.right = nSplitterPos-(SPLITTER_BORDER/2);
125 child.bottom = clientrect->bottom;
126 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow1, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
127 child.left = nSplitterPos+(SPLITTER_BORDER/2);
128 child.right = clientrect->right;
129 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow2, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
131 else
133 // three image windows
134 RECT child;
135 child.left = clientrect->left;
136 child.top = clientrect->top+tbHeight;
137 child.right = nSplitterPos-(SPLITTER_BORDER/2);
138 child.bottom = clientrect->bottom;
139 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow1, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
140 child.left = nSplitterPos+(SPLITTER_BORDER/2);
141 child.right = nSplitterPos2-(SPLITTER_BORDER/2);
142 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow2, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
143 child.left = nSplitterPos2+(SPLITTER_BORDER/2);
144 child.right = clientrect->right;
145 if (hdwp) hdwp = DeferWindowPos(hdwp, picWindow3, NULL, child.left, child.top, child.right-child.left, child.bottom-child.top, SWP_FRAMECHANGED|SWP_SHOWWINDOW);
149 if (hdwp) EndDeferWindowPos(hdwp);
150 picWindow1.SetTransparentColor(transparentColor);
151 picWindow2.SetTransparentColor(transparentColor);
152 picWindow3.SetTransparentColor(transparentColor);
153 InvalidateRect(*this, NULL, FALSE);
156 LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
158 if (uMsg == TaskBarButtonCreated)
160 SetUUIDOverlayIcon(hwnd);
162 switch (uMsg)
164 case WM_CREATE:
166 m_hwnd = hwnd;
167 picWindow1.RegisterAndCreateWindow(hwnd);
168 picWindow2.RegisterAndCreateWindow(hwnd);
169 if (selectionPaths.empty())
171 picWindow1.SetPic(leftpicpath, leftpictitle, true);
172 picWindow2.SetPic(rightpicpath, rightpictitle, false);
174 picWindow1.SetOtherPicWindow(&picWindow2);
175 picWindow2.SetOtherPicWindow(&picWindow1);
177 else
179 picWindow3.RegisterAndCreateWindow(hwnd);
181 picWindow1.SetPic(selectionPaths[FileTypeMine], selectionTitles[FileTypeMine], false);
182 picWindow2.SetPic(selectionPaths[FileTypeBase], selectionTitles[FileTypeBase], false);
183 picWindow3.SetPic(selectionPaths[FileTypeTheirs], selectionTitles[FileTypeTheirs], false);
186 picWindow1.SetSelectionMode(!selectionPaths.empty());
187 picWindow2.SetSelectionMode(!selectionPaths.empty());
188 picWindow3.SetSelectionMode(!selectionPaths.empty());
190 CreateToolbar();
191 // center the splitter
192 RECT rect;
193 GetClientRect(hwnd, &rect);
194 if (selectionPaths.size() != 3)
196 nSplitterPos = (rect.right-rect.left)/2;
197 nSplitterPos2 = 0;
199 else
201 nSplitterPos = (rect.right-rect.left)/3;
202 nSplitterPos2 = (rect.right-rect.left)*2/3;
205 PositionChildren(&rect);
206 picWindow1.FitImageInWindow();
207 picWindow2.FitImageInWindow();
208 picWindow3.FitImageInWindow();
210 break;
211 case WM_COMMAND:
213 return DoCommand(LOWORD(wParam), lParam);
215 break;
216 case WM_PAINT:
218 PAINTSTRUCT ps;
219 HDC hdc;
220 RECT rect;
222 ::GetClientRect(*this, &rect);
223 hdc = BeginPaint(hwnd, &ps);
224 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
225 ::ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
226 EndPaint(hwnd, &ps);
228 break;
229 case WM_GETMINMAXINFO:
231 MINMAXINFO * mmi = (MINMAXINFO*)lParam;
232 mmi->ptMinTrackSize.x = WINDOW_MINWIDTH;
233 mmi->ptMinTrackSize.y = WINDOW_MINHEIGHT;
234 return 0;
236 break;
237 case WM_SIZE:
239 RECT rect;
240 GetClientRect(hwnd, &rect);
241 if (bVertical)
243 RECT tbRect;
244 GetWindowRect(hwndTB, &tbRect);
245 LONG tbHeight = tbRect.bottom-tbRect.top-1;
246 if (selectionPaths.size() != 3)
248 nSplitterPos = (rect.bottom-rect.top)/2+tbHeight;
249 nSplitterPos2 = 0;
251 else
253 nSplitterPos = (rect.bottom-rect.top)/3+tbHeight;
254 nSplitterPos2 = (rect.bottom-rect.top)*2/3+tbHeight;
257 else
259 if (selectionPaths.size() != 3)
261 nSplitterPos = (rect.right-rect.left)/2;
262 nSplitterPos2 = 0;
264 else
266 nSplitterPos = (rect.right-rect.left)/3;
267 nSplitterPos2 = (rect.right-rect.left)*2/3;
270 PositionChildren(&rect);
272 break;
273 case WM_SETCURSOR:
275 if ((HWND)wParam == *this)
277 RECT rect;
278 POINT pt;
279 GetClientRect(*this, &rect);
280 GetCursorPos(&pt);
281 ScreenToClient(*this, &pt);
282 if (PtInRect(&rect, pt))
284 if (bVertical)
286 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS));
287 SetCursor(hCur);
289 else
291 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE));
292 SetCursor(hCur);
294 return TRUE;
297 return DefWindowProc(hwnd, uMsg, wParam, lParam);
299 break;
300 case WM_LBUTTONDOWN:
301 Splitter_OnLButtonDown(hwnd, uMsg, wParam, lParam);
302 break;
303 case WM_LBUTTONUP:
304 Splitter_OnLButtonUp(hwnd, uMsg, wParam, lParam);
305 break;
306 case WM_CAPTURECHANGED:
307 Splitter_CaptureChanged();
308 break;
309 case WM_MOUSEMOVE:
310 Splitter_OnMouseMove(hwnd, uMsg, wParam, lParam);
311 break;
312 case WM_MOUSEWHEEL:
314 // find out if the mouse cursor is over one of the views, and if
315 // it is, pass the mouse wheel message to that view
316 POINT pt;
317 DWORD ptW = GetMessagePos();
318 pt.x = GET_X_LPARAM(ptW);
319 pt.y = GET_Y_LPARAM(ptW);
320 RECT rect;
321 GetWindowRect(picWindow1, &rect);
322 if (PtInRect(&rect, pt))
324 picWindow1.OnMouseWheel(GET_KEYSTATE_WPARAM(wParam), GET_WHEEL_DELTA_WPARAM(wParam));
326 else
328 GetWindowRect(picWindow2, &rect);
329 if (PtInRect(&rect, pt))
331 picWindow2.OnMouseWheel(GET_KEYSTATE_WPARAM(wParam), GET_WHEEL_DELTA_WPARAM(wParam));
333 else
335 GetWindowRect(picWindow3, &rect);
336 if (PtInRect(&rect, pt))
338 picWindow3.OnMouseWheel(GET_KEYSTATE_WPARAM(wParam), GET_WHEEL_DELTA_WPARAM(wParam));
343 break;
344 case WM_MOUSEHWHEEL:
346 // find out if the mouse cursor is over one of the views, and if
347 // it is, pass the mouse wheel message to that view
348 POINT pt;
349 DWORD ptW = GetMessagePos();
350 pt.x = GET_X_LPARAM(ptW);
351 pt.y = GET_Y_LPARAM(ptW);
352 RECT rect;
353 GetWindowRect(picWindow1, &rect);
354 if (PtInRect(&rect, pt))
356 picWindow1.OnMouseWheel(GET_KEYSTATE_WPARAM(wParam)|MK_SHIFT, GET_WHEEL_DELTA_WPARAM(wParam));
358 else
360 GetWindowRect(picWindow2, &rect);
361 if (PtInRect(&rect, pt))
363 picWindow2.OnMouseWheel(GET_KEYSTATE_WPARAM(wParam)|MK_SHIFT, GET_WHEEL_DELTA_WPARAM(wParam));
365 else
367 GetWindowRect(picWindow3, &rect);
368 if (PtInRect(&rect, pt))
370 picWindow3.OnMouseWheel(GET_KEYSTATE_WPARAM(wParam)|MK_SHIFT, GET_WHEEL_DELTA_WPARAM(wParam));
375 break;
376 case WM_NOTIFY:
378 LPNMHDR pNMHDR = (LPNMHDR)lParam;
379 if (pNMHDR->code == TTN_GETDISPINFO)
381 LPTOOLTIPTEXT lpttt;
383 lpttt = (LPTOOLTIPTEXT) lParam;
384 lpttt->hinst = hResource;
386 // Specify the resource identifier of the descriptive
387 // text for the given button.
388 TCHAR stringbuf[MAX_PATH] = {0};
389 MENUITEMINFO mii;
390 mii.cbSize = sizeof(MENUITEMINFO);
391 mii.fMask = MIIM_TYPE;
392 mii.dwTypeData = stringbuf;
393 mii.cch = _countof(stringbuf);
394 GetMenuItemInfo(GetMenu(*this), (UINT)lpttt->hdr.idFrom, FALSE, &mii);
395 _tcscpy_s(lpttt->lpszText, 80, stringbuf);
398 break;
399 case WM_DESTROY:
400 bWindowClosed = TRUE;
401 PostQuitMessage(0);
402 break;
403 case WM_CLOSE:
404 ImageList_Destroy(hToolbarImgList);
405 ::DestroyWindow(m_hwnd);
406 break;
407 default:
408 return DefWindowProc(hwnd, uMsg, wParam, lParam);
411 return 0;
414 LRESULT CMainWindow::DoCommand(int id, LPARAM lParam)
416 switch (id)
418 case ID_FILE_OPEN:
420 if (OpenDialog())
422 picWindow1.SetPic(leftpicpath, _T(""), true);
423 picWindow2.SetPic(rightpicpath, _T(""), false);
424 if (bOverlap)
426 picWindow1.SetSecondPic(picWindow2.GetPic(), rightpictitle, rightpicpath);
428 else
430 picWindow1.SetSecondPic();
432 RECT rect;
433 GetClientRect(*this, &rect);
434 PositionChildren(&rect);
435 picWindow1.FitImageInWindow();
436 picWindow2.FitImageInWindow();
439 break;
440 case ID_VIEW_IMAGEINFO:
442 bShowInfo = !bShowInfo;
443 HMENU hMenu = GetMenu(*this);
444 UINT uCheck = MF_BYCOMMAND;
445 uCheck |= bShowInfo ? MF_CHECKED : MF_UNCHECKED;
446 CheckMenuItem(hMenu, ID_VIEW_IMAGEINFO, uCheck);
448 picWindow1.ShowInfo(bShowInfo);
449 picWindow2.ShowInfo(bShowInfo);
450 picWindow3.ShowInfo(bShowInfo);
452 // change the state of the toolbar button
453 TBBUTTONINFO tbi;
454 tbi.cbSize = sizeof(TBBUTTONINFO);
455 tbi.dwMask = TBIF_STATE;
456 tbi.fsState = bShowInfo ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
457 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_IMAGEINFO, (LPARAM)&tbi);
459 break;
460 case ID_VIEW_OVERLAPIMAGES:
462 bOverlap = !bOverlap;
463 HMENU hMenu = GetMenu(*this);
464 UINT uCheck = MF_BYCOMMAND;
465 uCheck |= bOverlap ? MF_CHECKED : MF_UNCHECKED;
466 CheckMenuItem(hMenu, ID_VIEW_OVERLAPIMAGES, uCheck);
467 uCheck |= (m_BlendType == CPicWindow::BLEND_ALPHA) ? MF_CHECKED : MF_UNCHECKED;
468 CheckMenuItem(hMenu, ID_VIEW_BLENDALPHA, uCheck);
470 // change the state of the toolbar button
471 TBBUTTONINFO tbi;
472 tbi.cbSize = sizeof(TBBUTTONINFO);
473 tbi.dwMask = TBIF_STATE;
474 tbi.fsState = bOverlap ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
475 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_OVERLAPIMAGES, (LPARAM)&tbi);
477 tbi.fsState = (m_BlendType == CPicWindow::BLEND_ALPHA) ? TBSTATE_CHECKED : 0;
478 if (bOverlap)
479 tbi.fsState |= TBSTATE_ENABLED;
480 else
481 tbi.fsState = 0;
482 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_BLENDALPHA, (LPARAM)&tbi);
484 if (bOverlap)
485 tbi.fsState = 0;
486 else
487 tbi.fsState = bVertical ? TBSTATE_ENABLED | TBSTATE_CHECKED : TBSTATE_ENABLED;
488 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_ARRANGEVERTICAL, (LPARAM)&tbi);
490 if (bOverlap)
492 bLinkedPositions = true;
493 picWindow1.LinkPositions(bLinkedPositions);
494 picWindow2.LinkPositions(bLinkedPositions);
495 tbi.fsState = TBSTATE_CHECKED;
497 else
498 tbi.fsState = bLinkedPositions ? TBSTATE_ENABLED | TBSTATE_CHECKED : TBSTATE_ENABLED;
499 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_LINKIMAGESTOGETHER, (LPARAM)&tbi);
501 ShowWindow(picWindow2, bOverlap ? SW_HIDE : SW_SHOW);
503 if (bOverlap)
505 picWindow1.StopTimer();
506 picWindow2.StopTimer();
507 picWindow1.SetSecondPic(picWindow2.GetPic(), rightpictitle, rightpicpath,
508 picWindow2.GetHPos(), picWindow2.GetVPos());
509 picWindow1.SetBlendAlpha(m_BlendType, 0.5f);
511 else
513 picWindow1.SetSecondPic();
515 picWindow1.SetOverlapMode(bOverlap);
516 picWindow2.SetOverlapMode(bOverlap);
519 RECT rect;
520 GetClientRect(*this, &rect);
521 PositionChildren(&rect);
523 return 0;
525 break;
526 case ID_VIEW_BLENDALPHA:
528 if (m_BlendType == CPicWindow::BLEND_ALPHA)
529 m_BlendType = CPicWindow::BLEND_XOR;
530 else
531 m_BlendType = CPicWindow::BLEND_ALPHA;
533 HMENU hMenu = GetMenu(*this);
534 UINT uCheck = MF_BYCOMMAND;
535 uCheck |= (m_BlendType == CPicWindow::BLEND_ALPHA) ? MF_CHECKED : MF_UNCHECKED;
536 CheckMenuItem(hMenu, ID_VIEW_BLENDALPHA, uCheck);
538 // change the state of the toolbar button
539 TBBUTTONINFO tbi;
540 tbi.cbSize = sizeof(TBBUTTONINFO);
541 tbi.dwMask = TBIF_STATE;
542 tbi.fsState = (m_BlendType == CPicWindow::BLEND_ALPHA) ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
543 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_BLENDALPHA, (LPARAM)&tbi);
544 picWindow1.SetBlendAlpha(m_BlendType, picWindow1.GetBlendAlpha());
545 PositionChildren();
547 break;
548 case ID_VIEW_TRANSPARENTCOLOR:
550 static COLORREF customColors[16] = {0};
551 CHOOSECOLOR ccDlg;
552 memset(&ccDlg, 0, sizeof(ccDlg));
553 ccDlg.lStructSize = sizeof(ccDlg);
554 ccDlg.hwndOwner = m_hwnd;
555 ccDlg.rgbResult = transparentColor;
556 ccDlg.lpCustColors = customColors;
557 ccDlg.Flags = CC_RGBINIT | CC_FULLOPEN;
558 if(ChooseColor(&ccDlg))
560 transparentColor = ccDlg.rgbResult;
561 picWindow1.SetTransparentColor(transparentColor);
562 picWindow2.SetTransparentColor(transparentColor);
563 picWindow3.SetTransparentColor(transparentColor);
564 // The color picker takes the focus and we don't get it back.
565 ::SetFocus(picWindow1);
568 break;
569 case ID_VIEW_FITIMAGEWIDTHS:
571 bFitWidths = !bFitWidths;
572 picWindow1.FitWidths(bFitWidths);
573 picWindow2.FitWidths(bFitWidths);
574 picWindow3.FitWidths(bFitWidths);
576 HMENU hMenu = GetMenu(*this);
577 UINT uCheck = MF_BYCOMMAND;
578 uCheck |= bFitWidths ? MF_CHECKED : MF_UNCHECKED;
579 CheckMenuItem(hMenu, ID_VIEW_FITIMAGEWIDTHS, uCheck);
581 // change the state of the toolbar button
582 TBBUTTONINFO tbi;
583 tbi.cbSize = sizeof(TBBUTTONINFO);
584 tbi.dwMask = TBIF_STATE;
585 tbi.fsState = bFitWidths ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
586 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_FITIMAGEWIDTHS, (LPARAM)&tbi);
588 break;
589 case ID_VIEW_FITIMAGEHEIGHTS:
591 bFitHeights = !bFitHeights;
592 picWindow1.FitHeights(bFitHeights);
593 picWindow2.FitHeights(bFitHeights);
594 picWindow3.FitHeights(bFitHeights);
596 HMENU hMenu = GetMenu(*this);
597 UINT uCheck = MF_BYCOMMAND;
598 uCheck |= bFitHeights ? MF_CHECKED : MF_UNCHECKED;
599 CheckMenuItem(hMenu, ID_VIEW_FITIMAGEHEIGHTS, uCheck);
601 // change the state of the toolbar button
602 TBBUTTONINFO tbi;
603 tbi.cbSize = sizeof(TBBUTTONINFO);
604 tbi.dwMask = TBIF_STATE;
605 tbi.fsState = bFitHeights ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
606 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_FITIMAGEHEIGHTS, (LPARAM)&tbi);
608 break;
609 case ID_VIEW_LINKIMAGESTOGETHER:
611 bLinkedPositions = !bLinkedPositions;
612 picWindow1.LinkPositions(bLinkedPositions);
613 picWindow2.LinkPositions(bLinkedPositions);
614 picWindow3.LinkPositions(bLinkedPositions);
616 HMENU hMenu = GetMenu(*this);
617 UINT uCheck = MF_BYCOMMAND;
618 uCheck |= bLinkedPositions ? MF_CHECKED : MF_UNCHECKED;
619 CheckMenuItem(hMenu, ID_VIEW_LINKIMAGESTOGETHER, uCheck);
621 // change the state of the toolbar button
622 TBBUTTONINFO tbi;
623 tbi.cbSize = sizeof(TBBUTTONINFO);
624 tbi.dwMask = TBIF_STATE;
625 tbi.fsState = bLinkedPositions ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
626 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_LINKIMAGESTOGETHER, (LPARAM)&tbi);
628 break;
629 case ID_VIEW_ALPHA0:
630 picWindow1.SetBlendAlpha(m_BlendType, 0.0f);
631 break;
632 case ID_VIEW_ALPHA255:
633 picWindow1.SetBlendAlpha(m_BlendType, 1.0f);
634 break;
635 case ID_VIEW_ALPHA127:
636 picWindow1.SetBlendAlpha(m_BlendType, 0.5f);
637 break;
638 case ID_VIEW_ALPHATOGGLE:
639 picWindow1.ToggleAlpha();
640 break;
641 case ID_VIEW_FITIMAGESINWINDOW:
643 picWindow1.FitImageInWindow();
644 picWindow2.FitImageInWindow();
645 picWindow3.FitImageInWindow();
647 break;
648 case ID_VIEW_ORININALSIZE:
650 picWindow1.SetZoom(100, false);
651 picWindow2.SetZoom(100, false);
652 picWindow3.SetZoom(100, false);
653 picWindow1.CenterImage();
654 picWindow2.CenterImage();
655 picWindow3.CenterImage();
657 break;
658 case ID_VIEW_ZOOMIN:
660 picWindow1.Zoom(true, false);
661 if ((!(bFitWidths || bFitHeights))&&(!bOverlap))
663 picWindow2.Zoom(true, false);
664 picWindow3.Zoom(true, false);
667 break;
668 case ID_VIEW_ZOOMOUT:
670 picWindow1.Zoom(false, false);
671 if ((!(bFitWidths || bFitHeights))&&(!bOverlap))
673 picWindow2.Zoom(false, false);
674 picWindow3.Zoom(false, false);
677 break;
678 case ID_VIEW_ARRANGEVERTICAL:
680 bVertical = !bVertical;
681 RECT rect;
682 GetClientRect(*this, &rect);
683 if (bVertical)
685 RECT tbRect;
686 GetWindowRect(hwndTB, &tbRect);
687 LONG tbHeight = tbRect.bottom-tbRect.top-1;
688 if (selectionPaths.size() != 3)
690 nSplitterPos = (rect.bottom-rect.top)/2+tbHeight;
691 nSplitterPos2 = 0;
693 else
695 nSplitterPos = (rect.bottom-rect.top)/3+tbHeight;
696 nSplitterPos2 = (rect.bottom-rect.top)*2/3+tbHeight;
699 else
701 if (selectionPaths.size() != 3)
703 nSplitterPos = (rect.right-rect.left)/2;
704 nSplitterPos2 = 0;
706 else
708 nSplitterPos = (rect.right-rect.left)/3;
709 nSplitterPos2 = (rect.right-rect.left)*2/3;
712 HMENU hMenu = GetMenu(*this);
713 UINT uCheck = MF_BYCOMMAND;
714 uCheck |= bVertical ? MF_CHECKED : MF_UNCHECKED;
715 CheckMenuItem(hMenu, ID_VIEW_ARRANGEVERTICAL, uCheck);
716 // change the state of the toolbar button
717 TBBUTTONINFO tbi;
718 tbi.cbSize = sizeof(TBBUTTONINFO);
719 tbi.dwMask = TBIF_STATE;
720 tbi.fsState = bVertical ? TBSTATE_CHECKED | TBSTATE_ENABLED : TBSTATE_ENABLED;
721 SendMessage(hwndTB, TB_SETBUTTONINFO, ID_VIEW_ARRANGEVERTICAL, (LPARAM)&tbi);
723 PositionChildren(&rect);
725 break;
726 case ID_ABOUT:
728 CAboutDlg dlg(*this);
729 dlg.DoModal(hInst, IDD_ABOUT, *this);
731 break;
732 case SELECTBUTTON_ID:
734 HWND hSource = (HWND)lParam;
735 if (picWindow1 == hSource)
737 if (!selectionResult.empty())
738 CopyFile(selectionPaths[FileTypeMine].c_str(), selectionResult.c_str(), FALSE);
739 PostQuitMessage(FileTypeMine);
741 if (picWindow2 == hSource)
743 if (!selectionResult.empty())
744 CopyFile(selectionPaths[FileTypeBase].c_str(), selectionResult.c_str(), FALSE);
745 PostQuitMessage(FileTypeBase);
747 if (picWindow3 == hSource)
749 if (!selectionResult.empty())
750 CopyFile(selectionPaths[FileTypeTheirs].c_str(), selectionResult.c_str(), FALSE);
751 PostQuitMessage(FileTypeTheirs);
754 break;
755 case IDM_EXIT:
756 ::PostQuitMessage(0);
757 return 0;
758 break;
759 default:
760 break;
762 return 1;
765 // splitter stuff
766 void CMainWindow::DrawXorBar(HDC hdc, int x1, int y1, int width, int height)
768 static WORD _dotPatternBmp[8] =
770 0x0055, 0x00aa, 0x0055, 0x00aa,
771 0x0055, 0x00aa, 0x0055, 0x00aa
774 HBITMAP hbm;
775 HBRUSH hbr, hbrushOld;
777 hbm = CreateBitmap(8, 8, 1, 1, _dotPatternBmp);
778 hbr = CreatePatternBrush(hbm);
780 SetBrushOrgEx(hdc, x1, y1, 0);
781 hbrushOld = (HBRUSH)SelectObject(hdc, hbr);
783 PatBlt(hdc, x1, y1, width, height, PATINVERT);
785 SelectObject(hdc, hbrushOld);
787 DeleteObject(hbr);
788 DeleteObject(hbm);
791 LRESULT CMainWindow::Splitter_OnLButtonDown(HWND hwnd, UINT /*iMsg*/, WPARAM /*wParam*/, LPARAM lParam)
793 POINT pt;
794 HDC hdc;
795 RECT rect;
796 RECT clientrect;
798 pt.x = (short)LOWORD(lParam); // horizontal position of cursor
799 pt.y = (short)HIWORD(lParam);
801 GetClientRect(hwnd, &clientrect);
802 GetWindowRect(hwnd, &rect);
803 POINT zero = {0,0};
804 ClientToScreen(hwnd, &zero);
805 OffsetRect(&clientrect, zero.x-rect.left, zero.y-rect.top);
807 ClientToScreen(hwnd, &pt);
808 // find out which drag bar is used
809 bDrag2 = false;
810 if (!selectionPaths.empty())
812 RECT pic2Rect;
813 GetWindowRect(picWindow2, &pic2Rect);
814 if (bVertical)
816 if (pic2Rect.bottom <= pt.y)
817 bDrag2 = true;
819 else
821 if (pic2Rect.right <= pt.x)
822 bDrag2 = true;
826 //convert the mouse coordinates relative to the top-left of
827 //the window
828 pt.x -= rect.left;
829 pt.y -= rect.top;
831 //same for the window coordinates - make them relative to 0,0
832 OffsetRect(&rect, -rect.left, -rect.top);
834 if (pt.x < 0)
835 pt.x = 0;
836 if (pt.x > rect.right-4)
837 pt.x = rect.right-4;
838 if (pt.y < 0)
839 pt.y = 0;
840 if (pt.y > rect.bottom-4)
841 pt.y = rect.bottom-4;
843 bDragMode = true;
845 SetCapture(hwnd);
847 hdc = GetWindowDC(hwnd);
848 if (bVertical)
849 DrawXorBar(hdc, clientrect.left, pt.y+2, clientrect.right-clientrect.left-2, 4);
850 else
851 DrawXorBar(hdc, pt.x+2, clientrect.top, 4, clientrect.bottom-clientrect.top-2);
852 ReleaseDC(hwnd, hdc);
854 oldx = pt.x;
855 oldy = pt.y;
857 return 0;
860 void CMainWindow::Splitter_CaptureChanged()
862 bDragMode = false;
865 LRESULT CMainWindow::Splitter_OnLButtonUp(HWND hwnd, UINT /*iMsg*/, WPARAM /*wParam*/, LPARAM lParam)
867 HDC hdc;
868 RECT rect;
869 RECT clientrect;
871 POINT pt;
872 pt.x = (short)LOWORD(lParam); // horizontal position of cursor
873 pt.y = (short)HIWORD(lParam);
875 if (bDragMode == FALSE)
876 return 0;
878 GetClientRect(hwnd, &clientrect);
879 GetWindowRect(hwnd, &rect);
880 POINT zero = {0,0};
881 ClientToScreen(hwnd, &zero);
882 OffsetRect(&clientrect, zero.x-rect.left, zero.y-rect.top);
884 ClientToScreen(hwnd, &pt);
885 pt.x -= rect.left;
886 pt.y -= rect.top;
888 OffsetRect(&rect, -rect.left, -rect.top);
890 if (pt.x < 0)
891 pt.x = 0;
892 if (pt.x > rect.right-4)
893 pt.x = rect.right-4;
894 if (pt.y < 0)
895 pt.y = 0;
896 if (pt.y > rect.bottom-4)
897 pt.y = rect.bottom-4;
899 hdc = GetWindowDC(hwnd);
900 if (bVertical)
901 DrawXorBar(hdc, clientrect.left, oldy+2, clientrect.right-clientrect.left-2, 4);
902 else
903 DrawXorBar(hdc, oldx+2, clientrect.top, 4, clientrect.bottom-clientrect.top-2);
904 ReleaseDC(hwnd, hdc);
906 oldx = pt.x;
907 oldy = pt.y;
909 bDragMode = false;
911 //convert the splitter position back to screen coords.
912 GetWindowRect(hwnd, &rect);
913 pt.x += rect.left;
914 pt.y += rect.top;
916 //now convert into CLIENT coordinates
917 ScreenToClient(hwnd, &pt);
918 GetClientRect(hwnd, &rect);
919 #define MINWINSIZE 10
920 if (bVertical)
922 if (bDrag2)
924 if (pt.y < (nSplitterPos+MINWINSIZE))
925 pt.y = nSplitterPos+MINWINSIZE;
926 nSplitterPos2 = pt.y;
928 else
930 if (pt.y > (nSplitterPos2-MINWINSIZE))
931 pt.y = nSplitterPos2-MINWINSIZE;
932 nSplitterPos = pt.y;
935 else
937 if (bDrag2)
939 if (pt.x < (nSplitterPos+MINWINSIZE))
940 pt.x = nSplitterPos+MINWINSIZE;
941 nSplitterPos2 = pt.x;
943 else
945 if (pt.x > (nSplitterPos2-MINWINSIZE))
946 pt.x = nSplitterPos2-MINWINSIZE;
947 nSplitterPos = pt.x;
951 ReleaseCapture();
953 //position the child controls
954 PositionChildren(&rect);
955 return 0;
958 LRESULT CMainWindow::Splitter_OnMouseMove(HWND hwnd, UINT /*iMsg*/, WPARAM wParam, LPARAM lParam)
960 HDC hdc;
961 RECT rect;
962 RECT clientrect;
964 POINT pt;
966 if (bDragMode == FALSE)
967 return 0;
969 pt.x = (short)LOWORD(lParam); // horizontal position of cursor
970 pt.y = (short)HIWORD(lParam);
972 GetClientRect(hwnd, &clientrect);
973 GetWindowRect(hwnd, &rect);
974 POINT zero = {0,0};
975 ClientToScreen(hwnd, &zero);
976 OffsetRect(&clientrect, zero.x-rect.left, zero.y-rect.top);
978 //convert the mouse coordinates relative to the top-left of
979 //the window
980 ClientToScreen(hwnd, &pt);
981 pt.x -= rect.left;
982 pt.y -= rect.top;
984 //same for the window coordinates - make them relative to 0,0
985 OffsetRect(&rect, -rect.left, -rect.top);
987 if (pt.x < 0)
988 pt.x = 0;
989 if (pt.x > rect.right-4)
990 pt.x = rect.right-4;
991 if (pt.y < 0)
992 pt.y = 0;
993 if (pt.y > rect.bottom-4)
994 pt.y = rect.bottom-4;
996 if ((wParam & MK_LBUTTON) && ((bVertical && (pt.y != oldy)) || (!bVertical && (pt.x != oldx))))
998 hdc = GetWindowDC(hwnd);
1000 if (bVertical)
1002 DrawXorBar(hdc, clientrect.left, oldy+2, clientrect.right-clientrect.left-2, 4);
1003 DrawXorBar(hdc, clientrect.left, pt.y+2, clientrect.right-clientrect.left-2, 4);
1005 else
1007 DrawXorBar(hdc, oldx+2, clientrect.top, 4, clientrect.bottom-clientrect.top-2);
1008 DrawXorBar(hdc, pt.x+2, clientrect.top, 4, clientrect.bottom-clientrect.top-2);
1011 ReleaseDC(hwnd, hdc);
1013 oldx = pt.x;
1014 oldy = pt.y;
1017 return 0;
1020 bool CMainWindow::OpenDialog()
1022 return (DialogBox(hResource, MAKEINTRESOURCE(IDD_OPEN), *this, (DLGPROC)OpenDlgProc)==IDOK);
1025 BOOL CALLBACK CMainWindow::OpenDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM /*lParam*/)
1027 switch (message)
1029 case WM_INITDIALOG:
1031 // center on the parent window
1032 HWND hParentWnd = ::GetParent(hwndDlg);
1033 RECT parentrect, childrect, centeredrect;
1034 GetWindowRect(hParentWnd, &parentrect);
1035 GetWindowRect(hwndDlg, &childrect);
1036 centeredrect.left = parentrect.left + ((parentrect.right-parentrect.left-childrect.right+childrect.left)/2);
1037 centeredrect.right = centeredrect.left + (childrect.right-childrect.left);
1038 centeredrect.top = parentrect.top + ((parentrect.bottom-parentrect.top-childrect.bottom+childrect.top)/2);
1039 centeredrect.bottom = centeredrect.top + (childrect.bottom-childrect.top);
1040 SetWindowPos(hwndDlg, NULL, centeredrect.left, centeredrect.top, centeredrect.right-centeredrect.left, centeredrect.bottom-centeredrect.top, SWP_SHOWWINDOW);
1042 if (!leftpicpath.empty())
1043 SetDlgItemText(hwndDlg, IDC_LEFTIMAGE, leftpicpath.c_str());
1044 SetFocus(hwndDlg);
1046 break;
1047 case WM_COMMAND:
1048 switch (LOWORD(wParam))
1050 case IDC_LEFTBROWSE:
1052 TCHAR path[MAX_PATH] = {0};
1053 if (AskForFile(hwndDlg, path))
1055 SetDlgItemText(hwndDlg, IDC_LEFTIMAGE, path);
1058 break;
1059 case IDC_RIGHTBROWSE:
1061 TCHAR path[MAX_PATH] = {0};
1062 if (AskForFile(hwndDlg, path))
1064 SetDlgItemText(hwndDlg, IDC_RIGHTIMAGE, path);
1067 break;
1068 case IDOK:
1070 TCHAR path[MAX_PATH] = {0};
1071 if (!GetDlgItemText(hwndDlg, IDC_LEFTIMAGE, path, _countof(path)))
1072 *path = 0;
1073 leftpicpath = path;
1074 if (!GetDlgItemText(hwndDlg, IDC_RIGHTIMAGE, path, _countof(path)))
1075 *path = 0;
1076 rightpicpath = path;
1078 // Fall through.
1079 case IDCANCEL:
1080 EndDialog(hwndDlg, wParam);
1081 return TRUE;
1084 return FALSE;
1087 bool CMainWindow::AskForFile(HWND owner, TCHAR * path)
1089 OPENFILENAME ofn = {0}; // common dialog box structure
1090 // Initialize OPENFILENAME
1091 ofn.lStructSize = sizeof(OPENFILENAME);
1092 ofn.hwndOwner = owner;
1093 ofn.lpstrFile = path;
1094 ofn.nMaxFile = MAX_PATH;
1095 ResString sTitle(::hResource, IDS_OPENIMAGEFILE);
1096 ofn.lpstrTitle = sTitle;
1097 ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_EXPLORER;
1098 ofn.hInstance = ::hResource;
1099 TCHAR filters[] = _T("Images\0*.wmf;*.jpg;*jpeg;*.bmp;*.gif;*.png;*.ico;*.dib;*.emf\0All (*.*)\0*.*\0\0");
1100 ofn.lpstrFilter = filters;
1101 ofn.nFilterIndex = 1;
1102 // Display the Open dialog box.
1103 if (GetOpenFileName(&ofn)==FALSE)
1105 return false;
1107 return true;
1110 bool CMainWindow::CreateToolbar()
1112 // Ensure that the common control DLL is loaded.
1113 INITCOMMONCONTROLSEX icex;
1114 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1115 icex.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES;
1116 InitCommonControlsEx(&icex);
1118 hwndTB = CreateWindowEx(0,
1119 TOOLBARCLASSNAME,
1120 (LPCTSTR)NULL,
1121 WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
1122 0, 0, 0, 0,
1123 *this,
1124 (HMENU)IDC_TORTOISEIDIFF,
1125 hResource,
1126 NULL);
1127 if (hwndTB == INVALID_HANDLE_VALUE)
1128 return false;
1130 SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
1132 TBBUTTON tbb[13];
1133 // create an imagelist containing the icons for the toolbar
1134 hToolbarImgList = ImageList_Create(24, 24, ILC_COLOR32 | ILC_MASK, 12, 4);
1135 if (hToolbarImgList == NULL)
1136 return false;
1137 int index = 0;
1138 HICON hIcon = NULL;
1139 if (selectionPaths.empty())
1141 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_OVERLAP));
1142 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1143 tbb[index].idCommand = ID_VIEW_OVERLAPIMAGES;
1144 tbb[index].fsState = TBSTATE_ENABLED;
1145 tbb[index].fsStyle = BTNS_BUTTON;
1146 tbb[index].dwData = 0;
1147 tbb[index++].iString = 0;
1149 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_BLEND));
1150 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1151 tbb[index].idCommand = ID_VIEW_BLENDALPHA;
1152 tbb[index].fsState = 0;
1153 tbb[index].fsStyle = BTNS_BUTTON;
1154 tbb[index].dwData = 0;
1155 tbb[index++].iString = 0;
1157 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_LINK));
1158 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1159 tbb[index].idCommand = ID_VIEW_LINKIMAGESTOGETHER;
1160 tbb[index].fsState = TBSTATE_ENABLED | TBSTATE_CHECKED;
1161 tbb[index].fsStyle = BTNS_BUTTON;
1162 tbb[index].dwData = 0;
1163 tbb[index++].iString = 0;
1165 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_FITWIDTHS));
1166 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1167 tbb[index].idCommand = ID_VIEW_FITIMAGEWIDTHS;
1168 tbb[index].fsState = TBSTATE_ENABLED;
1169 tbb[index].fsStyle = BTNS_BUTTON;
1170 tbb[index].dwData = 0;
1171 tbb[index++].iString = 0;
1173 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_FITHEIGHTS));
1174 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1175 tbb[index].idCommand = ID_VIEW_FITIMAGEHEIGHTS;
1176 tbb[index].fsState = TBSTATE_ENABLED;
1177 tbb[index].fsStyle = BTNS_BUTTON;
1178 tbb[index].dwData = 0;
1179 tbb[index++].iString = 0;
1181 tbb[index].iBitmap = 0;
1182 tbb[index].idCommand = 0;
1183 tbb[index].fsState = TBSTATE_ENABLED;
1184 tbb[index].fsStyle = BTNS_SEP;
1185 tbb[index].dwData = 0;
1186 tbb[index++].iString = 0;
1188 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_VERTICAL));
1189 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1190 tbb[index].idCommand = ID_VIEW_ARRANGEVERTICAL;
1191 tbb[index].fsState = TBSTATE_ENABLED;
1192 tbb[index].fsStyle = BTNS_BUTTON;
1193 tbb[index].dwData = 0;
1194 tbb[index++].iString = 0;
1196 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_FITINWINDOW));
1197 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1198 tbb[index].idCommand = ID_VIEW_FITIMAGESINWINDOW;
1199 tbb[index].fsState = TBSTATE_ENABLED;
1200 tbb[index].fsStyle = BTNS_BUTTON;
1201 tbb[index].dwData = 0;
1202 tbb[index++].iString = 0;
1204 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_ORIGSIZE));
1205 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1206 tbb[index].idCommand = ID_VIEW_ORININALSIZE;
1207 tbb[index].fsState = TBSTATE_ENABLED;
1208 tbb[index].fsStyle = BTNS_BUTTON;
1209 tbb[index].dwData = 0;
1210 tbb[index++].iString = 0;
1212 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_ZOOMIN));
1213 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1214 tbb[index].idCommand = ID_VIEW_ZOOMIN;
1215 tbb[index].fsState = TBSTATE_ENABLED;
1216 tbb[index].fsStyle = BTNS_BUTTON;
1217 tbb[index].dwData = 0;
1218 tbb[index++].iString = 0;
1220 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_ZOOMOUT));
1221 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1222 tbb[index].idCommand = ID_VIEW_ZOOMOUT;
1223 tbb[index].fsState = TBSTATE_ENABLED;
1224 tbb[index].fsStyle = BTNS_BUTTON;
1225 tbb[index].dwData = 0;
1226 tbb[index++].iString = 0;
1228 tbb[index].iBitmap = 0;
1229 tbb[index].idCommand = 0;
1230 tbb[index].fsState = TBSTATE_ENABLED;
1231 tbb[index].fsStyle = BTNS_SEP;
1232 tbb[index].dwData = 0;
1233 tbb[index++].iString = 0;
1235 hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_IMGINFO));
1236 tbb[index].iBitmap = ImageList_AddIcon(hToolbarImgList, hIcon);
1237 tbb[index].idCommand = ID_VIEW_IMAGEINFO;
1238 tbb[index].fsState = TBSTATE_ENABLED;
1239 tbb[index].fsStyle = BTNS_BUTTON;
1240 tbb[index].dwData = 0;
1241 tbb[index++].iString = 0;
1243 SendMessage(hwndTB, TB_SETIMAGELIST, 0, (LPARAM)hToolbarImgList);
1244 SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM)index, (LPARAM) (LPTBBUTTON) &tbb);
1245 SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);
1246 ShowWindow(hwndTB, SW_SHOW);
1247 return true;
1250 void CMainWindow::SetSelectionImage( FileType ft, const std::wstring& path, const std::wstring& title )
1252 selectionPaths[ft] = path;
1253 selectionTitles[ft] = title;