1 // TortoiseIDiff - an image diff viewer in TortoiseSVN
3 // Copyright (C) 2006-2012 - 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.
22 #include "PicWindow.h"
26 #pragma comment(lib, "Msimg32.lib")
27 #pragma comment(lib, "shell32.lib")
29 bool CPicWindow::RegisterAndCreateWindow(HWND hParent
)
33 // Fill in the window class structure with default parameters
34 wcx
.cbSize
= sizeof(WNDCLASSEX
);
35 wcx
.style
= CS_HREDRAW
| CS_VREDRAW
;
36 wcx
.lpfnWndProc
= CWindow::stWinMsgHandler
;
39 wcx
.hInstance
= hResource
;
40 wcx
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
41 wcx
.lpszClassName
= _T("TortoiseIDiffPicWindow");
42 wcx
.hIcon
= LoadIcon(hResource
, MAKEINTRESOURCE(IDI_TORTOISEIDIFF
));
43 wcx
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
44 wcx
.lpszMenuName
= MAKEINTRESOURCE(IDC_TORTOISEIDIFF
);
45 wcx
.hIconSm
= LoadIcon(wcx
.hInstance
, MAKEINTRESOURCE(IDI_TORTOISEIDIFF
));
47 if (CreateEx(WS_EX_ACCEPTFILES
| WS_EX_CLIENTEDGE
, WS_CHILD
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
, hParent
))
49 ShowWindow(m_hwnd
, SW_SHOW
);
57 void CPicWindow::PositionTrackBar()
61 HWND slider
= m_AlphaSlider
.GetWindow();
62 if ((pSecondPic
)&&(m_blend
== BLEND_ALPHA
))
64 MoveWindow(slider
, 0, rc
.top
-4+SLIDER_WIDTH
, SLIDER_WIDTH
, rc
.bottom
-rc
.top
-SLIDER_WIDTH
+8, true);
65 ShowWindow(slider
, SW_SHOW
);
66 MoveWindow(hwndAlphaToggleBtn
, 0, rc
.top
-4, SLIDER_WIDTH
, SLIDER_WIDTH
, true);
67 ShowWindow(hwndAlphaToggleBtn
, SW_SHOW
);
71 ShowWindow(slider
, SW_HIDE
);
72 ShowWindow(hwndAlphaToggleBtn
, SW_HIDE
);
76 LRESULT CALLBACK
CPicWindow::WinMsgHandler(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
83 // create a slider control
85 ShowWindow(m_AlphaSlider
.GetWindow(), SW_HIDE
);
88 RECT rect
; // for client area coordinates
90 hwndTT
= CreateWindowEx(WS_EX_TOPMOST
,
93 WS_POPUP
| TTS_NOPREFIX
| TTS_ALWAYSTIP
,
110 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
112 ::GetClientRect(hwnd
, &rect
);
114 ti
.cbSize
= sizeof(TOOLINFO
);
115 ti
.uFlags
= TTF_TRACK
| TTF_ABSOLUTE
;
117 ti
.hinst
= hResource
;
119 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
120 // ToolTip control will cover the whole window
121 ti
.rect
.left
= rect
.left
;
122 ti
.rect
.top
= rect
.top
;
123 ti
.rect
.right
= rect
.right
;
124 ti
.rect
.bottom
= rect
.bottom
;
126 SendMessage(hwndTT
, TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
127 SendMessage(hwndTT
, TTM_SETMAXTIPWIDTH
, 0, 600);
128 nHSecondScrollPos
= 0;
129 nVSecondScrollPos
= 0;
134 InvalidateRect(*this, NULL
, FALSE
);
147 if ((pSecondPic
)&&((HWND
)lParam
== m_AlphaSlider
.GetWindow()))
149 if (LOWORD(wParam
) == TB_THUMBTRACK
)
151 // while tracking, only redraw after 50 milliseconds
152 ::SetTimer(*this, TIMER_ALPHASLIDER
, 50, NULL
);
155 SetBlendAlpha(m_blend
, SendMessage(m_AlphaSlider
.GetWindow(), TBM_GETPOS
, 0, 0) / 16.0f
);
159 UINT nPos
= HIWORD(wParam
);
160 bool bForceUpdate
= false;
161 if (LOWORD(wParam
) == SB_THUMBTRACK
|| LOWORD(wParam
) == SB_THUMBPOSITION
)
163 // Get true 32-bit scroll position
165 si
.cbSize
= sizeof(SCROLLINFO
);
166 si
.fMask
= SIF_TRACKPOS
;
167 GetScrollInfo(*this, SB_VERT
, &si
);
172 OnVScroll(LOWORD(wParam
), nPos
);
173 if (bLinkedPositions
)
175 pTheOtherPic
->OnVScroll(LOWORD(wParam
), nPos
);
177 ::UpdateWindow(*pTheOtherPic
);
183 UINT nPos
= HIWORD(wParam
);
184 bool bForceUpdate
= false;
185 if (LOWORD(wParam
) == SB_THUMBTRACK
|| LOWORD(wParam
) == SB_THUMBPOSITION
)
187 // Get true 32-bit scroll position
189 si
.cbSize
= sizeof(SCROLLINFO
);
190 si
.fMask
= SIF_TRACKPOS
;
191 GetScrollInfo(*this, SB_VERT
, &si
);
196 OnHScroll(LOWORD(wParam
), nPos
);
197 if (bLinkedPositions
)
199 pTheOtherPic
->OnHScroll(LOWORD(wParam
), nPos
);
201 ::UpdateWindow(*pTheOtherPic
);
207 OnMouseWheel(GET_KEYSTATE_WPARAM(wParam
), GET_WHEEL_DELTA_WPARAM(wParam
));
209 pTheOtherPic
->OnMouseWheel(GET_KEYSTATE_WPARAM(wParam
), GET_WHEEL_DELTA_WPARAM(wParam
));
214 OnMouseWheel(GET_KEYSTATE_WPARAM(wParam
)|MK_SHIFT
, GET_WHEEL_DELTA_WPARAM(wParam
));
216 pTheOtherPic
->OnMouseWheel(GET_KEYSTATE_WPARAM(wParam
)|MK_SHIFT
, GET_WHEEL_DELTA_WPARAM(wParam
));
221 ptPanStart
.x
= GET_X_LPARAM(lParam
);
222 ptPanStart
.y
= GET_Y_LPARAM(lParam
);
223 startVScrollPos
= nVScrollPos
;
224 startHScrollPos
= nHScrollPos
;
225 startVSecondScrollPos
= nVSecondScrollPos
;
226 startHSecondScrollPos
= nHSecondScrollPos
;
235 SendMessage(hwndTT
, TTM_TRACKACTIVATE
, FALSE
, 0);
239 mevt
.cbSize
= sizeof(TRACKMOUSEEVENT
);
240 mevt
.dwFlags
= TME_LEAVE
;
241 mevt
.dwHoverTime
= HOVER_DEFAULT
;
242 mevt
.hwndTrack
= *this;
243 ::TrackMouseEvent(&mevt
);
244 POINT pt
= {((int)(short)LOWORD(lParam
)), ((int)(short)HIWORD(lParam
))};
245 if (pt
.y
< HEADER_HEIGHT
)
247 ClientToScreen(*this, &pt
);
248 if ((abs(m_lastTTPos
.x
- pt
.x
) > 20)||(abs(m_lastTTPos
.y
- pt
.y
) > 10))
253 SendMessage(hwndTT
, TTM_TRACKPOSITION
, 0, MAKELONG(pt
.x
, pt
.y
));
255 ti
.cbSize
= sizeof(TOOLINFO
);
258 SendMessage(hwndTT
, TTM_TRACKACTIVATE
, TRUE
, (LPARAM
)&ti
);
263 SendMessage(hwndTT
, TTM_TRACKACTIVATE
, FALSE
, 0);
267 if (wParam
& MK_LBUTTON
)
270 int xPos
= GET_X_LPARAM(lParam
);
271 int yPos
= GET_Y_LPARAM(lParam
);
273 if (wParam
& MK_CONTROL
)
275 nHSecondScrollPos
= startHSecondScrollPos
+ (ptPanStart
.x
- xPos
);
276 nVSecondScrollPos
= startVSecondScrollPos
+ (ptPanStart
.y
- yPos
);
278 else if (wParam
& MK_SHIFT
)
280 nHScrollPos
= startHScrollPos
+ (ptPanStart
.x
- xPos
);
281 nVScrollPos
= startVScrollPos
+ (ptPanStart
.y
- yPos
);
285 nHSecondScrollPos
= startHSecondScrollPos
+ (ptPanStart
.x
- xPos
);
286 nVSecondScrollPos
= startVSecondScrollPos
+ (ptPanStart
.y
- yPos
);
287 nHScrollPos
= startHScrollPos
+ (ptPanStart
.x
- xPos
);
288 nVScrollPos
= startVScrollPos
+ (ptPanStart
.y
- yPos
);
291 InvalidateRect(*this, NULL
, TRUE
);
293 if ((bLinkedPositions
)&&((wParam
& MK_SHIFT
)==0))
295 pTheOtherPic
->nHScrollPos
= nHScrollPos
;
296 pTheOtherPic
->nVScrollPos
= nVScrollPos
;
297 pTheOtherPic
->SetupScrollBars();
298 InvalidateRect(*pTheOtherPic
, NULL
, TRUE
);
299 UpdateWindow(*pTheOtherPic
);
306 // we show a hand cursor if the image can be dragged,
307 // and a hand-down cursor if the image is currently dragged
308 if ((*this == (HWND
)wParam
)&&(LOWORD(lParam
)==HTCLIENT
))
311 GetClientRect(&rect
);
312 LONG width
= picture
.m_Width
;
313 LONG height
= picture
.m_Height
;
316 width
= max(width
, pSecondPic
->m_Width
);
317 height
= max(height
, pSecondPic
->m_Height
);
320 if ((GetKeyState(VK_LBUTTON
)&0x8000)||(HIWORD(lParam
) == WM_LBUTTONDOWN
))
322 SetCursor(curHandDown
);
330 return DefWindowProc(hwnd
, uMsg
, wParam
, lParam
);
335 HDROP hDrop
= (HDROP
)wParam
;
336 TCHAR szFileName
[MAX_PATH
];
337 // we only use the first file dropped (if multiple files are dropped)
338 if (DragQueryFile(hDrop
, 0, szFileName
, _countof(szFileName
)))
340 SetPic(szFileName
, _T(""), bMainPic
);
342 InvalidateRect(*this, NULL
, TRUE
);
348 switch (LOWORD(wParam
))
353 if (bLinkedPositions
)
354 pTheOtherPic
->PrevImage();
361 if (bLinkedPositions
)
362 pTheOtherPic
->NextImage();
368 bPlaying
= !bPlaying
;
370 if (bLinkedPositions
)
371 pTheOtherPic
->Animate(bPlaying
);
375 case ALPHATOGGLEBUTTON_ID
:
377 WORD msg
= HIWORD(wParam
);
380 case BN_DOUBLECLICKED
:
382 SendMessage(hwndAlphaToggleBtn
, BM_SETSTATE
, 1, 0);
383 SetTimer(*this, ID_ALPHATOGGLETIMER
, 1000, NULL
);
387 KillTimer(*this, ID_ALPHATOGGLETIMER
);
396 m_blend
= BLEND_ALPHA
;
398 InvalidateRect(*this, NULL
, TRUE
);
405 InvalidateRect(*this, NULL
, TRUE
);
415 case ID_ANIMATIONTIMER
:
418 if (nCurrentFrame
> picture
.GetNumberOfFrames(0))
420 long delay
= picture
.SetActiveFrame(nCurrentFrame
);
421 delay
= max(100, delay
);
422 SetTimer(*this, ID_ANIMATIONTIMER
, delay
, NULL
);
423 InvalidateRect(*this, NULL
, FALSE
);
426 case TIMER_ALPHASLIDER
:
428 SetBlendAlpha(m_blend
, SendMessage(m_AlphaSlider
.GetWindow(), TBM_GETPOS
, 0, 0)/16.0f
);
429 KillTimer(*this, TIMER_ALPHASLIDER
);
432 case ID_ALPHATOGGLETIMER
:
442 LPNMHDR pNMHDR
= (LPNMHDR
)lParam
;
443 if (pNMHDR
->code
== TTN_GETDISPINFO
)
445 if (pNMHDR
->hwndFrom
== m_AlphaSlider
.GetWindow())
447 LPTOOLTIPTEXT lpttt
= (LPTOOLTIPTEXT
) lParam
;
448 lpttt
->hinst
= hResource
;
449 TCHAR stringbuf
[MAX_PATH
] = {0};
450 _stprintf_s(stringbuf
, _T("%i%% alpha"), (int)(SendMessage(m_AlphaSlider
.GetWindow(),TBM_GETPOS
,0,0)/16.0f
*100.0f
));
451 _tcscpy_s(lpttt
->lpszText
, 80, stringbuf
);
453 else if (pNMHDR
->idFrom
== (UINT_PTR
)hwndAlphaToggleBtn
)
455 _stprintf_s(m_wszTip
, (TCHAR
const *)ResString(hResource
, IDS_ALPHABUTTONTT
), (int)(SendMessage(m_AlphaSlider
.GetWindow(),TBM_GETPOS
,0,0)/16.0f
*100.0f
));
456 if (pNMHDR
->code
== TTN_NEEDTEXTW
)
458 NMTTDISPINFOW
* pTTTW
= (NMTTDISPINFOW
*)pNMHDR
;
459 pTTTW
->lpszText
= m_wszTip
;
463 NMTTDISPINFOA
* pTTTA
= (NMTTDISPINFOA
*)pNMHDR
;
464 pTTTA
->lpszText
= m_szTip
;
465 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
470 BuildInfoString(m_wszTip
, _countof(m_wszTip
), true);
471 if (pNMHDR
->code
== TTN_NEEDTEXTW
)
473 NMTTDISPINFOW
* pTTTW
= (NMTTDISPINFOW
*)pNMHDR
;
474 pTTTW
->lpszText
= m_wszTip
;
478 NMTTDISPINFOA
* pTTTA
= (NMTTDISPINFOA
*)pNMHDR
;
479 pTTTA
->lpszText
= m_szTip
;
480 ::WideCharToMultiByte(CP_ACP
, 0, m_wszTip
, -1, m_szTip
, 8192, NULL
, NULL
);
491 bWindowClosed
= TRUE
;
494 return DefWindowProc(hwnd
, uMsg
, wParam
, lParam
);
500 void CPicWindow::NextImage()
503 if (nCurrentDimension
> picture
.GetNumberOfDimensions())
504 nCurrentDimension
= picture
.GetNumberOfDimensions();
506 if (nCurrentFrame
> picture
.GetNumberOfFrames(0))
507 nCurrentFrame
= picture
.GetNumberOfFrames(0);
508 picture
.SetActiveFrame(nCurrentFrame
>= nCurrentDimension
? nCurrentFrame
: nCurrentDimension
);
509 InvalidateRect(*this, NULL
, FALSE
);
513 void CPicWindow::PrevImage()
516 if (nCurrentDimension
< 1)
517 nCurrentDimension
= 1;
519 if (nCurrentFrame
< 1)
521 picture
.SetActiveFrame(nCurrentFrame
>= nCurrentDimension
? nCurrentFrame
: nCurrentDimension
);
522 InvalidateRect(*this, NULL
, FALSE
);
526 void CPicWindow::Animate(bool bStart
)
530 SendMessage(hwndPlayBtn
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hStop
);
531 SetTimer(*this, ID_ANIMATIONTIMER
, 0, NULL
);
535 SendMessage(hwndPlayBtn
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hPlay
);
536 KillTimer(*this, ID_ANIMATIONTIMER
);
540 void CPicWindow::SetPic(tstring path
, tstring title
, bool bFirst
)
543 picpath
=path
;pictitle
=title
;
544 picture
.SetInterpolationMode(InterpolationModeHighQualityBicubic
);
545 bValid
= picture
.Load(picpath
);
546 nDimensions
= picture
.GetNumberOfDimensions();
548 nFrames
= picture
.GetNumberOfFrames(0);
553 InvalidateRect(*this, NULL
, FALSE
);
557 void CPicWindow::DrawViewTitle(HDC hDC
, RECT
* rect
)
560 hFont
= CreateFont(-MulDiv(pSecondPic
? 8 : 10, GetDeviceCaps(hDC
, LOGPIXELSY
), 72), 0, 0, 0, FW_DONTCARE
, false, false, false, ANSI_CHARSET
, OUT_DEFAULT_PRECIS
, CLIP_DEFAULT_PRECIS
, CLEARTYPE_QUALITY
, DEFAULT_PITCH
, _T("MS Shell Dlg"));
561 HFONT hFontOld
= (HFONT
)SelectObject(hDC
, (HGDIOBJ
)hFont
);
564 textrect
.left
= rect
->left
;
565 textrect
.top
= rect
->top
;
566 textrect
.right
= rect
->right
;
567 textrect
.bottom
= rect
->top
+ HEADER_HEIGHT
;
568 if (HasMultipleImages())
569 textrect
.bottom
+= HEADER_HEIGHT
;
572 crBk
= ::GetSysColor(COLOR_SCROLLBAR
);
573 crFg
= ::GetSysColor(COLOR_WINDOWTEXT
);
574 SetBkColor(hDC
, crBk
);
575 ::ExtTextOut(hDC
, 0, 0, ETO_OPAQUE
, &textrect
, NULL
, 0, NULL
);
577 if (GetFocus() == *this)
578 DrawEdge(hDC
, &textrect
, EDGE_BUMP
, BF_RECT
);
580 DrawEdge(hDC
, &textrect
, EDGE_ETCHED
, BF_RECT
);
582 SetTextColor(hDC
, crFg
);
584 // use the path if no title is set.
585 tstring
* title
= pictitle
.empty() ? &picpath
: &pictitle
;
587 tstring realtitle
= *title
;
588 tstring imgnumstring
;
590 if (HasMultipleImages())
594 _stprintf_s(buf
, (const TCHAR
*)ResString(hResource
, IDS_DIMENSIONSANDFRAMES
), nCurrentFrame
, nFrames
);
596 _stprintf_s(buf
, (const TCHAR
*)ResString(hResource
, IDS_DIMENSIONSANDFRAMES
), nCurrentDimension
, nDimensions
);
601 if (GetTextExtentPoint32(hDC
, realtitle
.c_str(), (int)realtitle
.size(), &stringsize
))
603 int nStringLength
= stringsize
.cx
;
604 int texttop
= pSecondPic
? textrect
.top
+ (HEADER_HEIGHT
/2) - stringsize
.cy
: textrect
.top
+ (HEADER_HEIGHT
/2) - stringsize
.cy
/2;
606 max(textrect
.left
+ ((textrect
.right
-textrect
.left
)-nStringLength
)/2, 1),
611 (UINT
)realtitle
.size(),
615 realtitle
= (pictitle2
.empty() ? picpath2
: pictitle2
);
617 max(textrect
.left
+ ((textrect
.right
-textrect
.left
)-nStringLength
)/2, 1),
618 texttop
+ stringsize
.cy
,
622 (UINT
)realtitle
.size(),
626 if (HasMultipleImages())
628 if (GetTextExtentPoint32(hDC
, imgnumstring
.c_str(), (int)imgnumstring
.size(), &stringsize
))
630 int nStringLength
= stringsize
.cx
;
633 max(textrect
.left
+ ((textrect
.right
-textrect
.left
)-nStringLength
)/2, 1),
634 textrect
.top
+ HEADER_HEIGHT
+ (HEADER_HEIGHT
/2) - stringsize
.cy
/2,
637 imgnumstring
.c_str(),
638 (UINT
)imgnumstring
.size(),
642 SelectObject(hDC
, (HGDIOBJ
)hFontOld
);
646 void CPicWindow::SetupScrollBars()
649 GetClientRect(&rect
);
651 SCROLLINFO si
= {sizeof(si
)};
653 si
.fMask
= SIF_POS
| SIF_PAGE
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
655 double width
= double(picture
.m_Width
)*picscale
;
656 double height
= double(picture
.m_Height
)*picscale
;
659 width
= max(width
, double(pSecondPic
->m_Width
)*pTheOtherPic
->GetZoom());
660 height
= max(height
, double(pSecondPic
->m_Height
)*pTheOtherPic
->GetZoom());
663 bool bShowHScrollBar
= (nHScrollPos
> 0); // left of pic is left of window
664 bShowHScrollBar
= bShowHScrollBar
|| (width
-nHScrollPos
> rect
.right
); // right of pic is outside right of window
665 bShowHScrollBar
= bShowHScrollBar
|| (width
+nHScrollPos
> rect
.right
); // right of pic is outside right of window
666 bool bShowVScrollBar
= (nVScrollPos
> 0); // top of pic is above window
667 bShowVScrollBar
= bShowVScrollBar
|| (height
-nVScrollPos
+rect
.top
> rect
.bottom
); // bottom of pic is below window
668 bShowVScrollBar
= bShowVScrollBar
|| (height
+nVScrollPos
+rect
.top
> rect
.bottom
); // bottom of pic is below window
670 // if the image is smaller than the window, we don't need the scrollbars
671 ShowScrollBar(*this, SB_HORZ
, bShowHScrollBar
);
672 ShowScrollBar(*this, SB_VERT
, bShowVScrollBar
);
676 si
.nPos
= nVScrollPos
;
677 si
.nPage
= rect
.bottom
-rect
.top
;
678 if (height
< rect
.bottom
-rect
.top
)
683 si
.nMax
= rect
.bottom
+nVScrollPos
-rect
.top
;
687 si
.nMin
= nVScrollPos
;
688 si
.nMax
= int(height
);
696 si
.nMax
= int(max(height
, rect
.bottom
+nVScrollPos
-rect
.top
));
701 si
.nMax
= int(height
-nVScrollPos
);
704 SetScrollInfo(*this, SB_VERT
, &si
, TRUE
);
709 si
.nPos
= nHScrollPos
;
710 si
.nPage
= rect
.right
-rect
.left
;
711 if (width
< rect
.right
-rect
.left
)
716 si
.nMax
= rect
.right
+nHScrollPos
-rect
.left
;
720 si
.nMin
= nHScrollPos
;
721 si
.nMax
= int(width
);
729 si
.nMax
= int(max(width
, rect
.right
+nHScrollPos
-rect
.left
));
734 si
.nMax
= int(width
-nHScrollPos
);
737 SetScrollInfo(*this, SB_HORZ
, &si
, TRUE
);
743 void CPicWindow::OnVScroll(UINT nSBCode
, UINT nPos
)
746 GetClientRect(&rect
);
751 nVScrollPos
= LONG(double(picture
.GetHeight())*picscale
);
763 nVScrollPos
+= (rect
.bottom
-rect
.top
);
766 nVScrollPos
-= (rect
.bottom
-rect
.top
);
768 case SB_THUMBPOSITION
:
777 LONG height
= LONG(double(picture
.GetHeight())*picscale
);
780 height
= max(height
, LONG(double(pSecondPic
->GetHeight())*picscale
));
781 nVSecondScrollPos
= nVScrollPos
;
785 InvalidateRect(*this, NULL
, TRUE
);
788 void CPicWindow::OnHScroll(UINT nSBCode
, UINT nPos
)
791 GetClientRect(&rect
);
796 nHScrollPos
= LONG(double(picture
.GetWidth())*picscale
);
808 nHScrollPos
+= (rect
.right
-rect
.left
);
811 nHScrollPos
-= (rect
.right
-rect
.left
);
813 case SB_THUMBPOSITION
:
822 LONG width
= LONG(double(picture
.GetWidth())*picscale
);
825 width
= max(width
, LONG(double(pSecondPic
->GetWidth())*picscale
));
826 nHSecondScrollPos
= nHScrollPos
;
830 InvalidateRect(*this, NULL
, TRUE
);
833 void CPicWindow::OnMouseWheel(short fwKeys
, short zDelta
)
836 GetClientRect(&rect
);
837 LONG width
= long(double(picture
.m_Width
)*picscale
);
838 LONG height
= long(double(picture
.m_Height
)*picscale
);
841 width
= max(width
, long(double(pSecondPic
->m_Width
)*picscale
));
842 height
= max(height
, long(double(pSecondPic
->m_Height
)*picscale
));
844 if ((fwKeys
& MK_SHIFT
)&&(fwKeys
& MK_CONTROL
)&&(pSecondPic
))
846 // ctrl+shift+wheel: change the alpha channel
847 float a
= blendAlpha
;
848 a
-= float(zDelta
)/120.0f
/4.0f
;
853 SetBlendAlpha(m_blend
, a
);
855 else if (fwKeys
& MK_SHIFT
)
857 // shift means scrolling sideways
858 OnHScroll(SB_THUMBPOSITION
, GetHPos()-zDelta
);
859 if ((bLinkedPositions
)&&(pTheOtherPic
))
861 pTheOtherPic
->OnHScroll(SB_THUMBPOSITION
, pTheOtherPic
->GetHPos()-zDelta
);
864 else if (fwKeys
& MK_CONTROL
)
866 // control means adjusting the scale factor
867 Zoom(zDelta
>0, true);
868 if ((bFitSizes
)&&(pTheOtherPic
)&&(!bOverlap
))
869 pTheOtherPic
->Zoom(zDelta
>0, true);
871 InvalidateRect(*this, NULL
, FALSE
);
872 SetWindowPos(*this, NULL
, 0, 0, 0, 0, SWP_FRAMECHANGED
|SWP_NOSIZE
|SWP_NOREPOSITION
|SWP_NOMOVE
);
876 OnVScroll(SB_THUMBPOSITION
, GetVPos()-zDelta
);
877 if ((bLinkedPositions
)&&(pTheOtherPic
))
879 pTheOtherPic
->OnVScroll(SB_THUMBPOSITION
, pTheOtherPic
->GetVPos()-zDelta
);
884 void CPicWindow::GetClientRect(RECT
* pRect
)
886 ::GetClientRect(*this, pRect
);
887 pRect
->top
+= HEADER_HEIGHT
;
888 if (HasMultipleImages())
890 pRect
->top
+= HEADER_HEIGHT
;
893 pRect
->left
+= SLIDER_WIDTH
;
896 void CPicWindow::GetClientRectWithScrollbars(RECT
* pRect
)
898 GetClientRect(pRect
);
899 ::GetWindowRect(*this, pRect
);
900 pRect
->right
= pRect
->right
-pRect
->left
;
901 pRect
->bottom
= pRect
->bottom
-pRect
->top
;
904 pRect
->top
+= HEADER_HEIGHT
;
905 if (HasMultipleImages())
907 pRect
->top
+= HEADER_HEIGHT
;
910 pRect
->left
+= SLIDER_WIDTH
;
914 void CPicWindow::SetZoom(double dZoom
, bool centermouse
)
916 // Set the interpolation mode depending on zoom
917 double oldPicscale
= picscale
;
918 double oldOtherPicscale
= picscale
;
920 { // Zoomed out, use high quality bicubic
921 picture
.SetInterpolationMode(InterpolationModeHighQualityBicubic
);
923 pSecondPic
->SetInterpolationMode(InterpolationModeHighQualityBicubic
);
925 else if (!((int)(dZoom
*100.0)%100))
926 { // "Even" zoom sizes should be shown w-o any interpolation
927 picture
.SetInterpolationMode(InterpolationModeNearestNeighbor
);
929 pSecondPic
->SetInterpolationMode(InterpolationModeNearestNeighbor
);
932 { // Arbitrary zoomed in, use bilinear that is semi-smoothed
933 picture
.SetInterpolationMode(InterpolationModeBilinear
);
935 pSecondPic
->SetInterpolationMode(InterpolationModeBilinear
);
939 if ((bFitSizes
)&&(bMainPic
))
941 double width
, height
;
942 double zoomWidth
, zoomHeight
;
943 width
= double(picture
.m_Width
)*dZoom
;
944 height
= double(picture
.m_Height
)*dZoom
;
945 zoomWidth
= width
/double(pTheOtherPic
->GetPic()->m_Width
);
946 zoomHeight
= height
/double(pTheOtherPic
->GetPic()->m_Height
);
947 oldOtherPicscale
= pTheOtherPic
->GetZoom();
948 pTheOtherPic
->SetZoom(min(zoomWidth
, zoomHeight
), false);
951 // adjust the scrollbar positions according to the new zoom and the
952 // mouse position: if possible, keep the pixel where the mouse pointer
953 // is at the same position after the zoom
955 DWORD ptW
= GetMessagePos();
956 cpos
.x
= GET_X_LPARAM(ptW
);
957 cpos
.y
= GET_Y_LPARAM(ptW
);
958 ScreenToClient(*this, &cpos
);
960 GetClientRect(&clientrect
);
961 if ((PtInRect(&clientrect
, cpos
))&&(centermouse
))
963 // the mouse pointer is over our window
964 nHScrollPos
= int(double(nHScrollPos
+ cpos
.x
)*(dZoom
/oldPicscale
))-cpos
.x
;
965 nVScrollPos
= int(double(nVScrollPos
+ cpos
.y
)*(dZoom
/oldPicscale
))-cpos
.y
;
966 if (pTheOtherPic
&& bMainPic
)
968 double otherzoom
= pTheOtherPic
->GetZoom();
969 nHSecondScrollPos
= int(double(nHSecondScrollPos
+ cpos
.x
)*(otherzoom
/oldOtherPicscale
))-cpos
.x
;
970 nVSecondScrollPos
= int(double(nVSecondScrollPos
+ cpos
.y
)*(otherzoom
/oldOtherPicscale
))-cpos
.y
;
975 nHScrollPos
= int(double(nHScrollPos
+ ((clientrect
.right
-clientrect
.left
)/2))*(dZoom
/oldPicscale
))-((clientrect
.right
-clientrect
.left
)/2);
976 nVScrollPos
= int(double(nVScrollPos
+ ((clientrect
.bottom
-clientrect
.top
)/2))*(dZoom
/oldPicscale
))-((clientrect
.bottom
-clientrect
.top
)/2);
977 if (pTheOtherPic
&& bMainPic
)
979 double otherzoom
= pTheOtherPic
->GetZoom();
980 nHSecondScrollPos
= int(double(nHSecondScrollPos
+ ((clientrect
.right
-clientrect
.left
)/2))*(otherzoom
/oldOtherPicscale
))-((clientrect
.right
-clientrect
.left
)/2);
981 nVSecondScrollPos
= int(double(nVSecondScrollPos
+ ((clientrect
.bottom
-clientrect
.top
)/2))*(otherzoom
/oldOtherPicscale
))-((clientrect
.bottom
-clientrect
.top
)/2);
987 InvalidateRect(*this, NULL
, TRUE
);
990 void CPicWindow::Zoom(bool in
, bool centermouse
)
994 // Find correct zoom factor and quantize picscale
995 if (!in
&& picscale
<= 0.2)
1000 else if ((in
&& picscale
< 1.0) || (!in
&& picscale
<= 1.0))
1002 picscale
= 0.1 * RoundDouble(picscale
/0.1, 0); // Quantize to 0.1
1005 else if ((in
&& picscale
< 2.0) || (!in
&& picscale
<= 2.0))
1007 picscale
= 0.25 * RoundDouble(picscale
/0.25, 0); // Quantize to 0.25
1012 picscale
= RoundDouble(picscale
,0);
1019 if ((pSecondPic
)&&(!bFitSizes
))
1020 pTheOtherPic
->SetZoom(pTheOtherPic
->GetZoom()+zoomFactor
, false);
1021 SetZoom(picscale
+zoomFactor
, centermouse
);
1025 if ((pSecondPic
)&&(!bFitSizes
))
1026 pTheOtherPic
->SetZoom(pTheOtherPic
->GetZoom()-zoomFactor
, false);
1027 SetZoom(picscale
-zoomFactor
, centermouse
);
1031 double CPicWindow::RoundDouble(double doValue
, int nPrecision
)
1033 static const double doBase
= 10.0;
1034 double doComplete5
, doComplete5i
;
1036 doComplete5
= doValue
* pow(doBase
, (double) (nPrecision
+ 1));
1047 doComplete5
/= doBase
;
1048 modf(doComplete5
, &doComplete5i
);
1050 return doComplete5i
/ pow(doBase
, (double) nPrecision
);
1052 void CPicWindow::FitImageInWindow()
1056 GetClientRectWithScrollbars(&rect
);
1058 if (rect
.right
-rect
.left
)
1061 if (((rect
.right
- rect
.left
) > picture
.m_Width
+2)&&((rect
.bottom
- rect
.top
)> picture
.m_Height
+2))
1063 // image is smaller than the window
1068 // image is bigger than the window
1069 double xscale
= double(rect
.right
-rect
.left
-2)/double(picture
.m_Width
);
1070 double yscale
= double(rect
.bottom
-rect
.top
-2)/double(picture
.m_Height
);
1071 dZoom
= min(yscale
, xscale
);
1075 if (((rect
.right
- rect
.left
) > pSecondPic
->m_Width
+2)&&((rect
.bottom
- rect
.top
)> pSecondPic
->m_Height
+2))
1077 // image is smaller than the window
1078 pTheOtherPic
->SetZoom(min(1.0, dZoom
), false);
1082 // image is bigger than the window
1083 double xscale
= double(rect
.right
-rect
.left
-2)/double(pSecondPic
->m_Width
);
1084 double yscale
= double(rect
.bottom
-rect
.top
-2)/double(pSecondPic
->m_Height
);
1085 pTheOtherPic
->SetZoom(min(yscale
, xscale
), false);
1087 nHSecondScrollPos
= 0;
1088 nVSecondScrollPos
= 0;
1090 SetZoom(dZoom
, false);
1094 InvalidateRect(*this, NULL
, TRUE
);
1097 void CPicWindow::CenterImage()
1100 GetClientRectWithScrollbars(&rect
);
1101 double width
= (double(picture
.m_Width
)*picscale
) + 2.0;
1102 double height
= (double(picture
.m_Height
)*picscale
) + 2.0;
1105 width
= max(width
, (double(pSecondPic
->m_Width
)*pTheOtherPic
->GetZoom()) + 2.0);
1106 height
= max(height
, (double(pSecondPic
->m_Height
)*pTheOtherPic
->GetZoom()) + 2.0);
1109 bool bPicWidthBigger
= (int(width
) > (rect
.right
-rect
.left
));
1110 bool bPicHeightBigger
= (int(height
) > (rect
.bottom
-rect
.top
));
1111 // set the scroll position so that the image is drawn centered in the window
1112 // if the window is bigger than the image
1113 if (!bPicWidthBigger
)
1115 nHScrollPos
= -((rect
.right
-rect
.left
+4)-int(width
))/2;
1116 nHSecondScrollPos
= nHScrollPos
;
1118 if (!bPicHeightBigger
)
1120 nVScrollPos
= -((rect
.bottom
-rect
.top
+4)-int(height
))/2;
1121 nVSecondScrollPos
= nVScrollPos
;
1126 void CPicWindow::FitSizes(bool bFit
)
1130 SetZoom(GetZoom(), false);
1133 void CPicWindow::ShowPicWithBorder(HDC hdc
, const RECT
&bounds
, CPicture
&pic
, double scale
)
1135 ::SetBkColor(hdc
, transparentColor
);
1136 ::ExtTextOut(hdc
, 0, 0, ETO_OPAQUE
, &bounds
, NULL
, 0, NULL
);
1139 picrect
.left
= bounds
.left
- nHScrollPos
;
1140 picrect
.top
= bounds
.top
- nVScrollPos
;
1141 if ((!bLinkedPositions
|| bOverlap
) && (pTheOtherPic
) && (&pic
!= &picture
))
1143 picrect
.left
= bounds
.left
- nHSecondScrollPos
;
1144 picrect
.top
= bounds
.top
- nVSecondScrollPos
;
1146 picrect
.right
= (picrect
.left
+ LONG(double(pic
.m_Width
) * scale
));
1147 picrect
.bottom
= (picrect
.top
+ LONG(double(pic
.m_Height
) * scale
));
1149 pic
.Show(hdc
, picrect
);
1152 border
.left
= picrect
.left
-1;
1153 border
.top
= picrect
.top
-1;
1154 border
.right
= picrect
.right
+1;
1155 border
.bottom
= picrect
.bottom
+1;
1157 HPEN hPen
= CreatePen(PS_SOLID
, 1, GetSysColor(COLOR_3DDKSHADOW
));
1158 HPEN hOldPen
= (HPEN
)SelectObject(hdc
, hPen
);
1159 MoveToEx(hdc
, border
.left
, border
.top
, NULL
);
1160 LineTo(hdc
, border
.left
, border
.bottom
);
1161 LineTo(hdc
, border
.right
, border
.bottom
);
1162 LineTo(hdc
, border
.right
, border
.top
);
1163 LineTo(hdc
, border
.left
, border
.top
);
1164 SelectObject(hdc
, hOldPen
);
1168 void CPicWindow::Paint(HWND hwnd
)
1172 RECT rect
, fullrect
;
1174 GetUpdateRect(hwnd
, &rect
, FALSE
);
1175 if (IsRectEmpty(&rect
))
1178 ::GetClientRect(*this, &fullrect
);
1179 hdc
= BeginPaint(hwnd
, &ps
);
1181 // Exclude the alpha control and button
1182 if ((pSecondPic
)&&(m_blend
== BLEND_ALPHA
))
1183 ExcludeClipRect(hdc
, 0, m_inforect
.top
-4, SLIDER_WIDTH
, m_inforect
.bottom
+4);
1185 CMyMemDC
memDC(hdc
);
1186 if ((pSecondPic
)&&(m_blend
!= BLEND_ALPHA
))
1188 // erase the place where the alpha slider would be
1189 ::SetBkColor(memDC
, transparentColor
);
1190 RECT bounds
= {0, m_inforect
.top
-4, SLIDER_WIDTH
, m_inforect
.bottom
+4};
1191 ::ExtTextOut(memDC
, 0, 0, ETO_OPAQUE
, &bounds
, NULL
, 0, NULL
);
1194 GetClientRect(&rect
);
1197 ShowPicWithBorder(memDC
, rect
, picture
, picscale
);
1200 HDC secondhdc
= CreateCompatibleDC(hdc
);
1201 HBITMAP hBitmap
= CreateCompatibleBitmap(hdc
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
1202 HBITMAP hOldBitmap
= (HBITMAP
)SelectObject(secondhdc
, hBitmap
);
1203 SetWindowOrgEx(secondhdc
, rect
.left
, rect
.top
, NULL
);
1205 if ((pSecondPic
)&&(m_blend
!= BLEND_ALPHA
))
1207 // erase the place where the alpha slider would be
1208 ::SetBkColor(secondhdc
, transparentColor
);
1209 RECT bounds
= {0, m_inforect
.top
-4, SLIDER_WIDTH
, m_inforect
.bottom
+4};
1210 ::ExtTextOut(secondhdc
, 0, 0, ETO_OPAQUE
, &bounds
, NULL
, 0, NULL
);
1212 ShowPicWithBorder(secondhdc
, rect
, *pSecondPic
, pTheOtherPic
->GetZoom());
1214 if (m_blend
== BLEND_ALPHA
)
1216 BLENDFUNCTION blender
;
1217 blender
.AlphaFormat
= 0;
1218 blender
.BlendFlags
= 0;
1219 blender
.BlendOp
= AC_SRC_OVER
;
1220 blender
.SourceConstantAlpha
= (BYTE
)(blendAlpha
*255);
1224 rect
.right
-rect
.left
,
1225 rect
.bottom
-rect
.top
,
1229 rect
.right
-rect
.left
,
1230 rect
.bottom
-rect
.top
,
1233 else if (m_blend
== BLEND_XOR
)
1238 rect
.right
-rect
.left
,
1239 rect
.bottom
-rect
.top
,
1243 //rect.right-rect.left,
1244 //rect.bottom-rect.top,
1246 InvertRect(memDC
, &rect
);
1248 SelectObject(secondhdc
, hOldBitmap
);
1249 DeleteObject(hBitmap
);
1250 DeleteDC(secondhdc
);
1252 int sliderwidth
= 0;
1253 if ((pSecondPic
)&&(m_blend
== BLEND_ALPHA
))
1254 sliderwidth
= SLIDER_WIDTH
;
1255 m_inforect
.left
= rect
.left
+4+sliderwidth
;
1256 m_inforect
.top
= rect
.top
;
1257 m_inforect
.right
= rect
.right
+sliderwidth
;
1258 m_inforect
.bottom
= rect
.bottom
;
1260 SetBkColor(memDC
, transparentColor
);
1263 TCHAR infostring
[8192];
1264 BuildInfoString(infostring
, _countof(infostring
), false);
1266 NONCLIENTMETRICS metrics
= {0};
1267 metrics
.cbSize
= sizeof(NONCLIENTMETRICS
);
1269 #if (WINVER >= 0x600)
1270 if (!SysInfo::Instance().IsVistaOrLater())
1272 metrics
.cbSize
-= sizeof(int); // subtract the size of the iPaddedBorderWidth member which is not available on XP
1276 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &metrics
, FALSE
);
1277 HFONT hFont
= CreateFontIndirect(&metrics
.lfStatusFont
);
1278 HFONT hFontOld
= (HFONT
)SelectObject(memDC
, (HGDIOBJ
)hFont
);
1279 // find out how big the rectangle for the text has to be
1280 DrawText(memDC
, infostring
, -1, &m_inforect
, DT_EDITCONTROL
| DT_EXPANDTABS
| DT_LEFT
| DT_VCENTER
| DT_CALCRECT
);
1282 // the text should be drawn with a four pixel offset to the window borders
1283 m_inforect
.top
= rect
.bottom
- (m_inforect
.bottom
-m_inforect
.top
) - 4;
1284 m_inforect
.bottom
= rect
.bottom
-4;
1286 // first draw an edge rectangle
1288 edgerect
.left
= m_inforect
.left
-4;
1289 edgerect
.top
= m_inforect
.top
-4;
1290 edgerect
.right
= m_inforect
.right
+4;
1291 edgerect
.bottom
= m_inforect
.bottom
+4;
1292 ::ExtTextOut(memDC
, 0, 0, ETO_OPAQUE
, &edgerect
, NULL
, 0, NULL
);
1293 DrawEdge(memDC
, &edgerect
, EDGE_BUMP
, BF_RECT
| BF_SOFT
);
1295 SetTextColor(memDC
, GetSysColor(COLOR_WINDOWTEXT
));
1296 DrawText(memDC
, infostring
, -1, &m_inforect
, DT_EDITCONTROL
| DT_EXPANDTABS
| DT_LEFT
| DT_VCENTER
);
1297 SelectObject(memDC
, (HGDIOBJ
)hFontOld
);
1298 DeleteObject(hFont
);
1303 SetBkColor(memDC
, ::GetSysColor(COLOR_WINDOW
));
1304 ::ExtTextOut(memDC
, 0, 0, ETO_OPAQUE
, &rect
, NULL
, 0, NULL
);
1306 ResString str
= ResString(hResource
, IDS_INVALIDIMAGEINFO
);
1309 NONCLIENTMETRICS metrics
= {0};
1310 metrics
.cbSize
= sizeof(NONCLIENTMETRICS
);
1311 #if (WINVER >= 0x600)
1312 if (!SysInfo::Instance().IsVistaOrLater())
1314 metrics
.cbSize
-= sizeof(int); // subtract the size of the iPaddedBorderWidth member which is not available on XP
1317 SystemParametersInfo(SPI_GETNONCLIENTMETRICS
, 0, &metrics
, FALSE
);
1318 HFONT hFont
= CreateFontIndirect(&metrics
.lfStatusFont
);
1319 HFONT hFontOld
= (HFONT
)SelectObject(memDC
, (HGDIOBJ
)hFont
);
1321 if (GetTextExtentPoint32(memDC
, str
, (int)_tcslen(str
), &stringsize
))
1323 int nStringLength
= stringsize
.cx
;
1326 max(rect
.left
+ ((rect
.right
-rect
.left
)-nStringLength
)/2, 1),
1327 rect
.top
+ ((rect
.bottom
-rect
.top
) - stringsize
.cy
)/2,
1334 SelectObject(memDC
, (HGDIOBJ
)hFontOld
);
1335 DeleteObject(hFont
);
1337 DrawViewTitle(memDC
, &fullrect
);
1339 EndPaint(hwnd
, &ps
);
1342 bool CPicWindow::CreateButtons()
1344 // Ensure that the common control DLL is loaded.
1345 INITCOMMONCONTROLSEX icex
;
1346 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1347 icex
.dwICC
= ICC_BAR_CLASSES
| ICC_WIN95_CLASSES
;
1348 InitCommonControlsEx(&icex
);
1350 hwndLeftBtn
= CreateWindowEx(0,
1353 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_ICON
| BS_FLAT
,
1356 (HMENU
)LEFTBUTTON_ID
,
1359 if (hwndLeftBtn
== INVALID_HANDLE_VALUE
)
1361 hLeft
= (HICON
)LoadImage(hResource
, MAKEINTRESOURCE(IDI_BACKWARD
), IMAGE_ICON
, 16, 16, LR_LOADTRANSPARENT
);
1362 SendMessage(hwndLeftBtn
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hLeft
);
1363 hwndRightBtn
= CreateWindowEx(0,
1366 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_ICON
| BS_FLAT
,
1369 (HMENU
)RIGHTBUTTON_ID
,
1372 if (hwndRightBtn
== INVALID_HANDLE_VALUE
)
1374 hRight
= (HICON
)LoadImage(hResource
, MAKEINTRESOURCE(IDI_FORWARD
), IMAGE_ICON
, 16, 16, LR_LOADTRANSPARENT
);
1375 SendMessage(hwndRightBtn
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hRight
);
1376 hwndPlayBtn
= CreateWindowEx(0,
1379 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_ICON
| BS_FLAT
,
1382 (HMENU
)PLAYBUTTON_ID
,
1385 if (hwndPlayBtn
== INVALID_HANDLE_VALUE
)
1387 hPlay
= (HICON
)LoadImage(hResource
, MAKEINTRESOURCE(IDI_START
), IMAGE_ICON
, 16, 16, LR_LOADTRANSPARENT
);
1388 hStop
= (HICON
)LoadImage(hResource
, MAKEINTRESOURCE(IDI_STOP
), IMAGE_ICON
, 16, 16, LR_LOADTRANSPARENT
);
1389 SendMessage(hwndPlayBtn
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hPlay
);
1390 hwndAlphaToggleBtn
= CreateWindowEx(0,
1393 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
| BS_ICON
| BS_FLAT
| BS_NOTIFY
| BS_PUSHLIKE
,
1396 (HMENU
)ALPHATOGGLEBUTTON_ID
,
1399 if (hwndAlphaToggleBtn
== INVALID_HANDLE_VALUE
)
1401 hAlphaToggle
= (HICON
)LoadImage(hResource
, MAKEINTRESOURCE(IDI_ALPHATOGGLE
), IMAGE_ICON
, 16, 16, LR_LOADTRANSPARENT
);
1402 SendMessage(hwndAlphaToggleBtn
, BM_SETIMAGE
, (WPARAM
)IMAGE_ICON
, (LPARAM
)hAlphaToggle
);
1405 ti
.cbSize
= sizeof(TOOLINFO
);
1406 ti
.uFlags
= TTF_IDISHWND
|TTF_SUBCLASS
;
1408 ti
.hinst
= hResource
;
1409 ti
.uId
= (UINT_PTR
)hwndAlphaToggleBtn
;
1410 ti
.lpszText
= LPSTR_TEXTCALLBACK
;
1411 // ToolTip control will cover the whole window
1416 SendMessage(hwndTT
, TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
1421 void CPicWindow::PositionChildren()
1424 ::GetClientRect(*this, &rect
);
1425 if (HasMultipleImages())
1427 SetWindowPos(hwndLeftBtn
, HWND_TOP
, rect
.left
+3, rect
.top
+ HEADER_HEIGHT
+ (HEADER_HEIGHT
-16)/2, 16, 16, SWP_FRAMECHANGED
|SWP_SHOWWINDOW
);
1428 SetWindowPos(hwndRightBtn
, HWND_TOP
, rect
.left
+23, rect
.top
+ HEADER_HEIGHT
+ (HEADER_HEIGHT
-16)/2, 16, 16, SWP_FRAMECHANGED
|SWP_SHOWWINDOW
);
1430 SetWindowPos(hwndPlayBtn
, HWND_TOP
, rect
.left
+43, rect
.top
+ HEADER_HEIGHT
+ (HEADER_HEIGHT
-16)/2, 16, 16, SWP_FRAMECHANGED
|SWP_SHOWWINDOW
);
1432 ShowWindow(hwndPlayBtn
, SW_HIDE
);
1436 ShowWindow(hwndLeftBtn
, SW_HIDE
);
1437 ShowWindow(hwndRightBtn
, SW_HIDE
);
1438 ShowWindow(hwndPlayBtn
, SW_HIDE
);
1443 bool CPicWindow::HasMultipleImages()
1445 return (((nDimensions
> 1)||(nFrames
> 1))&&(pSecondPic
== NULL
));
1448 void CPicWindow::CreateTrackbar(HWND hwndParent
)
1450 HWND hwndTrack
= CreateWindowEx(
1451 0, // no extended styles
1452 TRACKBAR_CLASS
, // class name
1453 _T("Trackbar Control"), // title (caption)
1454 WS_CHILD
| WS_VISIBLE
| TBS_VERT
| TBS_TOOLTIPS
| TBS_AUTOTICKS
, // style
1457 hwndParent
, // parent window
1458 (HMENU
)TRACKBAR_ID
, // control identifier
1460 NULL
// no WM_CREATE parameter
1463 SendMessage(hwndTrack
, TBM_SETRANGE
,
1464 (WPARAM
) TRUE
, // redraw flag
1465 (LPARAM
) MAKELONG(0, 16)); // min. & max. positions
1466 SendMessage(hwndTrack
, TBM_SETTIPSIDE
,
1470 m_AlphaSlider
.ConvertTrackbarToNice(hwndTrack
);
1473 void CPicWindow::BuildInfoString(TCHAR
* buf
, int size
, bool bTooltip
)
1475 // Unfortunately, we need two different strings for the tooltip
1476 // and the info box. Because the tooltips use a different tab size
1477 // than ExtTextOut(), and to keep the output aligned we therefore
1478 // need two different strings.
1479 // Note: some translations could end up with two identical strings, but
1480 // in English we need two - even if we wouldn't need two in English, some
1481 // translation might then need two again.
1484 _stprintf_s(buf
, size
,
1485 (TCHAR
const *)ResString(hResource
, bTooltip
? IDS_DUALIMAGEINFOTT
: IDS_DUALIMAGEINFO
),
1486 picture
.GetFileSizeAsText().c_str(), picture
.GetFileSizeAsText(false).c_str(),
1487 picture
.m_Width
, picture
.m_Height
,
1488 picture
.GetHorizontalResolution(), picture
.GetVerticalResolution(),
1489 picture
.m_ColorDepth
,
1490 (UINT
)(GetZoom()*100.0),
1491 pSecondPic
->GetFileSizeAsText().c_str(), pSecondPic
->GetFileSizeAsText(false).c_str(),
1492 pSecondPic
->m_Width
, pSecondPic
->m_Height
,
1493 pSecondPic
->GetHorizontalResolution(), pSecondPic
->GetVerticalResolution(),
1494 pSecondPic
->m_ColorDepth
,
1495 (UINT
)(pTheOtherPic
->GetZoom()*100.0));
1499 _stprintf_s(buf
, size
,
1500 (TCHAR
const *)ResString(hResource
, bTooltip
? IDS_IMAGEINFOTT
: IDS_IMAGEINFO
),
1501 picture
.GetFileSizeAsText().c_str(), picture
.GetFileSizeAsText(false).c_str(),
1502 picture
.m_Width
, picture
.m_Height
,
1503 picture
.GetHorizontalResolution(), picture
.GetVerticalResolution(),
1504 picture
.m_ColorDepth
,
1505 (UINT
)(GetZoom()*100.0));