00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "precomp.h"
00013
#pragma hdrstop
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 PWND HotKeyToWindow(
00027 DWORD key)
00028 {
00029
PHOTKEYSTRUCT phk;
00030
int ckeys;
00031
00032 ckeys =
gcHotKey;
00033
00034
if (ckeys == 0)
00035
return 0;
00036
00037 phk =
gpHotKeyList;
00038
00039
while (ckeys) {
00040
if (phk->
key == key)
00041
return TestWF(phk->
spwnd,
WFVISIBLE) ? phk->
spwnd :
NULL;
00042 phk++;
00043 ckeys--;
00044 }
00045
00046
return 0;
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 PHOTKEYSTRUCT HotKeyHelper(
00061
PWND pwnd)
00062 {
00063
PHOTKEYSTRUCT phk;
00064
int count;
00065
00066 count =
gcHotKey;
00067
00068
if (
gpHotKeyList ==
NULL)
00069
return 0;
00070
00071 phk =
gpHotKeyList;
00072
00073
while (count) {
00074
if (phk->
spwnd == pwnd)
00075
return phk;
00076 phk++;
00077 count--;
00078 }
00079
00080
return 0;
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 UINT DWP_SetHotKey(
00097
PWND pwnd,
00098 DWORD dwKey)
00099 {
00100
PHOTKEYSTRUCT phk;
00101
BOOL fKeyExists =
FALSE;
00102
PWND pwndTemp;
00103
00104
00105
00106
00107
if (
LOBYTE(dwKey) == VK_ESCAPE ||
00108
LOBYTE(dwKey) == VK_SPACE ||
00109
LOBYTE(dwKey) == VK_TAB ||
00110
LOBYTE(dwKey) == VK_PACKET) {
00111
00112
return (
UINT)-1;
00113 }
00114
00115
00116
00117
00118
if (
TestWF(pwnd,
WFCHILD))
00119
return 0;
00120
00121
00122
00123
00124
if (dwKey != 0) {
00125
00126 pwndTemp =
HotKeyToWindow(dwKey);
00127
00128
if ((pwndTemp !=
NULL) && (pwndTemp != pwnd))
00129 fKeyExists =
TRUE;
00130 }
00131
00132
00133
00134
00135
if ((phk =
HotKeyHelper(pwnd)) ==
NULL) {
00136
00137
00138
00139
00140
00141
if (dwKey == 0)
00142
return 1;
00143
00144
00145
00146
00147
if (
gcHotKey >=
gcHotKeyAlloc) {
00148
00149
if (
gcHotKeyAlloc) {
00150
00151 phk = (
PHOTKEYSTRUCT)UserReAllocPool(
00152 (HANDLE)
gpHotKeyList,
00153
gcHotKeyAlloc *
sizeof(
HOTKEYSTRUCT),
00154 (
gcHotKey + 1) *
sizeof(
HOTKEYSTRUCT), TAG_HOTKEY);
00155
00156
if (phk !=
NULL) {
00157
00158
gpHotKeyList = phk;
00159 phk = &
gpHotKeyList[
gcHotKey++];
00160
gcHotKeyAlloc =
gcHotKey;
00161
00162 }
else {
00163
00164
return 0;
00165 }
00166
00167 }
else {
00168
00169 UserAssert(
gpHotKeyList ==
NULL);
00170 UserAssert(
gcHotKey == 0);
00171
00172 phk = (
PHOTKEYSTRUCT)UserAllocPool(
sizeof(
HOTKEYSTRUCT),
00173 TAG_HOTKEY);
00174
00175
if (phk !=
NULL) {
00176
00177
gpHotKeyList = phk;
00178
gcHotKey = 1;
00179
gcHotKeyAlloc = 1;
00180
00181 }
else {
00182
00183
return 0;
00184 }
00185 }
00186
00187 }
else {
00188 phk = &
gpHotKeyList[
gcHotKey++];
00189 }
00190 }
00191
00192
if (dwKey == 0) {
00193
00194
00195
00196
00197
00198
if (--
gcHotKey) {
00199
00200
Lock(&phk->
spwnd,
gpHotKeyList[
gcHotKey].spwnd);
00201
Unlock(&
gpHotKeyList[
gcHotKey].spwnd);
00202
00203 phk->
key =
gpHotKeyList[
gcHotKey].
key;
00204 phk = (
PHOTKEYSTRUCT)UserReAllocPool((HANDLE)
gpHotKeyList,
00205
gcHotKeyAlloc *
sizeof(
HOTKEYSTRUCT),
00206
gcHotKey *
sizeof(
HOTKEYSTRUCT), TAG_HOTKEY);
00207
00208
if (phk !=
NULL) {
00209
gpHotKeyList = phk;
00210
gcHotKeyAlloc =
gcHotKey;
00211 }
00212
00213 }
else {
00214
00215
Unlock(&
gpHotKeyList[
gcHotKey].spwnd);
00216 UserFreePool((HANDLE)
gpHotKeyList);
00217
gpHotKeyList =
NULL;
00218
gcHotKeyAlloc = 0;
00219 }
00220
00221 }
else {
00222
00223
00224
00225
00226 phk->
spwnd =
NULL;
00227
Lock(&phk->
spwnd, pwnd);
00228 phk->
key = dwKey;
00229 }
00230
00231
return fKeyExists ? 2 : 1;
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 UINT DWP_GetHotKey(
00243
PWND pwnd)
00244 {
00245
PHOTKEYSTRUCT phk;
00246
00247
if ((phk =
HotKeyHelper(pwnd)) ==
NULL)
00248
return 0;
00249
00250
return phk->
key;
00251 }