📄 mouse.c
字号:
LPTSTR lpSchemeData;
HKEY hCuKey;
HKEY hCuCursorKey;
LONG lError = ERROR_SUCCESS;
BOOL bSchemeExists;
LoadString(hApplet, IDS_SYSTEM_SCHEME, szSystemScheme, MAX_PATH);
nSel = SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETCURSEL, 0, 0);
if (nSel == CB_ERR)
return FALSE;
if (nSel == 0)
{
szSchemeName[0] = 0;
}
else
{
SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETLBTEXT, nSel, (LPARAM)szNewSchemeName);
if (_tcsstr(szNewSchemeName, szSystemScheme))
{
szNewSchemeName[_tcslen(szNewSchemeName) - _tcslen(szSystemScheme) - 1] = 0;
}
}
/* Ask for a name for the new cursor scheme */
if (!DialogBoxParam(hApplet, MAKEINTRESOURCE(IDD_CURSOR_SCHEME_SAVEAS),
hwndDlg, SaveSchemeProc, (LPARAM)szNewSchemeName))
return TRUE;
/* Check all non-system schemes for the new name */
nSel = SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETCOUNT, 0, 0);
if (nSel == CB_ERR)
return FALSE;
bSchemeExists = FALSE;
for (i = 0; i < nSel; i++)
{
SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETLBTEXT, i, (LPARAM)szSchemeName);
if (_tcsstr(szSchemeName, szSystemScheme) == NULL)
{
if (_tcscmp(szSchemeName, szNewSchemeName) == 0)
{
bSchemeExists = TRUE;
break;
}
}
}
if (bSchemeExists)
{
LoadString(hApplet, IDS_OVERWRITE_TITLE, szTitle, 128);
LoadString(hApplet, IDS_OVERWRITE_TEXT, szText, 256);
/* Confirm scheme overwrite */
if (MessageBox(hwndDlg, szText, szTitle, MB_YESNO | MB_ICONQUESTION) == IDNO)
return TRUE;
}
/* Save the cursor scheme */
nLength = 0;
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
if (i > 0)
nLength++;
nLength += _tcslen(g_CursorData[i].szCursorPath);
}
nLength++;
lpSchemeData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength * sizeof(TCHAR));
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
CompressPath(szTempPath, g_CursorData[i].szCursorPath);
if (i > 0)
_tcscat(lpSchemeData, _T(","));
_tcscat(lpSchemeData, szTempPath);
}
if (RegOpenCurrentUser(KEY_READ | KEY_SET_VALUE, &hCuKey) != ERROR_SUCCESS)
return FALSE;
if (RegOpenKeyEx(hCuKey, _T("Control Panel\\Cursors\\Schemes"), 0, KEY_READ | KEY_SET_VALUE, &hCuCursorKey) != ERROR_SUCCESS)
{
RegCloseKey(hCuKey);
return FALSE;
}
lError = RegSetValueEx(hCuCursorKey, szNewSchemeName, 0,
REG_EXPAND_SZ, (LPBYTE)lpSchemeData,
(_tcslen(lpSchemeData) + 1) * sizeof(TCHAR));
RegCloseKey(hCuCursorKey);
RegCloseKey(hCuKey);
/* Add the new scheme to the scheme list and select it */
if (lError == ERROR_SUCCESS)
{
LPTSTR copy = _tcsdup(lpSchemeData);
nSel = SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_ADDSTRING, (WPARAM)0, (LPARAM)szNewSchemeName);
SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_SETITEMDATA, (WPARAM)nSel, (LPARAM)copy);
SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_SETCURSEL, (WPARAM)nSel, (LPARAM)0);
}
HeapFree(GetProcessHeap(), 0, lpSchemeData);
return (lError == ERROR_SUCCESS);
}
static BOOL
BrowseCursor(HWND hwndDlg)
{
TCHAR szFileName[MAX_PATH];
TCHAR szFilter[MAX_PATH];
TCHAR szTitle[MAX_PATH];
OPENFILENAME ofn;
INT nSel;
LoadString(hApplet, IDS_BROWSE_FILTER, szFilter, MAX_PATH);
LoadString(hApplet, IDS_BROWSE_TITLE, szTitle, MAX_PATH);
memset(szFileName, 0x0, sizeof(szFileName));
nSel = SendDlgItemMessage(hwndDlg, IDC_LISTBOX_CURSOR, LB_GETCURSEL, 0, 0);
if (nSel == LB_ERR)
{
MessageBox(hwndDlg, _T("LB_ERR"), _T(""), MB_ICONERROR);
return FALSE;
}
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwndDlg;
ofn.lpstrFilter = szFilter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrInitialDir = _T("%WINDIR%\\Cursors");
ofn.lpstrTitle = szTitle;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;
if (!GetOpenFileName(&ofn))
return FALSE;
/* Store the new cursor file path */
_tcsncpy(g_CursorData[nSel].szCursorPath, szFileName, MAX_PATH);
return TRUE;
}
static VOID
LoadCursorScheme(LPTSTR lpName, BOOL bSystem)
{
UINT index, i;
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
if (g_CursorData[i].hCursor != NULL)
{
DestroyCursor(g_CursorData[i].hCursor);
g_CursorData[i].hCursor = 0;
}
g_CursorData[i].szCursorPath[0] = 0;
}
if (lpName != NULL)
{
LPTSTR pStart = lpName;
LPTSTR pEnd = pStart;
INT nLength;
i = 0;
while (pEnd)
{
pEnd = _tcschr(pStart, _T(','));
if (pEnd)
nLength = ((INT_PTR)pEnd - (INT_PTR)pStart) / sizeof(TCHAR);
else
nLength = _tcslen(pStart);
_tcsncpy(g_CursorData[i].szCursorPath, pStart, nLength);
g_CursorData[i].szCursorPath[nLength] = 0;
pStart = pStart + (nLength + 1);
i++;
}
}
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
if (g_CursorData[i].szCursorPath[0] == 0)
g_CursorData[i].hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(g_CursorData[i].uDefaultCursorId),
IMAGE_CURSOR, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
else
g_CursorData[i].hCursor = (HCURSOR)LoadImage(NULL, g_CursorData[i].szCursorPath,
IMAGE_CURSOR, 0, 0,
LR_LOADFROMFILE | LR_DEFAULTSIZE);
}
}
static VOID
ReloadCurrentCursorScheme(VOID)
{
UINT index, i;
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
if (g_CursorData[i].hCursor != NULL)
DestroyCursor(g_CursorData[i].hCursor);
if (g_CursorData[i].szCursorPath[0] == 0)
g_CursorData[i].hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(g_CursorData[i].uDefaultCursorId),
IMAGE_CURSOR, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
else
g_CursorData[i].hCursor = (HCURSOR)LoadImage(NULL, g_CursorData[i].szCursorPath,
IMAGE_CURSOR, 0, 0,
LR_LOADFROMFILE | LR_DEFAULTSIZE);
}
}
static VOID
OnDrawItem(UINT idCtl,
LPDRAWITEMSTRUCT lpdis,
PPOINTER_DATA pPointerData)
{
RECT rc;
if (lpdis->itemState & ODS_SELECTED)
{
FillRect(lpdis->hDC,
&lpdis->rcItem,
(HBRUSH)(COLOR_HIGHLIGHT + 1));
SetBkColor(lpdis->hDC,
GetSysColor(COLOR_HIGHLIGHT));
SetTextColor(lpdis->hDC,
GetSysColor(COLOR_HIGHLIGHTTEXT));
}
else
{
FillRect(lpdis->hDC,
&lpdis->rcItem,
(HBRUSH)(COLOR_WINDOW + 1));
SetBkColor(lpdis->hDC,
GetSysColor(COLOR_WINDOW));
SetTextColor(lpdis->hDC,
GetSysColor(COLOR_WINDOWTEXT));
}
if (lpdis->itemID != -1)
{
CopyRect(&rc, &lpdis->rcItem);
rc.left += 5;
DrawText(lpdis->hDC,
g_CursorData[lpdis->itemData].szCursorName,
-1,
&rc,
DT_SINGLELINE | DT_VCENTER | DT_LEFT);
if (g_CursorData[lpdis->itemData].hCursor != NULL)
{
DrawIcon(lpdis->hDC,
lpdis->rcItem.right - pPointerData->cxCursor - 4,
lpdis->rcItem.top + 2,
g_CursorData[lpdis->itemData].hCursor);
}
}
if (lpdis->itemState & ODS_FOCUS)
{
CopyRect(&rc, &lpdis->rcItem);
InflateRect(&rc, -1, -1);
DrawFocusRect(lpdis->hDC, &rc);
}
}
static VOID
LoadNewCursorScheme(HWND hwndDlg)
{
TCHAR buffer[MAX_PATH];
TCHAR szSystemScheme[MAX_PATH];
HWND hDlgCtrl;
BOOL bEnable;
LPTSTR lpName;
INT nSel;
nSel = SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETCURSEL, 0, 0);
if (nSel == CB_ERR)
return;
SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETLBTEXT, nSel, (LPARAM)buffer);
LoadString(hApplet, IDS_SYSTEM_SCHEME, szSystemScheme, MAX_PATH);
if (_tcsstr(buffer, szSystemScheme) || nSel == 0) //avoid the default scheme can be deleted
bEnable = FALSE;
else
bEnable = TRUE;
/* delete button */
hDlgCtrl = GetDlgItem(hwndDlg, IDC_BUTTON_DELETE_SCHEME);
EnableWindow(hDlgCtrl, bEnable);
lpName = (LPTSTR)SendDlgItemMessage(hwndDlg, IDC_COMBO_CURSOR_SCHEME, CB_GETITEMDATA, nSel, 0);
LoadCursorScheme(lpName, !bEnable);
RefreshCursorList(hwndDlg, FALSE);
}
static VOID
LoadInitialCursorScheme(HWND hwndDlg)
{
TCHAR szSchemeName[256];
TCHAR szSystemScheme[256];
TCHAR szCursorPath[256];
HKEY hCursorKey;
LONG lError;
DWORD dwDataSize;
DWORD dwSchemeSource = 0;
UINT index, i;
DWORD dwType;
INT nSel;
for (index = IDS_ARROW, i = 0; index <= IDS_HAND; index++, i++)
{
g_CursorData[i].hCursor = 0;
g_CursorData[i].szCursorPath[0] = 0;
}
lError = RegOpenKeyEx(HKEY_CURRENT_USER,
_T("Control Panel\\Cursors"),
0,
KEY_READ | KEY_QUERY_VALUE,
&hCursorKey);
if (lError != ERROR_SUCCESS)
return;
dwDataSize = sizeof(DWORD);
lError = RegQueryValueEx(hCursorKey,
_T("Scheme Source"),
NULL,
NULL,
(LPBYTE)&dwSchemeSource,
&dwDataSize);
if (dwSchemeSource != 0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -