forked from irwir/eMule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuddyButton.cpp
123 lines (106 loc) · 4.07 KB
/
BuddyButton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// Based on idea from http://www.gipsysoft.com/articles/BuddyButton/
#include "stdafx.h"
#include "emule.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static LPCTSTR s_szPropOldWndProc = _T("PropBuddyButtonOldWndProc");
static LPCTSTR s_szPropBuddyData = _T("PropBuddyButtonData");
struct SBuddyData
{
UINT m_uButtonWidth;
HWND m_hwndButton;
};
static LRESULT CALLBACK BuddyButtonSubClassedProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
WNDPROC pfnOldWndProc = (WNDPROC)GetProp(hWnd, s_szPropOldWndProc);
ASSERT( pfnOldWndProc != NULL );
SBuddyData *pBuddyData = (SBuddyData *)GetProp(hWnd, s_szPropBuddyData);
ASSERT( pBuddyData != NULL );
switch (uMessage)
{
case WM_NCDESTROY:
SetWindowLong(hWnd, GWL_WNDPROC, (LONG)pfnOldWndProc);
VERIFY( RemoveProp(hWnd, s_szPropOldWndProc) != NULL );
VERIFY( RemoveProp(hWnd, s_szPropBuddyData) != NULL );
delete pBuddyData;
break;
case WM_NCHITTEST: {
LRESULT lResult = CallWindowProc(pfnOldWndProc, hWnd, uMessage, wParam, lParam);
if (lResult == HTNOWHERE)
lResult = HTTRANSPARENT;
return lResult;
}
case WM_NCCALCSIZE: {
LRESULT lResult = CallWindowProc(pfnOldWndProc, hWnd, uMessage, wParam, lParam);
LPNCCALCSIZE_PARAMS lpNCCS = (LPNCCALCSIZE_PARAMS)lParam;
lpNCCS->rgrc[0].right -= pBuddyData->m_uButtonWidth;
return lResult;
}
case WM_SIZE: {
CRect rc;
GetClientRect(hWnd, rc);
rc.left = rc.right;
rc.right = rc.left + pBuddyData->m_uButtonWidth;
MapWindowPoints(hWnd, GetParent(hWnd), (LPPOINT)&rc, 2);
SetWindowPos(pBuddyData->m_hwndButton, NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER);
break;
}
}
return CallWindowProc(pfnOldWndProc, hWnd, uMessage, wParam, lParam);
}
void AddBuddyButton(HWND hwndEdit, HWND hwndButton)
{
FARPROC lpfnOldWndProc = (FARPROC)SetWindowLong(hwndEdit, GWL_WNDPROC, (LONG)BuddyButtonSubClassedProc);
ASSERT( lpfnOldWndProc != NULL );
VERIFY( SetProp(hwndEdit, s_szPropOldWndProc, (HANDLE)lpfnOldWndProc) );
// Remove the 'flat' style which my have been set by 'InitWindowStyles'
DWORD dwButtonStyle = (DWORD)GetWindowLong(hwndButton, GWL_STYLE);
if (dwButtonStyle & BS_FLAT)
SetWindowLong(hwndButton, GWL_STYLE, dwButtonStyle & ~BS_FLAT);
CRect rcButton;
GetWindowRect(hwndButton, rcButton);
SBuddyData *pBuddyData = new SBuddyData;
pBuddyData->m_uButtonWidth = rcButton.Width();
pBuddyData->m_hwndButton = hwndButton;
VERIFY( SetProp(hwndEdit, s_szPropBuddyData, (HANDLE)pBuddyData) );
SetWindowPos(hwndEdit, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
bool InitAttachedBrowseButton(HWND hwndButton, HICON &ricoBrowse)
{
// Showing an icon button works for all Windows versions *except* Windows XP w/ active styles
if (theApp.IsXPThemeActive())
return false;
// However, do not stress system resources for non-NT systems.
if (afxIsWin95())
return false;
if (ricoBrowse == NULL)
{
ricoBrowse = theApp.LoadIcon(_T("BrowseFolderSmall"));
if (ricoBrowse == NULL)
return false;
}
DWORD dwStyle = (DWORD)GetWindowLong(hwndButton, GWL_STYLE);
SetWindowLong(hwndButton, GWL_STYLE, dwStyle | BS_ICON);
SendMessage(hwndButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)ricoBrowse);
return true;
}