| 1 |
//////////////////////////////////////////////////////////////////////////////// |
| 2 |
// |
| 3 |
// Copyright 2016 RWS Inc, All Rights Reserved |
| 4 |
// |
| 5 |
// This program is free software; you can redistribute it and/or modify |
| 6 |
// it under the terms of version 2 of the GNU General Public License as published by |
| 7 |
// the Free Software Foundation |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this program; if not, write to the Free Software Foundation, Inc., |
| 16 |
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 |
// |
| 18 |
/////////////////////////////////////////////////////////////////////////////// |
| 19 |
// MFCool.CPP |
| 20 |
// |
| 21 |
// 04/10/96 JMI Started. |
| 22 |
// |
| 23 |
/////////////////////////////////////////////////////////////////////////////// |
| 24 |
// |
| 25 |
// Cool stuff for MFC. |
| 26 |
// |
| 27 |
/////////////////////////////////////////////////////////////////////////////// |
| 28 |
|
| 29 |
/////////////////////////////////////////////////////////////////////////////// |
| 30 |
// Includes. |
| 31 |
/////////////////////////////////////////////////////////////////////////////// |
| 32 |
#include "stdafx.h" |
| 33 |
#include "MFC_CNTL/MFCool.h" |
| 34 |
|
| 35 |
/////////////////////////////////////////////////////////////////////////////// |
| 36 |
// Internal functions. |
| 37 |
/////////////////////////////////////////////////////////////////////////////// |
| 38 |
static BOOL CALLBACK EnumChildIconizeProc(HWND hWnd, int32_t) |
| 39 |
{ |
| 40 |
BOOL bRes = TRUE; // Assume we will continue enumeration. |
| 41 |
|
| 42 |
// Get class name . . . |
| 43 |
char szName[256]; |
| 44 |
if (GetClassName(hWnd, szName, sizeof(szName)) > 0) |
| 45 |
{ |
| 46 |
// If it is a button . . . |
| 47 |
if (stricmp(szName, "BUTTON") == 0) |
| 48 |
{ |
| 49 |
// If it is an icon button . . . |
| 50 |
if ((GetWindowLong(hWnd, GWL_STYLE) & BS_ICON) > 0) |
| 51 |
{ |
| 52 |
// Get the button text . . . |
| 53 |
if (GetWindowText(hWnd, szName, sizeof(szName)) > 0) |
| 54 |
{ |
| 55 |
// Get the icon . . . |
| 56 |
HICON hIcon = LoadIcon(AfxGetResourceHandle(), szName); |
| 57 |
if (hIcon != NULL) |
| 58 |
{ |
| 59 |
// Set the icon. |
| 60 |
SendMessage(hWnd, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon); |
| 61 |
} |
| 62 |
else |
| 63 |
{ |
| 64 |
TRACE("EnumChildIconizeProc(): LoadIcon failed.\n"); |
| 65 |
} |
| 66 |
} |
| 67 |
else |
| 68 |
{ |
| 69 |
TRACE("EnumChildIconizeProc(): GetWindowText failed.\n"); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
TRACE("EnumChildIconizeProc(): Unable to get class name.\n"); |
| 77 |
} |
| 78 |
|
| 79 |
return bRes; |
| 80 |
} |
| 81 |
|
| 82 |
/////////////////////////////////////////////////////////////////////////////// |
| 83 |
// External functions. |
| 84 |
/////////////////////////////////////////////////////////////////////////////// |
| 85 |
|
| 86 |
/////////////////////////////////////////////////////////////////////////////// |
| 87 |
// |
| 88 |
// Associates all icon style buttons that are children of pdlg with the icon |
| 89 |
// specified by the window text of that button. |
| 90 |
// Returns 0 on success. |
| 91 |
// |
| 92 |
/////////////////////////////////////////////////////////////////////////////// |
| 93 |
extern int16_t Iconize(CDialog* pdlg) |
| 94 |
{ |
| 95 |
int16_t sRes = 0; // Assume success. |
| 96 |
|
| 97 |
if (EnumChildWindows(pdlg->GetSafeHwnd(), EnumChildIconizeProc, 0L) != FALSE) |
| 98 |
{ |
| 99 |
// Success. |
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
TRACE("Iconize(): EnumChildWindows failed.\n"); |
| 104 |
sRes = -1; |
| 105 |
} |
| 106 |
|
| 107 |
return sRes; |
| 108 |
} |
| 109 |
|
| 110 |
/////////////////////////////////////////////////////////////////////////////// |
| 111 |
// |
| 112 |
// Store position of this window in the module's INI. |
| 113 |
// Returns 0 on success. |
| 114 |
// |
| 115 |
/////////////////////////////////////////////////////////////////////////////// |
| 116 |
extern int16_t StorePosition(CWnd* pwnd) |
| 117 |
{ |
| 118 |
int16_t sRes = 0; // Assume success. |
| 119 |
|
| 120 |
// Construct section name. |
| 121 |
char szSection[512]; |
| 122 |
pwnd->GetWindowText(szSection, sizeof(szSection)); |
| 123 |
strcat(szSection, " Position"); |
| 124 |
|
| 125 |
RECT rcWindow; |
| 126 |
pwnd->GetWindowRect(&rcWindow); |
| 127 |
|
| 128 |
AfxGetApp()->WriteProfileInt(szSection, "left", rcWindow.left); |
| 129 |
AfxGetApp()->WriteProfileInt(szSection, "top", rcWindow.top); |
| 130 |
AfxGetApp()->WriteProfileInt(szSection, "right", rcWindow.right); |
| 131 |
AfxGetApp()->WriteProfileInt(szSection, "bottom", rcWindow.bottom); |
| 132 |
|
| 133 |
return sRes; |
| 134 |
} |
| 135 |
|
| 136 |
/////////////////////////////////////////////////////////////////////////////// |
| 137 |
// |
| 138 |
// Restore position of this window from the module's INI. No change if no |
| 139 |
// settings stored. |
| 140 |
// Returns 0 on success. |
| 141 |
// |
| 142 |
/////////////////////////////////////////////////////////////////////////////// |
| 143 |
extern int16_t RestorePosition(CWnd* pwnd) |
| 144 |
{ |
| 145 |
int16_t sRes = 0; // Assume success. |
| 146 |
|
| 147 |
// Construct section name. |
| 148 |
char szSection[512]; |
| 149 |
pwnd->GetWindowText(szSection, sizeof(szSection)); |
| 150 |
strcat(szSection, " Position"); |
| 151 |
|
| 152 |
RECT rcWindow; |
| 153 |
pwnd->GetWindowRect(&rcWindow); |
| 154 |
|
| 155 |
rcWindow.left = AfxGetApp()->GetProfileInt(szSection, "left", rcWindow.left); |
| 156 |
rcWindow.top = AfxGetApp()->GetProfileInt(szSection, "top", rcWindow.top); |
| 157 |
rcWindow.right = AfxGetApp()->GetProfileInt(szSection, "right", rcWindow.right); |
| 158 |
rcWindow.bottom = AfxGetApp()->GetProfileInt(szSection, "bottom", rcWindow.bottom); |
| 159 |
|
| 160 |
if (rcWindow.top < 0) |
| 161 |
{ |
| 162 |
rcWindow.bottom -= rcWindow.top; |
| 163 |
rcWindow.top = 0; |
| 164 |
} |
| 165 |
|
| 166 |
if (rcWindow.left < 0) |
| 167 |
{ |
| 168 |
rcWindow.right -= rcWindow.left; |
| 169 |
rcWindow.left = 0; |
| 170 |
} |
| 171 |
|
| 172 |
CDC* pdc = pwnd->GetDC(); |
| 173 |
if (pdc != NULL) |
| 174 |
{ |
| 175 |
int32_t lScrWidth = pdc->GetDeviceCaps(HORZRES); |
| 176 |
int32_t lScrHeight = pdc->GetDeviceCaps(VERTRES); |
| 177 |
|
| 178 |
if (rcWindow.bottom > lScrHeight) |
| 179 |
{ |
| 180 |
rcWindow.top -= (rcWindow.bottom - lScrHeight); |
| 181 |
rcWindow.bottom -= (rcWindow.bottom - lScrHeight); |
| 182 |
} |
| 183 |
|
| 184 |
if (rcWindow.right > lScrWidth) |
| 185 |
{ |
| 186 |
rcWindow.left -= (rcWindow.right - lScrWidth); |
| 187 |
rcWindow.right -= (rcWindow.right - lScrWidth); |
| 188 |
} |
| 189 |
|
| 190 |
pwnd->ReleaseDC(pdc); |
| 191 |
} |
| 192 |
else |
| 193 |
{ |
| 194 |
TRACE("RestorePosition(): Unable to get CDC. Cannot bound window by " |
| 195 |
"desktop width & height.\n"); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
pwnd->MoveWindow( rcWindow.left, rcWindow.top, |
| 201 |
rcWindow.right - rcWindow.left, |
| 202 |
rcWindow.bottom - rcWindow.top); |
| 203 |
|
| 204 |
return sRes; |
| 205 |
} |
| 206 |
|
| 207 |
/////////////////////////////////////////////////////////////////////////////// |
| 208 |
// EOF |
| 209 |
/////////////////////////////////////////////////////////////////////////////// |