【原創】今日快速啟動插件的製作。
用到了RdWrtIni.h RdWrtIni.cpp,不知道是誰寫的,用來讀取ini,感謝他的分享。
用到了IImage庫。
// HelloWorldTodayPlug.cpp : 定义 DLL 应用程序的入口点。 // extern "C" _declspec(dllexport) HWND APIENTRY InitializeCustomItem(TODAYLISTITEM, HWND); extern "C" _declspec(dllexport) DWORD APIENTRY CustomOptionsDlgProc(); #include "stdafx.h" #include <windows.h> #include <commctrl.h> #include "stdio.h" #include "RdWrtIni.h" #include <initguid.h> #include <imaging.h> #pragma comment(lib, "Imaging") HINSTANCE g_hInst; HWND g_hWndParent; #define PROFILE _T(".\\TodayLauncher.ini") IImage *img[10]; IImagingFactory *imgFac[10]; int Length; int FocusSel; TCHAR szCmdExe[5][MAX_PATH]; TCHAR szCmdLine[5][MAX_PATH]; //void DrawUI(HDC hDC, int type); //void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr); void ShowUI(HDC hDC, int type); BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { return TRUE; } LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { FocusSel = 0; Length = GetSystemMetrics(SM_CXSCREEN) / 5; GetPrivateProfileString(_T("Executable"), _T("App1"), _T(""), szCmdExe[0], MAX_PATH, PROFILE); GetPrivateProfileString(_T("Executable"), _T("App2"), _T(""), szCmdExe[1], MAX_PATH, PROFILE); GetPrivateProfileString(_T("Executable"), _T("App3"), _T(""), szCmdExe[2], MAX_PATH, PROFILE); GetPrivateProfileString(_T("Executable"), _T("App4"), _T(""), szCmdExe[3], MAX_PATH, PROFILE); GetPrivateProfileString(_T("Executable"), _T("App5"), _T(""), szCmdExe[4], MAX_PATH, PROFILE); GetPrivateProfileString(_T("CommandLine"), _T("Cmd1"), _T(""), szCmdLine[0], MAX_PATH, PROFILE); GetPrivateProfileString(_T("CommandLine"), _T("Cmd2"), _T(""), szCmdLine[1], MAX_PATH, PROFILE); GetPrivateProfileString(_T("CommandLine"), _T("Cmd3"), _T(""), szCmdLine[2], MAX_PATH, PROFILE); GetPrivateProfileString(_T("CommandLine"), _T("Cmd4"), _T(""), szCmdLine[3], MAX_PATH, PROFILE); GetPrivateProfileString(_T("CommandLine"), _T("Cmd5"), _T(""), szCmdLine[4], MAX_PATH, PROFILE); if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) { MessageBox(NULL, _T("COM初始化失敗"), NULL, MB_OK); return FALSE; } for (int i=0; i<10; i++) { if(FAILED(CoCreateInstance(CLSID_ImagingFactory, NULL,CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void**)&imgFac[i]))) { MessageBox(NULL, _T("創建COM實例失敗"), NULL, MB_OK); return FALSE; } } if(FAILED(imgFac[0]->CreateImageFromFile(TEXT("\\TodayLauncher\\1.png"), &img[0]))) { MessageBox(NULL, _T("載入圖片1失敗"), NULL, MB_OK); } if(FAILED(imgFac[1]->CreateImageFromFile(TEXT("\\TodayLauncher\\2.png"), &img[1]))) { MessageBox(NULL, _T("載入圖片2失敗"), NULL, MB_OK); } if(FAILED(imgFac[2]->CreateImageFromFile(TEXT("\\TodayLauncher\\3.png"), &img[2]))) { MessageBox(NULL, _T("載入圖片3失敗"), NULL, MB_OK); } if(FAILED(imgFac[3]->CreateImageFromFile(TEXT("\\TodayLauncher\\4.png"), &img[3]))) { MessageBox(NULL, _T("載入圖片4失敗"), NULL, MB_OK); } if(FAILED(imgFac[4]->CreateImageFromFile(TEXT("\\TodayLauncher\\5.png"), &img[4]))) { MessageBox(NULL, _T("載入圖片5失敗"), NULL, MB_OK); } if(FAILED(imgFac[5]->CreateImageFromFile(TEXT("\\TodayLauncher\\6.png"), &img[5]))) { MessageBox(NULL, _T("載入圖片6失敗"), NULL, MB_OK); } if(FAILED(imgFac[6]->CreateImageFromFile(TEXT("\\TodayLauncher\\7.png"), &img[6]))) { MessageBox(NULL, _T("載入圖片7失敗"), NULL, MB_OK); } if(FAILED(imgFac[7]->CreateImageFromFile(TEXT("\\TodayLauncher\\8.png"), &img[7]))) { MessageBox(NULL, _T("載入圖片8失敗"), NULL, MB_OK); } if(FAILED(imgFac[8]->CreateImageFromFile(TEXT("\\TodayLauncher\\9.png"), &img[8]))) { MessageBox(NULL, _T("載入圖片9失敗"), NULL, MB_OK); } if(FAILED(imgFac[9]->CreateImageFromFile(TEXT("\\TodayLauncher\\10.png"), &img[9]))) { MessageBox(NULL, _T("載入圖片10失敗"), NULL, MB_OK); } } break; case WM_ERASEBKGND: { TODAYDRAWWATERMARKINFO tbi; tbi.hwnd = hWnd; tbi.hdc = (HDC)wParam; GetClientRect(hWnd, &tbi.rc); SendMessage(GetParent(hWnd), TODAYM_DRAWWATERMARK, 0, (LPARAM)&tbi); //ShowUI(tbi.hdc, FocusSel); return TRUE; } break; case WM_TODAYCUSTOM_QUERYREFRESHCACHE: if (!((TODAYLISTITEM*)wParam)->cyp) { ((TODAYLISTITEM*)wParam)->cyp = GetSystemMetrics(SM_CXSCREEN)/5; return TRUE; } break; case WM_TODAYCUSTOM_CLEARCACHE: break; case WM_DESTROY: { for (int i=0; i<10; i++) { img[i]->Release(); img[i] = NULL; imgFac[i]->Release(); imgFac[i] = NULL; } CoUninitialize(); } break; case WM_PAINT: { PAINTSTRUCT pt; HDC dc = BeginPaint(hWnd, &pt); SetBkMode(dc, TRANSPARENT); ShowUI(dc, FocusSel); EndPaint(hWnd, &pt); ReleaseDC(hWnd, dc); return 0; } break; case WM_LBUTTONUP: { POINT pt; pt.x = LOWORD(lParam); FocusSel = 0; InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); PROCESS_INFORMATION pi; //必备参数设置结束 if (pt.x > Length * 4) { if(!CreateProcess(szCmdExe[4], szCmdLine[4], NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { MessageBox(NULL, _T("CreateProcess Failed!"), _T("ERROR"), MB_OK); } } else if (pt.x > Length * 3) { if(!CreateProcess(szCmdExe[3], szCmdLine[3], NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { MessageBox(NULL, _T("CreateProcess Failed!"), _T("ERROR"), MB_OK); } } else if (pt.x > Length * 2) { if(!CreateProcess(szCmdExe[2], szCmdLine[2], NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { MessageBox(NULL, _T("CreateProcess Failed!"), _T("ERROR"), MB_OK); } } else if (pt.x > Length) { if(!CreateProcess(szCmdExe[1], szCmdLine[1], NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { MessageBox(NULL, _T("CreateProcess Failed!"), _T("ERROR"), MB_OK); } } else { if(!CreateProcess(szCmdExe[0], szCmdLine[0], NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi)) { MessageBox(NULL, _T("CreateProcess Failed!"), _T("ERROR"), MB_OK); } } return TRUE; } case WM_LBUTTONDOWN: { POINT pt; pt.x = LOWORD(lParam); if (pt.x > Length * 4) { FocusSel = 5; } else if (pt.x > Length * 3) { FocusSel = 4; } else if (pt.x > Length * 2) { FocusSel = 3; } else if (pt.x > Length) { FocusSel = 2; } else { FocusSel = 1; } InvalidateRect(hWnd, NULL, FALSE); UpdateWindow(hWnd); return TRUE; } default: return DefWindowProc( hWnd, msg, wParam, lParam ); } return 0; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASS wc = { 0L, MsgProc, 0L, 0L, hInstance, NULL, NULL, NULL, NULL, TEXT("TodayLauncherPlug") }; return RegisterClass( &wc ); } HWND APIENTRY InitializeCustomItem(TODAYLISTITEM *ptli, HWND hWndParent) { if (!ptli->fEnabled) { MessageBox(0, TEXT("DISABLED!"), NULL, 0); return NULL; } g_hInst = ptli->hinstDLL; g_hWndParent = hWndParent; MyRegisterClass(g_hInst); HWND hWnd = CreateWindow(TEXT("TodayLauncherPlug"), TEXT("TodayLauncherWindow"), WS_VISIBLE | WS_CHILD, 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CXSCREEN)/5, hWndParent, NULL, g_hInst, NULL); if (!hWnd) MessageBox(0, TEXT("MyRegisterClass Fail!"), NULL, 0); ShowWindow (hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); return hWnd; } DWORD APIENTRY CustomOptionsDlgProc() { return 0; } //if(!CreateProcess(szCmdExe,szCmdLine,NULL,NULL,FALSE,0,NULL,NULL,NULL,&pi)) // void DrawUI(HDC hDC, int type) // { // HDC MemDC = NULL; // HBITMAP MemBitmap = NULL; // MemDC = CreateCompatibleDC(NULL); // MemBitmap = CreateCompatibleBitmap(hDC, Length*5, Length); // // SelectObject(MemDC, MemBitmap); // FillSolidRect(MemDC, 0, 0, Length*5, Length, RGB(0, 255, 0)); // // //繪圖 // HBITMAP hBitmap; // HDC mdc; // // if (type != 1) // { // hBitmap = SHLoadImageFile(IMAGE_1); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, 0, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // else // { // hBitmap = SHLoadImageFile(IMAGE_AT1); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, 0, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // // if (type != 2) // { // hBitmap = SHLoadImageFile(IMAGE_2); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // else // { // hBitmap = SHLoadImageFile(IMAGE_AT2); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // // if (type != 3) // { // hBitmap = SHLoadImageFile(IMAGE_3); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length*2, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // else // { // hBitmap = SHLoadImageFile(IMAGE_AT3); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length*2, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // // if (type != 4) // { // hBitmap = SHLoadImageFile(IMAGE_4); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length*3, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // else // { // hBitmap = SHLoadImageFile(IMAGE_AT4); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length*3, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // // if (type != 5) // { // hBitmap = SHLoadImageFile(IMAGE_5); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length*4, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // else // { // hBitmap = SHLoadImageFile(IMAGE_AT5); // mdc = CreateCompatibleDC(NULL); // SelectObject(mdc, hBitmap); // BitBlt(MemDC, Length*4, 0, Length, Length, mdc, 0, 0, SRCCOPY); // DeleteDC(mdc); // DeleteObject(hBitmap); // } // // BitBlt(hDC, 0, 0, Length*5, Length, MemDC, 0, 0, SRCCOPY); // // //清理 // DeleteDC(MemDC); // DeleteObject(MemBitmap); // } // // void FillSolidRect(HDC hDC, int x, int y, int cx, int cy, COLORREF clr) // { // RECT rct; // rct.left = x; // rct.top = y; // rct.right = x + cx; // rct.bottom = y + cy; // // SetBkColor(hDC, clr); // ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rct, NULL, 0, NULL); // } void ShowUI(HDC hDC, int type) { RECT rect; rect.left = 0; rect.right = Length; rect.top = 0; rect.bottom = Length; if (type != 1) { if(FAILED(img[0]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片1失敗"), NULL, MB_OK); } } else { if(FAILED(img[5]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片6失敗"), NULL, MB_OK); } } rect.left = Length; rect.right = Length * 2; if (type != 2) { if(FAILED(img[1]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片2失敗"), NULL, MB_OK); } } else { if(FAILED(img[6]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片7失敗"), NULL, MB_OK); } } rect.left = Length * 2; rect.right = Length * 3; if (type != 3) { if(FAILED(img[2]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片3失敗"), NULL, MB_OK); } } else { if(FAILED(img[7]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片8失敗"), NULL, MB_OK); } } rect.left = Length * 3; rect.right = Length * 4; if (type != 4) { if(FAILED(img[3]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片4失敗"), NULL, MB_OK); } } else { if(FAILED(img[8]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片9失敗"), NULL, MB_OK); } } rect.left = Length * 4; rect.right = Length * 5; if (type != 5) { if(FAILED(img[4]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片5失敗"), NULL, MB_OK); } } else { if(FAILED(img[9]->Draw(hDC, &rect, NULL))) { MessageBox(NULL, _T("繪製圖片10失敗"), NULL, MB_OK); } } }
經過測試,Q屏和WVGA屏通過,理論兼容所有分辨率。
(五個白圈圈)
附上stdafx.h
// stdafx.h : 标准系统包含文件的包含文件, // 或是经常使用但不常更改的 // 特定于项目的包含文件 // #pragma once #pragma comment(linker, "/nodefaultlib:libc.lib") #pragma comment(linker, "/nodefaultlib:libcd.lib") // 注意 - 这个值与作为目标的 Windows CE OS 版本的关联性并不强 #define WINVER _WIN32_WCE #include <ceconfig.h> #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) #define SHELL_AYGSHELL #endif #ifdef _CE_DCOM #define _ATL_APARTMENT_THREADED #endif #include <aygshell.h> #pragma comment(lib, "aygshell.lib") // Windows 头文件: #include <windows.h> #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) #ifndef _DEVICE_RESOLUTION_AWARE #define _DEVICE_RESOLUTION_AWARE #endif #endif #ifdef _DEVICE_RESOLUTION_AWARE #include "DeviceResolutionAware.h" #endif #if _WIN32_WCE < 0x500 && ( defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) ) #pragma comment(lib, "ccrtrtti.lib") #ifdef _X86_ #if defined(_DEBUG) #pragma comment(lib, "libcmtx86d.lib") #else #pragma comment(lib, "libcmtx86.lib") #endif #endif #endif #include <altcecrt.h> // TODO: 在此处引用程序需要的其他头文件 #include <windows.h> #include <todaycmn.h>