📄 main.c
字号:
BOOL _ImageList_DrawEx(HIMAGELIST himl, int i, HDC hdcDst, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
{
HDC memdc;
HBITMAP hBitMap;
HBITMAP hRetMemBmp;
HBRUSH hBrush;
RECT rect;
int size;
if(himl == NULL){
return FALSE;
}
if(dx == 16 || dx == 32){
return ImageList_DrawEx(himl, i, hdcDst, x, y, dx, dy, rgbBk, rgbFg, fStyle);
}
size = ((dx < 24) ? 16 : 32);
memdc = CreateCompatibleDC(hdcDst);
hBitMap = CreateCompatibleBitmap(hdcDst, size, size);
hRetMemBmp = SelectObject(memdc, hBitMap);
hBrush = CreateSolidBrush(RGB(255, 0, 255));
SetRect(&rect, 0, 0, size, size);
FillRect(memdc, &rect, hBrush);
DeleteObject(hBrush);
ImageList_DrawEx(himl, i, memdc, 0, 0, size, size, CLR_NONE, rgbFg, fStyle);
TransparentImage(hdcDst, x, y, dx, dy, memdc, 0, 0, size, size, RGB(255, 0, 255));
SelectObject(memdc, hRetMemBmp);
DeleteObject(hBitMap);
DeleteDC(memdc);
return TRUE;
}
/******************************************************************************
OnPaint
傾僀僐儞偺昤夋
******************************************************************************/
void OnPaint(HWND hWnd, HDC hdc, PAINTSTRUCT *ps, HBITMAP hBackBmp)
{
#ifdef _WCE_PPC2002
TODAYDRAWWATERMARKINFO dwi;
#endif
HDC drawdc;
HDC mdc;
HBITMAP hDrawBitMap;
HBITMAP hRetDrawBmp;
HBITMAP hRetBmp;
RECT rect;
RECT selrect;
BITMAP bmp;
int x, y;
int i;
HBRUSH hBrush;
//僂傿儞僪僂僒僀僘偵崌傢偣偨價僢僩儅僢僾傪奿擺偡傞壖憐僂傿儞僪僂偺嶌惉
GetClientRect(hWnd, (LPRECT)&rect);
//昤夋梡壖憐DC
drawdc = CreateCompatibleDC(hdc);
hDrawBitMap = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
hRetDrawBmp = SelectObject(drawdc, hDrawBitMap);
#ifdef _WCE_PPC2002
dwi.hdc = drawdc;
GetClientRect(hWnd, &dwi.rc);
dwi.hwnd = hWnd;
SendMessage(GetParent(hWnd), TODAYM_DRAWWATERMARK, 0, (LPARAM)&dwi);
#else
FillRect(drawdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
#endif
//攚宨偺昤夋
if(hBackBmp != NULL){
mdc = CreateCompatibleDC(hdc);
hRetBmp = SelectObject(mdc, hBackBmp);
if(stretch_backbmp == 0){
BitBlt(drawdc, 0, 0, rect.right, rect.bottom, mdc, 0, 0, SRCCOPY);
}else{
GetObject(hBackBmp, sizeof(BITMAP), &bmp);
StretchBlt(drawdc, 0, 0, rect.right, rect.bottom, mdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
}
SelectObject(mdc, hRetBmp);
DeleteDC(mdc);
}
//傾僀僐儞偺昤夋
x = WinLeftMargin;
y = WinTopMargin;
for(i = 0; i < FileListCnt; i++){
if((x + IconSize + (HMargin * 2)) > GetSystemMetrics(SM_CXSCREEN) - WinRightMargin){
x = WinLeftMargin;
y += IconSize + (VMargin * 2);
}
if(SelItem == i){
//慖戰傾僀僐儞
SetRect(&selrect, x, y, x + IconSize + (HMargin * 2), y + IconSize + (VMargin * 2));
hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
FillRect(drawdc, &selrect, hBrush);
DeleteObject(hBrush);
}
_ImageList_DrawEx(IconList, i,
drawdc, x + HMargin, y + VMargin, IconSize, IconSize, CLR_NONE, 0,
ILD_NORMAL);
x += IconSize + (HMargin * 2);
}
BitBlt(hdc, ps->rcPaint.left, ps->rcPaint.top, ps->rcPaint.right, ps->rcPaint.bottom,
drawdc, ps->rcPaint.left, ps->rcPaint.top, SRCCOPY);
SelectObject(drawdc, hRetDrawBmp);
DeleteObject(hDrawBitMap);
DeleteDC(drawdc);
}
/******************************************************************************
Point2Item
埵抲偐傜傾僀僥儉傪庢摼
******************************************************************************/
static int Point2Item(int px, int py)
{
RECT rect;
POINT pt;
int x, y;
int i;
pt.x = px;
pt.y = py;
for(x = WinLeftMargin, y = WinTopMargin, i = 0; i < FileListCnt; i++){
if((x + IconSize + (HMargin * 2)) > GetSystemMetrics(SM_CXSCREEN) - WinRightMargin){
x = WinLeftMargin;
y += IconSize + (VMargin * 2);
}
SetRect(&rect, x, y, x + IconSize + (HMargin * 2), y + IconSize + (VMargin * 2));
if(PtInRect(&rect, pt) == TRUE){
return i;
}
x += IconSize + (HMargin * 2);
}
return -1;
}
/******************************************************************************
ShellOpen
僼傽僀儖傪幚峴
******************************************************************************/
static BOOL ShellOpen(TCHAR *FileName, TCHAR *CommnadLine)
{
SHELLEXECUTEINFO sei;
WIN32_FIND_DATA FindData;
HANDLE hFindFile;
if((hFindFile = FindFirstFile(FileName, &FindData)) != INVALID_HANDLE_VALUE){
FindClose(hFindFile);
if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
//Folder open
CommnadLine = FileName;
FileName = FILE_EXPLORER;
}
}
if(lstrcmp(FileName, TEXT("\\")) == 0){
CommnadLine = FileName;
FileName = FILE_EXPLORER;
}
memset(&sei, 0, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(sei);
sei.fMask = 0;
sei.hwnd = NULL;
sei.lpVerb = NULL;
sei.lpFile = FileName;
if(*CommnadLine != TEXT('\0')){
sei.lpParameters = CommnadLine;
}
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;
sei.hInstApp = hInst;
return ShellExecuteEx(&sei);
}
/******************************************************************************
WndProc
儊僀儞僂傿儞僪僂僾儘僔乕僕儍
******************************************************************************/
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HBITMAP hBackBmp;
HDC hdc;
PAINTSTRUCT ps;
SHRGINFO rg;
int x, y;
int i;
switch(msg)
{
case WM_CREATE:
if(hToolTip == NULL){
hToolTip = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG_TOOLTIP), NULL, ToolTipProc);
}
//僼傽僀儖偐傜價僢僩儅僢僾傪撉傒崬傓
if(hBackBmp != NULL){
DeleteObject(hBackBmp);
hBackBmp = NULL;
}
if(*backbmpfile != TEXT('\0')){
hBackBmp = SHLoadDIBitmap(backbmpfile);
}
break;
case WM_DESTROY:
DestroyWindow(hToolTip);
hToolTip = NULL;
if(hBackBmp != NULL){
DeleteObject(hBackBmp);
hBackBmp = NULL;
}
if(IconList != NULL){
ImageList_Destroy((void *)IconList);
IconList = NULL;
}
if(FileList != NULL){
LocalFree(FileList);
}
FileList = NULL;
FileListCnt = 0;
return 0;
case WM_TODAYCUSTOM_CLEARCACHE:
break;
case WM_TODAYCUSTOM_QUERYREFRESHCACHE:
if(Refresh){
Refresh = FALSE;
//僂傿儞僪僂偺崅偝偺庢摼
for(x = WinLeftMargin, y = WinTopMargin, i = 0; i < FileListCnt; i++){
if((x + IconSize + (HMargin * 2)) > GetSystemMetrics(SM_CXSCREEN) - WinRightMargin){
x = WinLeftMargin;
y += IconSize + (VMargin * 2);
}
x += IconSize + (HMargin * 2);
}
y += IconSize + (VMargin * 2) + WinBottomMargin;
((TODAYLISTITEM *)(wParam))->cyp = y;
SetTimer(hWnd, ID_ICON_TIMER, ShowIconSec * 1000, NULL);
return TRUE;
}
return FALSE;
case WM_LBUTTONDOWN:
SelItem = Point2Item(LOWORD(lParam), HIWORD(lParam));
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
rg.cbSize = sizeof(SHRGINFO);
rg.hwndClient = hWnd;
rg.ptDown.x = LOWORD(lParam);
rg.ptDown.y = HIWORD(lParam);
#ifdef _WCE_PPC2002
rg.dwFlags = SHRG_RETURNCMD | SHRG_NOANIMATION;
#else
rg.dwFlags = SHRG_RETURNCMD;
#endif
if(SelItem != -1 && SHRecognizeGesture(&rg) == GN_CONTEXTMENU){
RECT rect;
RECT tip_rect;
SendMessage(hToolTip, WM_SETTEXT, 0, (LPARAM)(FileList + SelItem)->Name);
GetWindowRect(hWnd, &rect);
GetWindowRect(hToolTip, &tip_rect);
tip_rect.left = rect.left + LOWORD(lParam) - (tip_rect.right - tip_rect.left) - 10;
if(tip_rect.left < 0) tip_rect.left = 0;
tip_rect.top = rect.top + HIWORD(lParam) - (tip_rect.bottom - tip_rect.top) - 10;
if(tip_rect.top < 0) tip_rect.top = 0;
SetWindowPos(hToolTip, HWND_TOPMOST,
tip_rect.left, tip_rect.top,
0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
ShowWindow(hToolTip, SW_HIDE);
ReleaseCapture();
i = Point2Item(LOWORD(lParam), HIWORD(lParam));
if(i != -1 && i == SelItem){
ShellOpen((FileList + i)->FileName, (FileList + i)->CommnadLine);
}
SelItem = -1;
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
OnPaint(hWnd, hdc, &ps, hBackBmp);
EndPaint(hWnd, &ps);
break;
case WM_ERASEBKGND:
return 1;
case WM_TIMER:
switch(wParam)
{
case ID_ICON_TIMER:
if(SetImegeListIcon(FileList, FileListCnt, IconSize) == FALSE){
break;
}
KillTimer(hWnd, ID_ICON_TIMER);
InvalidateRect(hWnd, NULL, FALSE);
UpdateWindow(hWnd);
break;
}
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
/******************************************************************************
InitInstance
僂傿儞僪僂偺嶌惉
******************************************************************************/
static HWND InitInstance(HWND pWnd, TODAYLISTITEM *ptli)
{
WNDCLASS wc;
hInst = ptli->hinstDLL;
//愝掕撉傒崬傒
GetOption();
CreateFileList();
//僂傿儞僪僂僋儔僗偺搊榐
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hCursor = 0;
wc.lpszMenuName = 0;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = ptli->hinstDLL;
wc.hIcon = NULL;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName = MAIN_WND_CLASS;
UnregisterClass(MAIN_WND_CLASS, ptli->hinstDLL);
RegisterClass(&wc);
Refresh = TRUE;
//僂傿儞僪僂偺嶌惉
return CreateWindow(MAIN_WND_CLASS, WINDOW_TITLE, WS_CHILD | WS_VISIBLE, CW_DEFAULT, CW_DEFAULT, 0, 0,
pWnd, NULL, ptli->hinstDLL, NULL);
}
/******************************************************************************
InitializeCustomItem
弶婜壔
******************************************************************************/
HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *ptli, HWND pWnd)
{
if(ptli->fEnabled == 0){
return NULL;
}
//僂僀儞僪僂偺嶌惉
return InitInstance(pWnd, ptli);
}
/******************************************************************************
OptionDlgProc
愝掕夋柺
******************************************************************************/
static BOOL CALLBACK OptionDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
SHINITDLGINFO shidi;
TCHAR buf[BUF_SIZE];
switch(uMsg)
{
case WM_INITDIALOG:
//PocketPC梡弶婜壔
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
SetWindowText(hDlg, TEXT("Option"));
//僐儞僩儘乕儖偺弶婜壔
SendDlgItemMessage(hDlg, IDC_EDIT_BACKBMP, WM_SETTEXT, 0, (LPARAM)backbmpfile);
SendDlgItemMessage(hDlg, IDC_CHECK_STRETCH, BM_SETCHECK, stretch_backbmp, 0);
SetDlgItemInt(hDlg, IDC_EDIT_ICONSIZE, IconSize, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_HMARGIN, HMargin, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_VMARGIN, VMargin, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_WINLEFTMARGIN, WinLeftMargin, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_WINTOPMARGIN, WinTopMargin, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_WINRIGHTMARGIN, WinRightMargin, FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_WINBOTTOMMARGIN, WinBottomMargin, FALSE);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_EDIT_BACKBMP:
case IDC_EDIT_ICONSIZE:
case IDC_EDIT_HMARGIN:
case IDC_EDIT_VMARGIN:
case IDC_EDIT_WINLEFTMARGIN:
case IDC_EDIT_WINTOPMARGIN:
case IDC_EDIT_WINRIGHTMARGIN:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -