| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801 |
- // TrayS.cpp : 定义应用程序的入口点。
- //
- #ifdef _WIN64
- #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #else
- #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
- #endif
-
- #include "framework.h"
- #include "TrayS.h"
-
- int DPI(int pixel)
- {
- return pixel * iDPI / 96;
- }
-
- #if 0
- typedef struct _IP_HEADER
- {
- BYTE bVerAndHLen;
- / *版本信息(前4位)和头长度(后4位)* /
- BYTE bTypeOfService; //服务类型
- USHORT nTotalLength; //数据包长度
- USHORT nID; //数据包标识
- USHORT nReserved; //保留字段
- BYTE bTTL; //生成时间
- BYTE bProtocol; //协议类型
- USHORT nCheckSum; //校验和
- UINT nSourIp; //源IP
- UINT nDestIp; //目的IP
- }
- IP_HEADER, * PIP_HEADER;
-
- typedef struct _TCP_HEADER
- {
- USHORT nSourPort;
- USHORT nDestPort;
- UINT nSequNum;
- UINT nAcknowledgeNum;
- USHORT nHLenAndFlag;
- USHORT nWindowSize;
- USHORT nCheckSum;
- USHORT nrgentPointer;
- }
- TCP_HEADER, * PTCP_HEADER;
-
- typedef struct _UDP_HEADER
- {
- USHORT nSourPort;
- USHORT nDestPort;
- USHORT nLength;
- USHORT nCheckSum;
- }
- UDP_HEADER, * PUDP_HEADER;
-
- typedef struct _PACK_INFO
- {
- USHORT nLength;
- USHORT nProtocol;
- UINT nSourIp;
- UINT nDestIp;
- USHORT nSourPort;
- USHORT nDestPort;
- }
- PACK_INFO, * LPPACK_INFO;
-
- void AnalyseTcp(DWORD dwPort, ULONG64 ul64Flow, bool IsRecv)
- {
- DWORD dwPid = 0;
- MIB_TCPTABLE_OWNER_PID* stcTcpTable = NULL;
- DWORD szTcpTableSize = 0;
- //获取TCP表大小
- GetExtendedTcpTable(stcTcpTable, &szTcpTableSize, FALSE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0);
- //分配内存
- stcTcpTable = (MIB_TCPTABLE_OWNER_PID*)malloc(szTcpTableSize);
- ZeroMemory(stcTcpTable, szTcpTableSize);
-
- //获取TCP表
- if (NO_ERROR != GetExtendedTcpTable(stcTcpTable, &szTcpTableSize, FALSE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0))
- {
- free(stcTcpTable);
- return;
- }
-
- for (DWORD i = 0;
- i < stcTcpTable->dwNumEntries;
- i++)
- {
- if (stcTcpTable->table[i].dwLocalPort == dwPort)
- dwPid = stcTcpTable->table[i].dwOwningPid;
- }
-
- free(stcTcpTable);
- }
-
- void AnalyseUdp(DWORD dwPort, ULONG64 ul64Flow, bool IsRecv)
- {
- DWORD dwPid = 0;
- MIB_UDPTABLE_OWNER_PID* stcUdpTable = NULL;
- DWORD szUdpTableSize = 0;
- //获取UDP表大小
- GetExtendedUdpTable(stcUdpTable, &szUdpTableSize, FALSE, AF_INET, UDP_TABLE_OWNER_PID, 0);
- //分配内存
- stcUdpTable = (MIB_UDPTABLE_OWNER_PID*)malloc(szUdpTableSize);
- ZeroMemory(stcUdpTable, szUdpTableSize);
-
- //获取UDP表
- if (NO_ERROR != GetExtendedUdpTable(stcUdpTable, &szUdpTableSize, FALSE, AF_INET, UDP_TABLE_OWNER_PID, 0))
- {
- //在实际测试中这个地方确实偶尔是会失败的,不过在频繁的更新中一两次失败无关紧要
- free(stcUdpTable);
- return;
- }
-
- for (DWORD i = 0;
- i < stcUdpTable->dwNumEntries;
- i++)
- {
- if (stcUdpTable->table[i].dwLocalPort == dwPort)
- dwPid = stcUdpTable->table[i].dwOwningPid;
- //此处已经找到进程对应的pid了,同时包的大小和是上传还是下载已经通过参数传进来了。
- }
-
- free(stcUdpTable);
- //对数据的处理
- //...
- }
-
- void Thread()
- {
- PACK_INFO PackInfo =
- {
- 0
- };
-
- int nRecvSize = 0;
- char szPackBuf[DEF_BUF_SIZE] =
- {
- 0
- };
-
- WSADATA wsaData;
- int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
- if (iResult != NO_ERROR)
- return;
-
- // 获取本地地址信息
- sockaddr_in LocalAddr;
- char szLocalName[DEF_BUF_SIZE] =
- {
- 0
- };
- gethostname(szLocalName, DEF_BUF_SIZE);
- hostent* pHost = gethostbyname(szLocalName);
-
- if (pHost != NULL)
- {
- LocalAddr.sin_family = AF_INET;
- LocalAddr.sin_port = htons(0);
- memcpy(&(LocalAddr.sin_addr.s_addr), pHost->h_addr_list[0], pHost->h_length);
- }
- else
- return;
-
- // 创建监听套接字
- SOCKET MonSock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);
- if (MonSock == INVALID_SOCKET)
- return;
-
- // 绑定地址信息到套接字
- if (bind(MonSock, (sockaddr*)&LocalAddr, sizeof(sockaddr)) == SOCKET_ERROR)
- return;
-
- // 设置为混杂模式,收所有IP包
- DWORD dwValue = 1;
- if (ioctlsocket(MonSock, SIO_RCVALL, &dwValue) != 0)
- return;
-
- while (1)
- {
- // 取得数据包
- nRecvSize = recv(MonSock, szPackBuf, DEF_BUF_SIZE, 0);
- if (nRecvSize > 0)
- {
- // 解析IP包头
- PIP_HEADER pIpHeader = (PIP_HEADER)szPackBuf;
- PackInfo.nLength = nRecvSize;
- PackInfo.nProtocol = (USHORT)pIpHeader->bProtocol;
- PackInfo.nSourIp = pIpHeader->nSourIp;
- PackInfo.nDestIp = pIpHeader->nDestIp;
- UINT nIpHeadLength = (pIpHeader->bVerAndHLen & 0x0F) * sizeof(UINT); // IP数据包头长度
-
- // 只检测TCP和UDP包
- switch (pIpHeader->bProtocol)
- {
- case IPPROTO_TCP:
- {
- // 取得TCP数据包端口号
- PTCP_HEADER pTcpHeader = (PTCP_HEADER)&szPackBuf[nIpHeadLength];
- PackInfo.nSourPort = pTcpHeader->nSourPort;
- PackInfo.nDestPort = pTcpHeader->nDestPort;
- //判断上传还是下载
- if (PackInfo.nSourIp == LocalAddr.sin_addr.S_un.S_addr)
- AnalyseTcp(PackInfo.nSourPort, PackInfo.nLength, FALSE);
- else
- AnalyseTcp(PackInfo.nDestPort, PackInfo.nLength, TRUE);
- }
- break;
-
- case IPPROTO_UDP:
- {
- // 取得UDP数据包端口号
- PUDP_HEADER pUdpHeader = (PUDP_HEADER)&szPackBuf[nIpHeadLength];
- PackInfo.nSourPort = pUdpHeader->nSourPort;
- PackInfo.nDestPort = pUdpHeader->nDestPort;
- if (PackInfo.nSourIp == LocalAddr.sin_addr.S_un.S_addr)
- AnalyseUdp(PackInfo.nSourPort, PackInfo.nLength, FALSE);
- else
- AnalyseUdp(PackInfo.nDestPort, PackInfo.nLength, TRUE);
-
- }
- break;
- }
- }
-
- }
- }
- #endif
-
- BOOL CALLBACK FindWindowFunc(HWND hWnd, LPARAM lpAram)
- {
- WCHAR szText[16];
- GetWindowText(hWnd, szText, 16);
-
- if (lstrcmp(szText, L"_TrayS_") == 0)
- {
- SendMessage(hWnd, WM_TRAYS, 0, 0);
- return FALSE;
- }
-
- return TRUE;
- }
-
- BOOL CALLBACK IsZoomedFunc(HWND hWnd, LPARAM lpAram)
- {
- if (::IsWindowVisible(hWnd) && IsZoomed(hWnd))
- {
- if (MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST) == (HMONITOR)lpAram)
- {
- BOOL Attribute = FALSE;
- if (pDwmGetWindowAttribute)
- pDwmGetWindowAttribute(hWnd, 14, &Attribute, sizeof(BOOL));
-
- if (Attribute == FALSE)
- {
- iWindowMode = 1;
- return FALSE;
- }
- }
- }
-
- return TRUE;
- }
-
- #if 0
- BOOL CreateProcessByExplorer(LPCWSTR process, LPCWSTR szDir, LPCWSTR cmd)
- {
- BOOL ret = FALSE;
-
- HANDLE hProcess = 0, hToken = 0, hDuplicatedToken = 0;
- LPVOID lpEnv = NULL;
- do
- {
- HWND hTrayWnd = ::FindWindow(szShellTray, NULL);
- DWORD explorerPid;
- GetWindowThreadProcessId(hTrayWnd, &explorerPid); // 获取explorer进程号,自行实现
-
- if (explorerPid == NULL)
- break;
- hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, TRUE, explorerPid);
- if (INVALID_HANDLE_VALUE == hProcess)
- break;
-
- if (!OpenProcessToken(hProcess, TOKEN_ALL_ACCESS, &hToken))
- break;
-
- DuplicateTokenEx(hToken, MAXIMUM_ALLOWED, NULL, SecurityIdentification, TokenPrimary, &hDuplicatedToken);
- CreateEnvironmentBlock(&lpEnv, hDuplicatedToken, FALSE);
-
- / *
- WCHAR szDir[MAX_PATH] = L"\"";
- wcscpy_s(&szDir[2], MAX_PATH, process);
- int iLen = wcslen(szDir);
- if (NULL != cmd)
- {
- wcscpy_s(&szDir[iLen], MAX_PATH, L"\" \"");
- iLen = wcslen(szDir);
- wcscpy_s(&szDir[iLen], MAX_PATH, cmd);
- }
- iLen = wcslen(szDir);
- wcscpy_s(&szDir[iLen], MAX_PATH, L"\"");
- * /
-
- STARTUPINFO si =
- {
- 0
- };
- PROCESS_INFORMATION pi =
- {
- 0
- };
- si.cb = sizeof(STARTUPINFO);
- si.lpDesktop = (LPWSTR)L"winsta0\\default";
- si.dwFlags = STARTF_USESHOWWINDOW;
- si.wShowWindow = SW_HIDE;
- if (!CreateProcessAsUser(hToken, process, NULL / *const_cast<LPWSTR>(szDir) * / , 0, 0, FALSE, CREATE_UNICODE_ENVIRONMENT, lpEnv, NULL, &si, &pi))
- break;
- ret = TRUE;
- } while (0);
- if (INVALID_HANDLE_VALUE != hProcess)
- CloseHandle(hProcess);
- if (INVALID_HANDLE_VALUE != hToken)
- CloseHandle(hToken);
- if (INVALID_HANDLE_VALUE != hDuplicatedToken)
- CloseHandle(hDuplicatedToken);
- if (NULL != lpEnv)
- DestroyEnvironmentBlock(lpEnv);
- return ret;
- }
- #endif
-
- DWORD iCPU;
- /////////////////////////////////////////////////////////////////////////////CPU占用率
- FILETIME pre_idleTime;
- FILETIME pre_kernelTime;
- FILETIME pre_userTime;
-
- __int64 CompareFileTime(FILETIME time1, FILETIME time2)
- {
- __int64 a = time1.dwHighDateTime;
- a = a << 32 | time1.dwLowDateTime;
- __int64 b = time2.dwHighDateTime;
- b = b << 32 | time2.dwLowDateTime;
- return (b - a);
- }
-
- typedef struct _PDH_RAW_COUNTER
- {
- volatile DWORD CStatus;
- FILETIME TimeStamp;
- LONGLONG FirstValue;
- LONGLONG SecondValue;
- DWORD MultiCount;
- } PDH_RAW_COUNTER, *PPDH_RAW_COUNTER;
-
- PDH_RAW_COUNTER m_last_rawData;
- BOOL m_first_get_CPU_utility = TRUE;
-
- int GetCPUUseRate()
- {
- if (TraySave.bMonitorPDH)
- {
- #define PDH_FMT_RAW ((DWORD) 0x00000010)
- #define PDH_FMT_ANSI ((DWORD) 0x00000020)
- #define PDH_FMT_UNICODE ((DWORD) 0x00000040)
- #define PDH_FMT_LONG ((DWORD) 0x00000100)
- #define PDH_FMT_DOUBLE ((DWORD) 0x00000200)
- #define PDH_FMT_LARGE ((DWORD) 0x00000400)
- #define PDH_FMT_NOSCALE ((DWORD) 0x00001000)
- #define PDH_FMT_1000 ((DWORD) 0x00002000)
- #define PDH_FMT_NODATA ((DWORD) 0x00004000)
- #define PDH_FMT_NOCAP100 ((DWORD) 0x00008000)
- #define PERF_DETAIL_COSTLY ((DWORD) 0x00010000)
- #define PERF_DETAIL_STANDARD ((DWORD) 0x0000FFFF)
- typedef HANDLE PDH_HCOUNTER;
- typedef HANDLE PDH_HQUERY;
- typedef HANDLE PDH_HLOG;
- typedef PDH_HCOUNTER HCOUNTER;
- typedef PDH_HQUERY HQUERY;
- typedef struct _PDH_FMT_COUNTERVALUE
- {
- DWORD CStatus;
- union
- {
- LONG longValue;
- double doubleValue;
- LONGLONG largeValue;
- LPCSTR AnsiStringValue;
- LPCWSTR WideStringValue;
- };
- }
- PDH_FMT_COUNTERVALUE, *PPDH_FMT_COUNTERVALUE;
- //获取CPU使用率
- HQUERY hQuery;
- HCOUNTER hCounter;
- DWORD counterType;
- PDH_RAW_COUNTER rawData;
-
- typedef ULONG(WINAPI *pfnPdhOpenQuery)(_In_opt_ LPCWSTR szDataSource, _In_ DWORD_PTR dwUserData, _Out_ PDH_HQUERY *phQuery);
- typedef ULONG(WINAPI *pfnPdhAddCounter)(_In_ PDH_HQUERY hQuery, _In_ LPCWSTR szFullCounterPath, _In_ DWORD_PTR dwUserData, _Out_ PDH_HCOUNTER *phCounter);
- typedef ULONG(WINAPI *pfnPdhCollectQueryData)(PDH_HQUERY hQuery);
- typedef ULONG(WINAPI *pfnPdhGetRawCounterValue)(PDH_HCOUNTER hCounter, LPDWORD lpdwType, PPDH_RAW_COUNTER pValue);
- typedef ULONG(WINAPI *pfnPdhCalculateCounterFromRawValue)(PDH_HCOUNTER hCounter, DWORD dwFormat, PPDH_RAW_COUNTER rawValue1, PPDH_RAW_COUNTER rawValue2, PPDH_FMT_COUNTERVALUE fmtValue);
- typedef ULONG(WINAPI *pfnPdhCloseQuery)(PDH_HQUERY hQuery);
-
- if (hPDH == NULL)
- hPDH = LoadLibrary(L"pdh.dll");
- if (hPDH)
- {
- pfnPdhOpenQuery PdhOpenQuery = (pfnPdhOpenQuery)GetProcAddress(hPDH, "PdhOpenQueryW");
- pfnPdhAddCounter PdhAddCounter = (pfnPdhAddCounter)GetProcAddress(hPDH, "PdhAddCounterW");
- pfnPdhCollectQueryData PdhCollectQueryData = (pfnPdhCollectQueryData)GetProcAddress(hPDH, "PdhCollectQueryData");
- pfnPdhGetRawCounterValue PdhGetRawCounterValue = (pfnPdhGetRawCounterValue)GetProcAddress(hPDH, "PdhGetRawCounterValue");
- pfnPdhCalculateCounterFromRawValue PdhCalculateCounterFromRawValue = (pfnPdhCalculateCounterFromRawValue)GetProcAddress(hPDH, "PdhCalculateCounterFromRawValue");
- pfnPdhCloseQuery PdhCloseQuery = (pfnPdhCloseQuery)GetProcAddress(hPDH, "PdhCloseQuery");
-
- if (PdhCloseQuery != NULL && PdhAddCounter != NULL && PdhCollectQueryData != NULL && PdhGetRawCounterValue != NULL && PdhCalculateCounterFromRawValue != NULL && PdhCloseQuery != NULL)
- {
- PdhOpenQuery(NULL, 0, &hQuery); //开始查询
- const wchar_t *query_str{
- };
-
- query_str = L"\\Processor Information(_Total)\\% Processor Utility";
- PdhAddCounter(hQuery, query_str, NULL, &hCounter);
- PdhCollectQueryData(hQuery);
- PdhGetRawCounterValue(hCounter, &counterType, &rawData);
- PDH_FMT_COUNTERVALUE fmtValue;
- PdhCalculateCounterFromRawValue(hCounter, PDH_FMT_DOUBLE, &rawData, &m_last_rawData, &fmtValue); //计算使用率
- iCPU = (int)fmtValue.doubleValue; //传出数据
-
- if (iCPU > 100)
- iCPU = 100;
- m_last_rawData = rawData; //保存上一次数据
- PdhCloseQuery(hQuery); //关闭查询
- }
- }
-
- return iCPU;
- }
- else
- {
- if (hPDH)
- {
- FreeLibrary(hPDH);
- hPDH = NULL;
- }
-
- int nCPUUseRate = -1;
- FILETIME idleTime; //空闲时间
- FILETIME kernelTime; //核心态时间
- FILETIME userTime; //用户态时间
- GetSystemTimes(&idleTime, &kernelTime, &userTime);
-
- __int64 idle = CompareFileTime(pre_idleTime, idleTime);
- __int64 kernel = CompareFileTime(pre_kernelTime, kernelTime);
- __int64 user = CompareFileTime(pre_userTime, userTime);
-
- if (kernel + user != 0)
- nCPUUseRate = (int)((kernel + user - idle) * 100 / (kernel + user));
-
- pre_idleTime = idleTime;
- pre_kernelTime = kernelTime;
- pre_userTime = userTime;
-
- if (nCPUUseRate < 1)
- nCPUUseRate = iCPU;
- else if (nCPUUseRate > 100)
- nCPUUseRate = 100;
-
- return nCPUUseRate;
- }
- }
- void ReadReg() //读取设置
- {
- SetToCurrentPath();
- HANDLE hFile = CreateFile(szTraySave, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL);
-
- if (hFile)
- {
- DWORD dwBytes;
- ReadFile(hFile, &TraySave, sizeof TraySave, &dwBytes, NULL);
- CloseHandle(hFile);
- }
- #if 0
- HKEY pKey;
- if(IsUserAdmin())
- RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, NULL, KEY_ALL_ACCESS, &pKey);
- else
- RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, NULL, KEY_ALL_ACCESS, &pKey);
- if (pKey)
- {
- DWORD dType = REG_BINARY;
- DWORD cbData = sizeof(aMode);
- RegQueryValueEx(pKey, szMode, NULL, &dType, (BYTE*)aMode, &cbData);
- dType = REG_BINARY;
- cbData = sizeof(dAlphaColor);
- RegQueryValueEx(pKey, szAlphaColor, NULL, &dType, (BYTE*)dAlphaColor, &cbData);
- dType = REG_BINARY;
- cbData = sizeof(bAlpha);
- RegQueryValueEx(pKey, szAlpha, NULL, &dType, (BYTE*)bAlpha, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szPos, NULL, &dType, (BYTE*)&iPos, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szUnit, NULL, &dType, (BYTE*)&iUnit, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szTrayIcon, NULL, &dType, (BYTE*)&bTrayIcon, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitor, NULL, &dType, (BYTE*)&bMonitor, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorLeft, NULL, &dType, (BYTE*)&bMonitorLeft, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorFloat, NULL, &dType, (BYTE*)&bMonitorFloat, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorTransparent, NULL, &dType, (BYTE*)&bMonitorTransparent, &cbData);
- dType = REG_BINARY;
- cbData = sizeof(dMonitorPoint);
- RegQueryValueEx(pKey, szMonitorPoint, NULL, &dType, (BYTE*)&dMonitorPoint, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorTraffic, NULL, &dType, (BYTE*)&bMonitorTraffic, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorTemperature, NULL, &dType, (BYTE*)&bMonitorTemperature, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorUsage, NULL, &dType, (BYTE*)&bMonitorUsage, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szSound, NULL, &dType, (BYTE*)&bSound, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorPDH, NULL, &dType, (BYTE*)&bMonitorPDH, &cbData);
- dType = REG_DWORD;
- cbData = sizeof(DWORD);
- RegQueryValueEx(pKey, szMonitorSimple, NULL, &dType, (BYTE*)&bMonitorSimple, &cbData);
- dType = REG_BINARY;
- cbData = sizeof(cMonitorColor);
- RegQueryValueEx(pKey, szMonitorColor, NULL, &dType, (BYTE*)cMonitorColor, &cbData);
- dType = REG_BINARY;
- cbData = sizeof(dNumValues);
- RegQueryValueEx(pKey, szNumValues, NULL, &dType, (BYTE*)dNumValues, &cbData);
- dType = REG_BINARY;
- cbData = 38;
- RegQueryValueEx(pKey, szAdapterName, NULL, &dType, (BYTE*)AdpterName, &cbData);
- RegCloseKey(pKey);
- }
- #endif
- }
- void WriteReg() //写入设置
- {
- SetToCurrentPath();
- HANDLE hFile = CreateFile(szTraySave, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, NULL);
-
- if (hFile)
- {
- DWORD dwBytes;
- WriteFile(hFile, &TraySave, sizeof TraySave, &dwBytes, NULL);
- CloseHandle(hFile);
- }
- #if 0
- HKEY pKey;
- if (IsUserAdmin())
- {
- RegCreateKey(HKEY_LOCAL_MACHINE, szSubKey, &pKey);
- RegCloseKey(pKey);
- RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, NULL, KEY_ALL_ACCESS, &pKey);
- }
- else
- {
- RegCreateKey(HKEY_CURRENT_USER, szSubKey, &pKey);
- RegCloseKey(pKey);
- RegOpenKeyEx(HKEY_CURRENT_USER, szSubKey, NULL, KEY_ALL_ACCESS, &pKey);
- }
- if (pKey)
- {
- RegSetValueEx(pKey, szMode, NULL, REG_BINARY, (BYTE*)aMode, sizeof(aMode));
- RegSetValueEx(pKey, szAlphaColor, NULL, REG_BINARY, (BYTE*)dAlphaColor, sizeof(dAlphaColor));
- RegSetValueEx(pKey, szAlpha, NULL, REG_BINARY, (BYTE*)bAlpha, sizeof(bAlpha));
- RegSetValueEx(pKey, szPos, NULL, REG_DWORD, (BYTE*)&iPos, sizeof(iPos));
- RegSetValueEx(pKey, szUnit, NULL, REG_DWORD, (BYTE*)&iUnit, sizeof(iUnit));
- RegSetValueEx(pKey, szTrayIcon, NULL, REG_DWORD, (BYTE*)&bTrayIcon, sizeof(bTrayIcon));
- RegSetValueEx(pKey, szMonitor, NULL, REG_DWORD, (BYTE*)&bMonitor, sizeof(bMonitor));
- RegSetValueEx(pKey, szMonitorLeft, NULL, REG_DWORD, (BYTE*)&bMonitorLeft, sizeof(bMonitorLeft));
- RegSetValueEx(pKey, szMonitorFloat, NULL, REG_DWORD, (BYTE*)&bMonitorFloat, sizeof(bMonitorFloat));
- RegSetValueEx(pKey, szMonitorTransparent, NULL, REG_DWORD, (BYTE*)&bMonitorTransparent, sizeof(bMonitorTransparent));
- RegSetValueEx(pKey, szMonitorPoint, NULL, REG_BINARY, (BYTE*)&dMonitorPoint, sizeof(dMonitorPoint));
- RegSetValueEx(pKey, szMonitorTraffic, NULL, REG_DWORD, (BYTE*)&bMonitorTraffic, sizeof(bMonitorTraffic));
- RegSetValueEx(pKey, szMonitorTemperature, NULL, REG_DWORD, (BYTE*)&bMonitorTemperature, sizeof(bMonitorTemperature));
- RegSetValueEx(pKey, szMonitorUsage, NULL, REG_DWORD, (BYTE*)&bMonitorUsage, sizeof(bMonitorUsage));
- RegSetValueEx(pKey, szMonitorPDH, NULL, REG_DWORD, (BYTE*)&bMonitorPDH, sizeof(bMonitorPDH));
- RegSetValueEx(pKey, szMonitorSimple, NULL, REG_DWORD, (BYTE*)&bMonitorSimple, sizeof(bMonitorSimple));
- RegSetValueEx(pKey, szSound, NULL, REG_DWORD, (BYTE*)&bSound, sizeof(bSound));
- RegSetValueEx(pKey, szMonitorColor, NULL, REG_BINARY, (BYTE*)cMonitorColor, sizeof(cMonitorColor));
- RegSetValueEx(pKey, szNumValues, NULL, REG_BINARY, (BYTE*)dNumValues, sizeof(dNumValues));
- RegSetValueEx(pKey, szAdapterName, NULL, REG_BINARY, (BYTE*)AdpterName, 38);
- RegCloseKey(pKey);
- }
- #endif
- }
-
- void GetShellAllWnd()
- {
- while (IsWindow(hTray) == FALSE)
- {
- hTray = FindWindow(szShellTray, NULL);
- if (hTray == NULL)
- Sleep(100);
- }
-
- while (IsWindow(hReBarWnd) == FALSE)
- {
- hReBarWnd = FindWindowEx(hTray, 0, L"ReBarWindow32", NULL);
- if (hReBarWnd == NULL)
- Sleep(100);
- }
-
- if (IsWindow(hTaskWnd) == FALSE)
- hTaskWnd = FindWindowEx(hReBarWnd, NULL, L"MSTaskSwWClass", NULL);
- if (IsWindow(hTaskListWnd) == FALSE)
- hTaskListWnd = FindWindowEx(hTaskWnd, NULL, L"MSTaskListWClass", NULL);
- }
-
- void CloseTaskBar()
- {
- if (IsWindow(hTaskBar))
- DestroyWindow(hTaskBar);
- if (IsWindow(hTaskTips))
- DestroyWindow(hTaskTips);
- }
-
- void OpenTaskBar()
- {
- if (IsWindow(hTaskBar) == FALSE)
- {
- hTaskBar = ::CreateDialog(hInst, MAKEINTRESOURCE(IDD_TASKBAR), NULL, (DLGPROC)TaskBarProc);
- if (hTaskBar)
- {
- GetShellAllWnd();
- if (TraySave.bMonitorFloat)
- {
- LONG exStyle = WS_EX_LAYERED | WS_EX_TOPMOST;
- if (TraySave.bMonitorTransparent)
- exStyle |= WS_EX_TRANSPARENT;
- SetWindowLongPtr(hTaskBar, GWL_EXSTYLE, GetWindowLongPtr(hTaskBar, GWL_EXSTYLE) | exStyle);
- SetLayeredWindowAttributes(hTaskBar, RGB(0, 0, 1), 198, LWA_ALPHA | LWA_COLORKEY);
- SetParent(hTaskBar, NULL);
- }
- else
- SetParent(hTaskBar, hReBarWnd);
-
- SetWH();
- #if 0
- if (rovi.dwMajorVersion < 10)
- {
- SetWindowLongPtr(hTaskBar, GWL_EXSTYLE, GetWindowLongPtr(hTaskBar, GWL_EXSTYLE) | WS_EX_LAYERED);
- SetLayeredWindowAttributes(hTaskBar, RGB(128, 128, 129), 0, LWA_COLORKEY);
- }
- #endif
- ShowWindow(hTaskBar, SW_SHOW);
- SetTimer(hTaskBar, 3, 1000, NULL);
- // SetTimer(hTaskBar, 6, 100, NULL);
- }
- }
- else
- {
- if (TraySave.bMonitorTransparent)
- SetWindowLongPtr(hTaskBar, GWL_EXSTYLE, GetWindowLongPtr(hTaskBar, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
- else
- SetWindowLongPtr(hTaskBar, GWL_EXSTYLE, GetWindowLongPtr(hTaskBar, GWL_EXSTYLE) & ~WS_EX_TRANSPARENT);
- }
- }
-
- ////////////////////////////////////////////获取CPU温度
- #define MISC_CONTROL_3 (0x3 + ((0x18) << 3))
- int GetCpuTemp(DWORD Core)
- {
- if (bRing0)
- {
- SetThreadAffinityMask(GetCurrentThread(), Core);
- DWORD eax = 0, ebx, ecx, edx;
- if (!bIntel)
- {
- Cpuid(1, &eax, &ebx, &ecx, &edx);
- int family = ((eax >> 20) & 0xFF) + ((eax >> 8) & 0xF);
-
- if (family > 0xf)
- {
- // DWORD pciDevAddr = FindPciDeviceById(0x1022, 0x1203, 0);
- DWORD miscReg;
- ReadPciConfigDwordEx(MISC_CONTROL_3, 0xa4, &miscReg);
- return (miscReg >> 21) >> 3;
- }
- else
- {
- // DWORD pciDevAddr = FindPciDeviceById(0x1022, 0x1103, 0);
- DWORD miscReg;
- ReadPciConfigDwordEx(MISC_CONTROL_3, 0xe4, &miscReg);
- return ((miscReg & 0xFF0000) >> 16) - 49;
- // return (miscReg >> 16) & 0xFF;
- }
- }
- else
- {
- DWORD IAcore;
- int Tjunction = 100;
- Rdmsr(0x1A2, &eax, &edx);
- if (eax & 0x20000000)
- Tjunction = 85;
- Rdmsr(0x19C, &eax, &edx);
- IAcore = eax;
- IAcore &= 0xFF0000;
- IAcore = IAcore >> 16;
- return Tjunction - IAcore;
- }
- }
-
- return 0;
- }
-
- //////////////////////////////////////////////////载入温度DLL
- void LoadTemperatureDLL()
- {
- if (!InitOpenLibSys(&m_hOpenLibSys))
- bRing0 = FALSE;
- else
- {
- bRing0 = TRUE;
- DWORD eax, ebx, ecx, edx;
- Cpuid(0, &eax, &ebx, &ecx, &edx);
- bIntel = TRUE;
- if (ebx == 0x68747541)
- {
- bIntel = FALSE;
- }
- }
- #ifdef _WIN64
- hNVDLL = LoadLibrary(L"nvapi64.dll");
- #else
- hNVDLL = LoadLibrary(L"nvapi.dll");
- #endif
- if (hNVDLL)
- {
- NvAPI_QueryInterface = (NvAPI_QueryInterface_t)GetProcAddress(hNVDLL, "nvapi_QueryInterface");
- if (NvAPI_QueryInterface)
- {
- NvAPI_Initialize_t NvAPI_Initialize = (NvAPI_Initialize_t)NvAPI_QueryInterface(ID_NvAPI_Initialize);
- NvAPI_EnumPhysicalGPUs_t NvAPI_EnumPhysicalGPUs = (NvAPI_EnumPhysicalGPUs_t)NvAPI_QueryInterface(ID_NvAPI_EnumPhysicalGPUs);
- NvAPI_GPU_GetThermalSettings = (NvAPI_GPU_GetThermalSettings_t)NvAPI_QueryInterface(ID_NvAPI_GPU_GetThermalSettings);
- if (NvAPI_Initialize != NULL && NvAPI_EnumPhysicalGPUs != NULL && NvAPI_GPU_GetThermalSettings != NULL)
- {
- if (NvAPI_Initialize() == 0)
- {
- for (NvU32 PhysicalGpuIndex = 0; PhysicalGpuIndex < 4; PhysicalGpuIndex++)
- {
- hPhysicalGpu[PhysicalGpuIndex] = 0;
- }
- int physicalGpuCount;
- NvAPI_EnumPhysicalGPUs(hPhysicalGpu, &physicalGpuCount);
- }
- else
- {
- FreeLibrary(hNVDLL);
- hNVDLL = NULL;
- }
- }
- else
- {
- FreeLibrary(hNVDLL);
- hNVDLL = NULL;
- }
- }
- else
- {
- FreeLibrary(hNVDLL);
- hNVDLL = NULL;
- }
- }
- #ifdef _WIN64
- hATIDLL = LoadLibrary(L"atiadlxx.dll");
- #else
- hATIDLL = LoadLibrary(L"atiadlxy.dll");
- #endif
- if (hATIDLL)
- {
- ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE)GetProcAddress(hATIDLL, "ADL_Main_Control_Create");
- ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY)GetProcAddress(hATIDLL, "ADL_Main_Control_Destroy");
- ADL_Overdrive5_Temperature_Get = (ADL_OVERDRIVE5_TEMPERATURE_GET)GetProcAddress(hATIDLL, "ADL_Overdrive5_Temperature_Get");
- if (NULL != ADL_Main_Control_Create &&
- NULL != ADL_Main_Control_Destroy
- )
- {
- if (ADL_OK != ADL_Main_Control_Create(ADL_Main_Memory_Alloc, 1))
- {
- FreeLibrary(hATIDLL);
- hATIDLL = NULL;
- }
- }
- else
- {
- FreeLibrary(hATIDLL);
- hATIDLL = NULL;
- }
- }
- }
-
- ///////////////////////////////////释放温度DLL
- void FreeTemperatureDLL()
- {
- if (hATIDLL)
- {
- ADL_Main_Control_Destroy();
- FreeLibrary(hATIDLL);
- hATIDLL = NULL;
- }
-
- if (hNVDLL)
- {
- FreeLibrary(hNVDLL);
- hNVDLL = NULL;
- }
-
- if (m_hOpenLibSys)
- DeinitOpenLibSys(&m_hOpenLibSys);
- m_hOpenLibSys = NULL;
- }
- ///////////////////////////////////////////////打开读取设置
- void OpenSetting()
- {
- if (IsWindow(hSetting))
- {
- SetForegroundWindow(hSetting);
- return;
- }
-
- hSetting = ::CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETTING), NULL, (DLGPROC)SettingProc);
-
- if (!hSetting)
- {
- return;
- }
-
- SendMessage(hSetting, WM_SETICON, ICON_BIG, (LPARAM)(HICON)iMain);
- SendMessage(hSetting, WM_SETICON, ICON_SMALL, (LPARAM)(HICON)iMain);
- CheckRadioButton(hSetting, IDC_RADIO_NORMAL, IDC_RADIO_MAXIMIZE, IDC_RADIO_NORMAL);
- iProject = iWindowMode;
-
- if (iProject == 0)
- CheckRadioButton(hSetting, IDC_RADIO_NORMAL, IDC_RADIO_MAXIMIZE, IDC_RADIO_NORMAL);
- else
- CheckRadioButton(hSetting, IDC_RADIO_NORMAL, IDC_RADIO_MAXIMIZE, IDC_RADIO_MAXIMIZE);
- if (TraySave.aMode[iProject] == ACCENT_DISABLED)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_DEFAULT);
- else if (TraySave.aMode[iProject] == ACCENT_ENABLE_TRANSPARENTGRADIENT)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_TRANSPARENT);
- else if (TraySave.aMode[iProject] == ACCENT_ENABLE_BLURBEHIND)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_BLURBEHIND);
- else if (TraySave.aMode[iProject] == ACCENT_ENABLE_ACRYLICBLURBEHIND)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_ACRYLIC);
- if (TraySave.iPos == 0)
- CheckRadioButton(hSetting, IDC_RADIO_LEFT, IDC_RADIO_RIGHT, IDC_RADIO_LEFT);
- else if (TraySave.iPos == 1)
- CheckRadioButton(hSetting, IDC_RADIO_LEFT, IDC_RADIO_RIGHT, IDC_RADIO_CENTER);
- else if (TraySave.iPos == 2)
- CheckRadioButton(hSetting, IDC_RADIO_LEFT, IDC_RADIO_RIGHT, IDC_RADIO_RIGHT);
- if (LOWORD(TraySave.iUnit) == 0)
- CheckRadioButton(hSetting, IDC_RADIO_AUTO, IDC_RADIO_MB, IDC_RADIO_AUTO);
- else if (LOWORD(TraySave.iUnit) == 1)
- CheckRadioButton(hSetting, IDC_RADIO_AUTO, IDC_RADIO_MB, IDC_RADIO_KB);
- else if (LOWORD(TraySave.iUnit) == 2)
- CheckRadioButton(hSetting, IDC_RADIO_AUTO, IDC_RADIO_MB, IDC_RADIO_MB);
- if (HIWORD(TraySave.iUnit) == 0)
- CheckRadioButton(hSetting, IDC_RADIO_BYTE, IDC_RADIO_BIT, IDC_RADIO_BYTE);
- else
- CheckRadioButton(hSetting, IDC_RADIO_BYTE, IDC_RADIO_BIT, IDC_RADIO_BIT);
-
- CheckDlgButton(hSetting, IDC_CHECK_TRAYICON, TraySave.bTrayIcon);
- CheckDlgButton(hSetting, IDC_CHECK_MONITOR, TraySave.bMonitor);
- CheckDlgButton(hSetting, IDC_CHECK_TRAFFIC, TraySave.bMonitorTraffic);
- CheckDlgButton(hSetting, IDC_CHECK_TEMPERATURE, TraySave.bMonitorTemperature);
- CheckDlgButton(hSetting, IDC_CHECK_USAGE, TraySave.bMonitorUsage);
- CheckDlgButton(hSetting, IDC_CHECK_SOUND, TraySave.bSound);
- CheckDlgButton(hSetting, IDC_CHECK_MONITOR_PDH, TraySave.bMonitorPDH);
- CheckDlgButton(hSetting, IDC_CHECK_MONITOR_SIMPLE, TraySave.iMonitorSimple);
- CheckDlgButton(hSetting, IDC_CHECK_MONITOR_LEFT, TraySave.bMonitorLeft);
- CheckDlgButton(hSetting, IDC_CHECK_MONITOR_FLOAT, TraySave.bMonitorFloat);
- CheckDlgButton(hSetting, IDC_CHECK_TRANSPARENT, TraySave.bMonitorTransparent);
- CheckDlgButton(hSetting, IDC_CHECK_TIPS, TraySave.bMonitorTips);
- SendDlgItemMessage(hSetting, IDC_SLIDER_ALPHA, TBM_SETRANGE, 0, MAKELPARAM(0, 255));
- SendDlgItemMessage(hSetting, IDC_SLIDER_ALPHA, TBM_SETPOS, TRUE, TraySave.bAlpha[iProject]);
- SendDlgItemMessage(hSetting, IDC_SLIDER_ALPHA_B, TBM_SETRANGE, 0, MAKELPARAM(0, 255));
- BYTE bAlphaB = TraySave.dAlphaColor[iProject] >> 24;
- SendDlgItemMessage(hSetting, IDC_SLIDER_ALPHA_B, TBM_SETPOS, TRUE, bAlphaB);
- SendDlgItemMessage(hSetting, IDC_CHECK_AUTORUN, BM_SETCHECK, AutoRun(FALSE, FALSE, szAppName), NULL);
- bSettingInit = TRUE;
- SetDlgItemInt(hSetting, IDC_EDIT1, TraySave.dNumValues[0] / 1048576, 0);
- SetDlgItemInt(hSetting, IDC_EDIT2, TraySave.dNumValues[1] / 1048576, 0);
- SetDlgItemInt(hSetting, IDC_EDIT3, TraySave.dNumValues[2], 0);
- SetDlgItemInt(hSetting, IDC_EDIT4, TraySave.dNumValues[3], 0);
- SetDlgItemInt(hSetting, IDC_EDIT5, TraySave.dNumValues[4], 0);
- SetDlgItemInt(hSetting, IDC_EDIT6, TraySave.dNumValues[5], 0);
- SetDlgItemInt(hSetting, IDC_EDIT7, TraySave.dNumValues[6], 0);
- SetDlgItemInt(hSetting, IDC_EDIT8, TraySave.dNumValues[7], 0);
- SetDlgItemInt(hSetting, IDC_EDIT9, TraySave.dNumValues[8] / 1048576, 0);
- SetDlgItemInt(hSetting, IDC_EDIT10, TraySave.dNumValues[9], 0);
- SetDlgItemInt(hSetting, IDC_EDIT11, TraySave.dNumValues[10], 0);
- SetDlgItemInt(hSetting, IDC_EDIT12, TraySave.dNumValues[11], 0);
- SetDlgItemInt(hSetting, IDC_EDIT_TIME, TraySave.FlushTime, 0);
- SetDlgItemText(hSetting, IDC_EDIT14, TraySave.szTrafficOut);
- SetDlgItemText(hSetting, IDC_EDIT15, TraySave.szTrafficIn);
- SetDlgItemText(hSetting, IDC_EDIT16, TraySave.szTemperatureCPU);
- SetDlgItemText(hSetting, IDC_EDIT17, TraySave.szTemperatureGPU);
- SetDlgItemText(hSetting, IDC_EDIT18, TraySave.szTemperatureCPUUnit);
- SetDlgItemText(hSetting, IDC_EDIT19, TraySave.szTemperatureGPUUnit);
- SetDlgItemText(hSetting, IDC_EDIT20, TraySave.szUsageCPU);
- SetDlgItemText(hSetting, IDC_EDIT21, TraySave.szUsageMEM);
- SetDlgItemText(hSetting, IDC_EDIT22, TraySave.szUsageCPUUnit);
- SetDlgItemText(hSetting, IDC_EDIT23, TraySave.szUsageMEMUnit);
- bSettingInit = FALSE;
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_BACKGROUND), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_TRAFFIC_LOW), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_TRAFFIC_MEDIUM), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_TRAFFIC_HIGH), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_LOW), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_MEDUIM), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- oldColorButtonPoroc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hSetting, IDC_BUTTON_COLOR_HIGH), GWLP_WNDPROC, (LONG_PTR)ColorButtonProc);
- ShowWindow(hSetting, SW_SHOW);
- UpdateWindow(hSetting);
- SetForegroundWindow(hSetting);
- }
- #if 0
- void SetTaskScheduler(BOOL bAdd)
- {
- HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- if (SUCCEEDED(hr))
- {
- // Set general COM security levels.
- hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0, NULL);
- if (SUCCEEDED(hr))
- {
- ITaskService* pService = NULL;
- hr = CoCreateInstance(CLSID_TaskScheduler,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_ITaskService,
- (void**)&pService);
- if (SUCCEEDED(hr))
- {
- hr = pService->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t());
- if (SUCCEEDED(hr))
- {
- ITaskFolder* pRootFolder = NULL;
- hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder);
- if (SUCCEEDED(hr))
- {
- pRootFolder->DeleteTask(_bstr_t(szAppName), 0);
- if (bAdd)
- {
- ITaskDefinition* pTask = NULL;
- hr = pService->NewTask(0, &pTask);
- // pService->Release(); // COM clean up. Pointer is no longer used.
- if (SUCCEEDED(hr))
- {
- if (IsUserAdmin())
- {
- IPrincipal* pPrincipal;
- hr = pTask->get_Principal(&pPrincipal);
- if (SUCCEEDED(hr))
- {
- pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);
- }
- }
- IRegistrationInfo* pRegInfo = NULL;
- hr = pTask->get_RegistrationInfo(&pRegInfo);
- if (SUCCEEDED(hr))
- {
- hr = pRegInfo->put_Author(_bstr_t(L"cgbsmy"));
- pRegInfo->Release();
-
- if (SUCCEEDED(hr))
- {
- ITaskSettings* pSettings = NULL;
- hr = pTask->get_Settings(&pSettings);
- if (SUCCEEDED(hr))
- {
- pSettings->put_StopIfGoingOnBatteries(VARIANT_FALSE);
- pSettings->put_DisallowStartIfOnBatteries(VARIANT_FALSE);
- pSettings->put_AllowHardTerminate(VARIANT_FALSE);
- pSettings->put_ExecutionTimeLimit(_bstr_t(L"PT0S"));
- pSettings->put_WakeToRun(VARIANT_TRUE);
- hr = pSettings->put_StartWhenAvailable(VARIANT_TRUE);
- pSettings->Release();
- if (SUCCEEDED(hr))
- {
- ITriggerCollection* pTriggerCollection = NULL;
- hr = pTask->get_Triggers(&pTriggerCollection);
- if (SUCCEEDED(hr))
- {
- ITrigger* pTrigger = NULL;
- hr = pTriggerCollection->Create(TASK_TRIGGER_LOGON, &pTrigger);
- pTriggerCollection->Release();
- if (SUCCEEDED(hr))
- {
- ILogonTrigger* pLogonTrigger = NULL;
- hr = pTrigger->QueryInterface(
- IID_ILogonTrigger, (void**)&pLogonTrigger);
- pTrigger->Release();
- if (SUCCEEDED(hr))
- {
- hr = pLogonTrigger->put_Id(_bstr_t(L"cgbsmy"));
- if (SUCCEEDED(hr))
- {
- // hr = pBootTrigger->put_StartBoundary(_bstr_t(L"2020-06-11T0:00:00"));
- // hr = pBootTrigger->put_EndBoundary(_bstr_t(L"2222-06-19T08:00:00"));
- // Delay the task to start 30 seconds after system start.
- // hr = pBootTrigger->put_Delay(_bstr_t(L"PT1S"));
- if (!IsUserAdmin())
- {
- WCHAR szName[MAX_PATH];
- DWORD dwLen = MAX_PATH;
- GetUserName(szName, &dwLen);
- pLogonTrigger->put_UserId(_bstr_t(szName));
- }
- pLogonTrigger->Release();
- IActionCollection* pActionCollection = NULL;
- hr = pTask->get_Actions(&pActionCollection);
- if (SUCCEEDED(hr))
- {
-
- // Create the action, specifying it as an executable action.
- IAction* pAction = NULL;
- hr = pActionCollection->Create(TASK_ACTION_EXEC, &pAction);
- pActionCollection->Release();
- if (SUCCEEDED(hr))
- {
- IExecAction* pExecAction = NULL;
- // QI for the executable task pointer.
- hr = pAction->QueryInterface(
- IID_IExecAction, (void**)&pExecAction);
- pAction->Release();
- if (SUCCEEDED(hr))
- {
- WCHAR szExe[MAX_PATH];
- GetModuleFileName(NULL, szExe, MAX_PATH);
- size_t sLen = wcslen(szExe);
- hr = pExecAction->put_Path(_bstr_t(szExe));
- pExecAction->put_Arguments(_bstr_t(L" t"));
- pExecAction->Release();
- if (SUCCEEDED(hr))
- {
- IRegisteredTask* pRegisteredTask = NULL;
- VARIANT varID;
- varID.vt = VT_NULL;
- VARIANT varPassword;
- varPassword.vt = VT_NULL;
- // MessageBox(hSetting, szName, szName, MB_OK);
- //hr = pRootFolder->RegisterTaskDefinition(_bstr_t(szAppName), pTask, TASK_CREATE_OR_UPDATE, _variant_t(), _variant_t(), TASK_LOGON_INTERACTIVE_TOKEN, _variant_t(L""), &pRegisteredTask);
- //hr = pRootFolder->RegisterTaskDefinition(_bstr_t(szAppName),pTask,TASK_CREATE_OR_UPDATE, _variant_t(),_variant_t(),TASK_LOGON_NONE,_variant_t(L""),&pRegisteredTask);
- if(IsUserAdmin())
- hr = pRootFolder->RegisterTaskDefinition(_bstr_t(szAppName), pTask, TASK_CREATE_OR_UPDATE, _variant_t(L"Builtin\\Administrators"), _variant_t(), TASK_LOGON_GROUP, _variant_t(L""), &pRegisteredTask);
- else
- hr = pRootFolder->RegisterTaskDefinition(_bstr_t(szAppName), pTask, TASK_CREATE_OR_UPDATE, _variant_t(), _variant_t(), TASK_LOGON_INTERACTIVE_TOKEN, _variant_t(L""), &pRegisteredTask);
- if (SUCCEEDED(hr))
- {
- IRunningTask* pRunningTask=NULL;
- VARIANT param;
- param.vt = VT_EMPTY;
- hr = pRegisteredTask->Run(param, &pRunningTask);
- // hr = pRegisteredTask->RunEx(param, TASK_RUN_IGNORE_CONSTRAINTS, NULL, NULL, &pRunningTask);
- if (SUCCEEDED(hr))
- {
-
- }
- pRegisteredTask->Release();
- }
-
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- }
- pTask->Release();
- }
- }
- pRootFolder->Release();
- }
- }
- pService->Release();
- }
-
- }
- CoUninitialize();
- }
-
- }
- HRESULT hr = S_OK;
- ITaskScheduler* pITS;
- hr = CoInitialize(NULL);
- if (SUCCEEDED(hr))
- {
- hr = CoInitializeSecurity(
- NULL,
- -1,
- NULL,
- NULL,
- RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
- RPC_C_IMP_LEVEL_IMPERSONATE,
- NULL,
- 0,
- NULL
- );
- hr = CoCreateInstance(CLSID_CTaskScheduler,
- NULL,
- CLSCTX_INPROC_SERVER,
- IID_ITaskScheduler,
- (void**)&pITS);
- if (SUCCEEDED(hr))
- {
- ITask* pITask;
- IPersistFile* pIPersistFile;
- pITS->Delete(szAppName);
- hr = pITS->NewWorkItem(szAppName, // Name of task
- CLSID_CTask, // Class identifier
- IID_ITask, // Interface identifier
- (IUnknown**)&pITask); // Address of task
- pITS->Release(); // Release object
- if (hr == S_OK)
- {
- pITask->
- hr = pITask->QueryInterface(IID_IPersistFile,
- (void**)&pIPersistFile);
- pITask->Release();
- if (hr == S_OK)
- {
- hr = pIPersistFile->Save(NULL, TRUE);
- pIPersistFile->Release();
- }
- }
- }
- CoUninitialize();
- }
- #endif
-
- #ifndef _DEBUG
- extern "C" void WinMainCRTStartup()
- {
- LPWSTR lpCmdLine = GetCommandLine();
- int iLen = lstrlen(lpCmdLine);
- int flag = 0;
-
- for (int i = 0; i < iLen; i++)
- {
- if (lpCmdLine[i] == L'\"')
- {
- ++flag;
- }
- else if (flag == 2)
- {
- lpCmdLine = &lpCmdLine[i + 1];
- break;
- }
- else if (lpCmdLine[i] == L' ' && flag == 0)
- {
- lpCmdLine = &lpCmdLine[i + 1];
- break;
- }
- }
-
- if (lpCmdLine[0] == L'c') ////打开控制面板
- {
- CloseHandle(pShellExecute(NULL, L"open", L"control.exe", &lpCmdLine[1], NULL, SW_SHOW));
- ExitProcess(0);
- }
- else if (lpCmdLine[0] == L'o') //用SHELLEXECUTE打开
- {
- CloseHandle(pShellExecute(NULL, L"open", &lpCmdLine[1], NULL, NULL, SW_SHOW));
- ExitProcess(0);
- }
- else if (lpCmdLine[0] == L's') //打开任务计划
- {
- CloseHandle(pShellExecute(NULL, L"open", L"schtasks", &lpCmdLine[1], NULL, SW_HIDE));
- ExitProcess(0);
- }
-
- if (IsUserAdmin())
- {
- // lpServiceName = (LPWSTR)szAppName;
- InitService();
- SERVICE_TABLE_ENTRY st[] =
- {
- {(LPWSTR)szAppName, (LPSERVICE_MAIN_FUNCTION)ServiceMain},
- {NULL, NULL}
- };
- if (lstrcmpi(lpCmdLine, L"/install") == 0)
- {
- InstallService();
- ExitProcess(0);
- }
- else if (lstrcmpi(lpCmdLine, L"/uninstall") == 0)
- {
- UninstallService();
- ExitProcess(0);
- }
- else if (lstrcmpi(lpCmdLine, L"/start") == 0)
- {
- ServiceCtrlStart();
- ExitProcess(0);
- }
- else if (lstrcmpi(lpCmdLine, L"/stop") == 0)
- {
- ServiceCtrlStop();
- ExitProcess(0);
- }
-
- if (ServiceRunState() != SERVICE_RUNNING)
- {
- if (IsServiceInstalled())
- {
- if (ServiceRunState() == SERVICE_STOPPED)
- ServiceCtrlStart();
- StartServiceCtrlDispatcher(st);
- ExitProcess(0);
- }
- }
-
- ServiceCtrlStop();
- }
- #else
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
-
- if (lpCmdLine[0] == L'c') ////打开控制面板
- {
- CloseHandle(pShellExecute(NULL, L"open", L"control.exe", &lpCmdLine[1], NULL, SW_SHOW));
- return 0;
- }
- else if (lpCmdLine[0] == L'o') //用SHELLEXECUTE打开
- {
- CloseHandle(pShellExecute(NULL, L"open", &lpCmdLine[1], NULL, NULL, SW_SHOW));
- return 0;
- }
- else if (lpCmdLine[0] == L's') //打开任务计划
- {
- CloseHandle(pShellExecute(NULL, L"open", L"schtasks", &lpCmdLine[1], NULL, SW_HIDE));
- return 0;
- }
-
- if (IsUserAdmin())
- {
- // lpServiceName = (LPWSTR)szAppName;
- InitService();
- SERVICE_TABLE_ENTRY st[] =
- {
- {(LPWSTR)szAppName, (LPSERVICE_MAIN_FUNCTION)ServiceMain},
- {NULL, NULL}
- };
- if (lstrcmpi(lpCmdLine, L"/install") == 0)
- {
- InstallService();
- return 0;
- }
- else if (lstrcmpi(lpCmdLine, L"/uninstall") == 0)
- {
- UninstallService();
- return 0;
- }
- else if (lstrcmpi(lpCmdLine, L"/start") == 0)
- {
- ServiceCtrlStart();
- return 0;
- }
- else if (lstrcmpi(lpCmdLine, L"/stop") == 0)
- {
- ServiceCtrlStop();
- return 0;
- }
-
- if (ServiceRunState() != SERVICE_RUNNING)
- {
- if (IsServiceInstalled())
- {
- if (ServiceRunState() == SERVICE_STOPPED)
- ServiceCtrlStart();
- StartServiceCtrlDispatcher(st);
- return 0;
- }
- }
-
- ServiceCtrlStop();
- }
- #endif
- while (hTray == NULL)
- {
- hTray = FindWindow(szShellTray, NULL);
- if (hTray == NULL)
- Sleep(100);
- }
-
- hInst = GetModuleHandle(NULL); // 将实例句柄存储在全局变量中
- ReadReg();
- /*
- typedef WINUSERAPI DWORD WINAPI RTLGETVERSION(PRTL_OSVERSIONINFOW lpVersionInformation);
- rovi.dwOSVersionInfoSize = sizeof(rovi);
- RTLGETVERSION *RtlGetVersion = (RTLGETVERSION*)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion");
- if (RtlGetVersion)
- RtlGetVersion(&rovi);
- */
- hMutex = CreateMutex(NULL, TRUE, L"_TrayS_");
-
- if (hMutex != NULL)
- {
- if (ERROR_ALREADY_EXISTS == GetLastError())
- {
- CloseHandle(hMutex);
- if (lpCmdLine[0] != L't')
- {
- if (FindWindow(NULL, szAppName))
- #ifndef _DEBUG
- ExitProcess(0);
- #else
- return 0;
- #endif
- EnumWindows((WNDENUMPROC)FindWindowFunc, 0);
- }
- }
- else
- {
- iMain = LoadIcon(hInst, MAKEINTRESOURCE(IDI_TRAYS));
- hDwmapi = LoadLibrary(L"dwmapi.dll");
-
- if (hDwmapi)
- {
- pDwmGetWindowAttribute = (pfnDwmGetWindowAttribute)GetProcAddress(hDwmapi, "DwmGetWindowAttribute");
- }
-
- SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
-
- if (TraySave.bMonitorTemperature)
- LoadTemperatureDLL();
-
- pProcessTime = NULL;
- EnableDebugPrivilege(TRUE);
- SYSTEM_INFO si;
- GetSystemInfo(&si);
- dNumProcessor = si.dwNumberOfProcessors;
-
- if (dNumProcessor == 0)
- dNumProcessor = 1;
-
- ppmu[0] = &pmu[0];
- ppmu[1] = &pmu[1];
- ppmu[2] = &pmu[2];
- ppcu[0] = &pcu[0];
- ppcu[1] = &pcu[1];
- ppcu[2] = &pcu[2];
- g_hHeapWindowInfo = HeapCreate(NULL, 0, 0);
- // 执行应用程序初始化:
- if (!InitInstance(hInst, 0))
- {
- #ifndef _DEBUG
- ExitProcess(0);
- #else
- return 0;
- #endif
- }
- MSG msg;
- // 主消息循环:
- while (GetMessage(&msg, nullptr, 0, 0))
- {
- if (!IsDialogMessage(hMain, &msg) && !IsDialogMessage(hSetting, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
-
- if (IsWindow(hSetting))
- DestroyWindow(hSetting);
- CloseTaskBar();
- if (IsWindow(hMain))
- DestroyWindow(hMain);
- pShell_NotifyIcon(NIM_DELETE, &nid);
- DestroyIcon(iMain);
- DeleteObject(hFont);
- //free(ipinfo);
- FreeLibrary(hDwmapi);
- if (hIphlpapi)
- FreeLibrary(hIphlpapi);
- if (hOleacc)
- FreeLibrary(hOleacc);
- if (hPDH)
- FreeLibrary(hPDH);
- HeapFree(GetProcessHeap(), 0, mi);
- HeapFree(GetProcessHeap(), 0, piaa);
- HeapFree(GetProcessHeap(), 0, traffic);
- HeapDestroy(g_hHeapWindowInfo);
- if (hMutex)
- CloseHandle(hMutex);
- FreeTemperatureDLL();
- if (bResetRun)
- RunProcess(NULL, NULL);
- }
- }
-
- // 初始化全局字符串
- // LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- // LoadStringW(hInstance, IDC_TRAYS, szWindowClass, MAX_LOADSTRING);
- ExitProcess((UINT)0);
- }
- //
- // 函数: InitInstance(HINSTANCE, int)
- //
- // 目标: 保存实例句柄并创建主窗口
- //
- // 注释:
- //
- // 在此函数中,我们在全局变量中保存实例句柄并
- // 创建和显示主程序窗口。
- //
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- hMain = ::CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)MainProc);
- if (!hMain)
- {
- return FALSE;
- }
- ChangeWindowMessageFilter(WM_TRAYS, MSGFLT_ADD);
- ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
- ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
- //////////////////////////////////////////////////////////////////////////////////设置通知栏图标
- nid.cbSize = sizeof NOTIFYICONDATA;
- nid.uID = WM_IAWENTRAY;
- nid.hWnd = hMain;
- nid.hIcon = iMain;
- nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
- nid.uCallbackMessage = WM_IAWENTRAY;
- // nid.dwInfoFlags = NIIF_INFO;
- LoadString(hInst, IDS_TIPS, nid.szTip, 88);
- if (TraySave.bTrayIcon)
- pShell_NotifyIcon(NIM_ADD, &nid);
-
- MemoryStatusEx.dwLength = sizeof MEMORYSTATUSEX;
- ////////////////////////////////////////////////////////////当前DPI
- HDC hdc = GetDC(hMain);
- iDPI = GetDeviceCaps(hdc, LOGPIXELSY);
- ::ReleaseDC(hMain, hdc);
- if (TraySave.bMonitor)
- {
- AdjustWindowPos();
- }
- if (TraySave.aMode[0] != ACCENT_DISABLED || TraySave.aMode[1] != ACCENT_DISABLED)
- SetTimer(hMain, 3, TraySave.FlushTime, NULL);
- SetTimer(hMain, 6, 1000, NULL);
- SetTimer(hMain, 11, 6000, NULL);
- // ShowWindow(hMain,SW_SHOW);
- return TRUE;
- }
-
- BOOL Find(IAccessible *paccParent, int iRole, IAccessible **paccChild) //查找任务图标UI
- {
- HRESULT hr;
- long numChildren;
- unsigned long numFetched;
- VARIANT varChild;
- int indexCount;
- IAccessible *pChild = NULL;
- IEnumVARIANT *pEnum = NULL;
- IDispatch *pDisp = NULL;
- BOOL found = false;
- //Get the IEnumVARIANT interface
- hr = paccParent->QueryInterface(IID_IEnumVARIANT, (PVOID *)&pEnum);
- if (pEnum)
- pEnum->Reset();
- // Get child count
- paccParent->get_accChildCount(&numChildren);
- for (indexCount = 1; indexCount <= numChildren && !found; indexCount++)
- {
- pChild = NULL;
- if (pEnum)
- hr = pEnum->Next(1, &varChild, &numFetched);
- else
- {
- varChild.vt = VT_I4;
- varChild.lVal = indexCount;
- }
- if (varChild.vt == VT_I4)
- {
- pDisp = NULL;
- hr = paccParent->get_accChild(varChild, &pDisp);
- }
- else
- pDisp = varChild.pdispVal;
- if (pDisp)
- {
- hr = pDisp->QueryInterface(IID_IAccessible, (void **)&pChild);
- hr = pDisp->Release();
- }
- if (pChild)
- {
- VariantInit(&varChild);
- varChild.vt = VT_I4;
- varChild.lVal = CHILDID_SELF;
- *paccChild = pChild;
- }
- VARIANT varState;
- pChild->get_accState(varChild, &varState);
- if ((varState.intVal & STATE_SYSTEM_INVISIBLE) == 0)
- {
- VARIANT varRole;
- pChild->get_accRole(varChild, &varRole);
- if (varRole.lVal == iRole)
- {
- paccParent->Release();
- found = true;
- break;
- }
- }
- if (!found && pChild)
- {
- // found = Find(pCAcc, iRole, paccChild);
- // if (*paccChild != pCAcc)
- pChild->Release();
- }
- }
- if (pEnum)
- pEnum->Release();
- return found;
- }
-
- int oleft = 0, otop = 0;
- void SetTaskBarPos(HWND hTaskListWnd, HWND hTrayWnd, HWND hTaskWnd, HWND hReBarWnd, BOOL bMainTray) //设置任务栏图标位置
- {
- if (hOleacc == NULL)
- {
- hOleacc = LoadLibrary(L"oleacc.dll");
- if (hOleacc)
- {
- AccessibleObjectFromWindowT = (pfnAccessibleObjectFromWindow)GetProcAddress(hOleacc, "AccessibleObjectFromWindow");
- AccessibleChildrenT = (pfnAccessibleChildren)GetProcAddress(hOleacc, "AccessibleChildren");
- }
- }
-
- if (hOleacc == NULL)
- return;
- IAccessible *pAcc = NULL;
- AccessibleObjectFromWindowT(hTaskListWnd, OBJID_WINDOW, IID_IAccessible, (void **)&pAcc);
- IAccessible *paccChlid = NULL;
-
- if (pAcc)
- {
- if (Find(pAcc, 22, &paccChlid) == FALSE)
- {
- return;
- }
- }
- else
- return;
-
- long childCount;
- long returnCount;
- LONG left, top, width, height;
- LONG ol = 0, ot = 0;
- int tWidth = 0;
- int tHeight = 0;
-
- if (paccChlid)
- {
- if (paccChlid->get_accChildCount(&childCount) == S_OK && childCount != 0)
- {
- VARIANT *pArray = (VARIANT *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof VARIANT *childCount);
- if (AccessibleChildrenT(paccChlid, 0L, childCount, pArray, &returnCount) == S_OK)
- {
- for (int x = 0; x < returnCount; x++)
- {
- VARIANT vtChild = pArray[x];
- VARIANT varState;
- paccChlid->get_accState(vtChild, &varState);
-
- if ((varState.intVal & STATE_SYSTEM_INVISIBLE) == 0)
- {
- VARIANT varRole;
- paccChlid->get_accRole(vtChild, &varRole);
- if (varRole.intVal == 0x2b || varRole.intVal == 0x39)
- {
- paccChlid->accLocation(&left, &top, &width, &height, vtChild);
- if (ol != left)
- {
- tWidth += width;
- ol = left;
- }
- if (ot != top)
- {
- tHeight += height;
- ot = top;
- }
- }
- }
- }
- }
-
- HeapFree(GetProcessHeap(), 0, pArray);
- }
- paccChlid->Release();
- }
- else
- return;
-
- RECT lrc, src, trc;
- GetWindowRect(hTaskListWnd, &lrc);
- GetWindowRect(hTrayWnd, &src);
- GetWindowRect(hTaskWnd, &trc);
- BOOL Vertical = FALSE;
- if (src.right - src.left < src.bottom - src.top)
- Vertical = TRUE;
- SendMessage(hReBarWnd, WM_SETREDRAW, TRUE, 0);
- int lr, tb;
-
- if (Vertical)
- {
- int t = trc.left - src.left;
- int b = src.bottom - trc.bottom;
-
- if (bMainTray && TraySave.bMonitor && TraySave.bMonitorFloat == FALSE)
- {
- if (TraySave.bMonitorLeft == FALSE)
- b += mHeight;
- else
- t += mHeight;
- }
- if (t > b)
- tb = t;
- else
- tb = b;
- }
- else
- {
- int l = trc.left - src.left;
- int r = src.right - trc.right;
-
- if (TraySave.bMonitor && bMainTray && TraySave.bMonitorFloat == FALSE)
- {
- if (TraySave.bMonitorLeft == FALSE)
- r += mWidth;
- else
- l += mWidth;
- }
- if (l > r)
- lr = l;
- else
- lr = r;
- }
-
- int nleft, ntop;
- if ((TraySave.iPos == 2 || (Vertical == FALSE && tWidth >= trc.right - trc.left - lr) || (Vertical && tHeight >= trc.bottom - trc.top - tb)) && TraySave.iPos != 0)
- {
- if (Vertical)
- {
- ntop = trc.bottom - trc.top - tHeight;
- if (TraySave.bMonitorLeft == FALSE && TraySave.bMonitor && bMainTray && TraySave.bMonitorFloat == FALSE)
- ntop -= mHeight + 2;
- }
- else
- {
- nleft = trc.right - trc.left - tWidth;
- if (TraySave.bMonitorLeft == FALSE && TraySave.bMonitor && bMainTray && TraySave.bMonitorFloat == FALSE)
- nleft -= mWidth + 2;
- }
- }
- else if (TraySave.iPos == 0)
- {
- if (TraySave.bMonitorLeft && TraySave.bMonitor && bMainTray && TraySave.bMonitorFloat == FALSE)
- {
- nleft = mWidth;
- ntop = mHeight;
- }
- else
- {
- nleft = 0;
- ntop = 0;
- if (TraySave.bMonitor == FALSE)
- {
- SetTimer(hMain, 11, 1000, NULL);
- }
- }
- }
- else if (TraySave.iPos == 1)
- {
- if (Vertical)
- ntop = src.top + (src.bottom - src.top) / 2 - trc.top - tHeight / 2;
- else
- nleft = src.left + (src.right - src.left) / 2 - trc.left - tWidth / 2;
- if (bMainTray)
- {
- if (Vertical)
- ntop -= 2;
- else
- nleft -= 2;
- }
- }
- if (Vertical)
- {
- if (bMainTray)
- {
- if (otop == 0)
- lrc.top = ntop;
- else
- lrc.top = otop;
- otop = ntop;
- while (ntop != lrc.top)
- {
- if (ntop > lrc.top)
- ++lrc.top;
- else
- --lrc.top;
- SetWindowPos(hTaskListWnd, 0, 0, lrc.top, lrc.right - lrc.left, lrc.bottom - lrc.top, SWP_NOSIZE | SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSENDCHANGING);
- }
- }
- SetWindowPos(hTaskListWnd, 0, 0, ntop, lrc.right - lrc.left, lrc.bottom - lrc.top, SWP_NOSIZE | SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSENDCHANGING);
- }
- else
- {
- if (bMainTray)
- {
- if (oleft == 0)
- lrc.left = nleft;
- else
- lrc.left = oleft;
- oleft = nleft;
- while (nleft != lrc.left)
- {
- if (nleft > lrc.left)
- ++lrc.left;
- else
- --lrc.left;
- SetWindowPos(hTaskListWnd, 0, lrc.left, 0, lrc.right - lrc.left, lrc.bottom - lrc.top, SWP_NOSIZE | SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSENDCHANGING);
- }
- }
- SetWindowPos(hTaskListWnd, 0, nleft, 0, lrc.right - lrc.left, lrc.bottom - lrc.top, SWP_NOSIZE | SWP_ASYNCWINDOWPOS | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSENDCHANGING);
- }
- if (TraySave.iPos != 0)
- SendMessage(hReBarWnd, WM_SETREDRAW, FALSE, 0);
- ShowWindow(hTaskWnd, SW_SHOWNOACTIVATE);
- }
- int otleft, ottop;
- void SetWH()
- {
- mWidth = 0;
- mHeight = 0;
- HDC mdc = GetDC(hMain);
- TraySave.TraybarFont.lfHeight = DPI(TraySave.TraybarFontSize);
- DeleteObject(hFont);
- hFont = CreateFontIndirect(&TraySave.TraybarFont); //创建字体
- HFONT oldFont = (HFONT)SelectObject(mdc, hFont);
- SIZE tSize;
- WCHAR sz[16];
- if (TraySave.bMonitorTraffic)
- {
- if (TraySave.iMonitorSimple == 1)
- ::GetTextExtentPoint(mdc, L"↓:8.88M", lstrlen(L"↓:8.88M"), &tSize);
- else if (TraySave.iMonitorSimple == 2)
- ::GetTextExtentPoint(mdc, L"8.88M", lstrlen(L"8.88M"), &tSize);
- else
- {
- wsprintf(sz, L"%s8.88M", TraySave.szTrafficOut);
- ::GetTextExtentPoint(mdc, sz, lstrlen(sz), &tSize);
- }
- wTraffic = tSize.cx + tSize.cy / 4;
- mWidth += wTraffic;
- mHeight += tSize.cy * 2;
- wHeight = tSize.cy + 1;
- }
- if (TraySave.bMonitorTemperature)
- {
- if (TraySave.iMonitorSimple == 1)
- ::GetTextExtentPoint(mdc, L"88℃", lstrlen(L"88℃"), &tSize);
- else if (TraySave.iMonitorSimple == 2)
- ::GetTextExtentPoint(mdc, L"88", lstrlen(L"88"), &tSize);
- else
- {
- wsprintf(sz, L"%s88%s", TraySave.szTemperatureGPU, TraySave.szTemperatureGPUUnit);
- ::GetTextExtentPoint(mdc, sz, lstrlen(sz), &tSize);
- }
- wTemperature = tSize.cx + tSize.cy / 4;
- mWidth += wTemperature;
- wHeight = tSize.cy + 1;
- if (bRing0)
- mHeight += tSize.cy * 2;
- else
- mHeight += tSize.cy;
- }
- if (TraySave.bMonitorUsage)
- {
- if (TraySave.iMonitorSimple == 1)
- ::GetTextExtentPoint(mdc, L"88%", lstrlen(L"88%"), &tSize);
- else if (TraySave.iMonitorSimple == 2)
- ::GetTextExtentPoint(mdc, L"88", lstrlen(L"88"), &tSize);
- else
- {
- wsprintf(sz, L"%s88%s", TraySave.szUsageMEM, TraySave.szUsageMEMUnit);
- ::GetTextExtentPoint(mdc, sz, lstrlen(sz), &tSize);
- }
- wUsage = tSize.cx + tSize.cy / 4;
- mWidth += wUsage;
- wHeight = tSize.cy + 1;
- mHeight += tSize.cy * 2;
- }
- SelectObject(mdc, oldFont);
- ReleaseDC(hMain, mdc);
- ottop = -1;
- otleft = -1;
- AdjustWindowPos();
- }
- void AdjustWindowPos() //设置信息窗口位置大小
- {
- if (IsWindow(hTaskBar) == FALSE)
- OpenTaskBar();
- if (TraySave.bMonitorFloat)
- {
- RECT ScreenRect;
- GetScreenRect(hTaskBar, &ScreenRect, FALSE);
- if (TraySave.dMonitorPoint.x + mWidth > ScreenRect.right)
- TraySave.dMonitorPoint.x = ScreenRect.right - mWidth;
- if (TraySave.dMonitorPoint.y + wHeight * 2 > ScreenRect.bottom)
- TraySave.dMonitorPoint.y = ScreenRect.bottom - wHeight * 2;
- SetWindowPos(hTaskBar, HWND_TOPMOST, TraySave.dMonitorPoint.x, TraySave.dMonitorPoint.y, mWidth, wHeight * 2, SWP_NOACTIVATE);
- return;
- }
- RECT rrc, trc;
- GetWindowRect(hReBarWnd, &rrc);
- GetWindowRect(hTaskWnd, &trc);
- if (rrc.right - rrc.left > rrc.bottom - rrc.top)
- VTray = FALSE;
- else
- VTray = TRUE;
- if (VTray == FALSE)
- {
- int nleft;
- if (TraySave.bMonitorLeft)
- nleft = trc.left - rrc.left;
- else
- nleft = trc.right - trc.left - mWidth + (trc.left - rrc.left);
- int h = wHeight * 2;
- int ntop;
- BOOL sTray = FALSE;
- if (rrc.bottom - rrc.top < h)
- {
- sTray = TRUE;
- h = rrc.bottom - rrc.top - 2;
- ntop = 1;
- }
- else
- ntop = (trc.bottom - trc.top - h) / 2;
- if (nleft != otleft || ottop != ntop)
- {
- HDC hdc = GetDC(hTaskBar);
- RECT crc;
- GetClientRect(hTaskBar, &crc);
- HBRUSH hb = CreateSolidBrush(RGB(0, 0, 0));
- FillRect(hdc, &crc, hb);
- DeleteObject(hb);
- ReleaseDC(hTaskBar, hdc);
- otleft = nleft;
- ottop = ntop;
- MoveWindow(hTaskBar, nleft, ntop, mWidth, h, FALSE);
- ::InvalidateRect(hTaskBar, NULL, TRUE);
- }
- }
- else
- {
- int ntop;
- if (TraySave.bMonitorLeft)
- ntop = trc.top - rrc.top;
- else
- ntop = trc.bottom - trc.top - mHeight + (trc.top - rrc.top);
- int nleft = 2;
- int w = trc.right - trc.left - 4;
- if (ntop != ottop || otleft != w)
- {
- HDC hdc = GetDC(hTaskBar);
- RECT crc;
- GetClientRect(hTaskBar, &crc);
- HBRUSH hb = CreateSolidBrush(RGB(0, 0, 0));
- FillRect(hdc, &crc, hb);
- DeleteObject(hb);
- ReleaseDC(hTaskBar, hdc);
- ottop = ntop;
- otleft = w;
- MoveWindow(hTaskBar, nleft, ntop, w, mHeight, FALSE);
- ::InvalidateRect(hTaskBar, NULL, TRUE);
- }
- }
- }
-
- DWORD dwIPSize = 0;
- DWORD dwMISize = 0;
- INT_PTR CALLBACK TaskTipsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) //提示信息窗口过程
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_MOUSEMOVE:
- {
- POINT pt;
- pt.x = GET_X_LPARAM(lParam);
- pt.y = GET_Y_LPARAM(lParam);
- RECT rc;
- GetClientRect(hDlg, &rc);
- rc.top = nTraffic * wTipsHeight;
- rc.bottom = (nTraffic + 6) * wTipsHeight;
- rc.left = rc.right * 100 / 160;
- rc.right = rc.right * 100 / 148;
- if (PtInRect(&rc, pt))
- {
- inTipsProcessX = TRUE;
- ::InvalidateRect(hDlg, NULL, TRUE);
- }
- else
- {
- inTipsProcessX = FALSE;
- }
- }
- break;
- case WM_LBUTTONDOWN:
- {
- POINT pt;
- pt.x = GET_X_LPARAM(lParam);
- pt.y = GET_Y_LPARAM(lParam);
- if (pt.y < nTraffic * wTipsHeight)
- RunProcess(NULL, szNetCpl);
- else if (pt.y < (nTraffic + 6) * wTipsHeight)
- {
- RECT rc;
- GetClientRect(hDlg, &rc);
- rc.left = rc.right * 100 / 160;
- rc.right = rc.right * 100 / 148;
- if (PtInRect(&rc, pt))
- {
-
- int x = 0;
- if (wTipsHeight != 0)
- x = (pt.y / wTipsHeight) - nTraffic;
- DWORD pid;
- if (x < 3)
- pid = ppcu[x]->dwProcessID;
- else
- pid = ppmu[x - 3]->dwProcessID;
- HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
- if (hProc)
- {
- TerminateProcess(hProc, 0);
- CloseHandle(hProc);
- inTipsProcessX = FALSE;
- GetCursorPos(&pt);
- SetCursorPos(pt.x + 88, pt.y);
- }
- }
- else
- RunProcess(NULL, szTaskmgr);
- }
- else
- RunProcess(NULL, szPowerCpl);
- return TRUE;
- }
- break;
- case WM_MOUSELEAVE:
- {
- POINT pt;
- GetCursorPos(&pt);
- if (WindowFromPoint(pt) != hTaskBar)
- {
- if (pProcessTime != NULL)
- {
- HeapFree(GetProcessHeap(), 0, pProcessTime);
- pProcessTime = NULL;
- }
- DestroyWindow(hTaskTips);
- SetTimer(hMain, 11, 1000, NULL);
- }
- }
- break;
- case WM_ERASEBKGND:
- HDC hdc = (HDC)wParam; //BeginPaint(hDlg, &ps);
- RECT rc, crc;
- GetClientRect(hDlg, &rc);
- crc = rc;
- HDC mdc = CreateCompatibleDC(hdc);
- HBITMAP hMemBmp = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
- HBITMAP oldBmp = (HBITMAP)SelectObject(mdc, hMemBmp);
- // if (bErasebkgnd)
- {
- TraySave.TipsFont.lfHeight = TraySave.TipsFontSize;
- HFONT hTipsFont = CreateFontIndirect(&TraySave.TipsFont); //创建字体
- HFONT oldFont = (HFONT)SelectObject(mdc, hTipsFont);
- WCHAR sz[64];
- SetBkMode(mdc, TRANSPARENT);
- COLORREF rgb;
- rgb = RGB(192, 192, 192);
- SetTextColor(mdc, rgb);
- rc.bottom = wTipsHeight;
- HBRUSH hb = CreateSolidBrush(RGB(22, 22, 22));
- for (int i = 0; i < nTraffic / 2 + 4; i++)
- {
- FillRect(mdc, &rc, hb);
- OffsetRect(&rc, 0, wTipsHeight * 2);
- }
- DeleteObject(hb);
- HPEN hp = CreatePen(PS_DOT, 1, RGB(98, 98, 98));
- HPEN oldpen = (HPEN)SelectObject(mdc, hp);
- MoveToEx(mdc, crc.right * 10 / 23, 0, NULL);
- LineTo(mdc, crc.right * 10 / 23, wTipsHeight * nTraffic);
- MoveToEx(mdc, crc.right * 7 / 10, 0, NULL);
- LineTo(mdc, crc.right * 7 / 10, wTipsHeight * nTraffic);
- MoveToEx(mdc, crc.right * 85 / 100, 0, NULL);
- LineTo(mdc, crc.right * 85 / 100, wTipsHeight * nTraffic);
-
- MoveToEx(mdc, crc.right * 100 / 124, wTipsHeight * nTraffic, NULL);
- LineTo(mdc, crc.right * 100 / 124, wTipsHeight * (nTraffic + 6));
- MoveToEx(mdc, crc.right * 100 / 148, wTipsHeight * nTraffic, NULL);
- LineTo(mdc, crc.right * 100 / 148, wTipsHeight * (nTraffic + 6));
- MoveToEx(mdc, crc.right * 100 / 160, wTipsHeight * nTraffic, NULL);
- LineTo(mdc, crc.right * 100 / 160, wTipsHeight * (nTraffic + 6));
- MoveToEx(mdc, 0, wTipsHeight * nTraffic, NULL);
- LineTo(mdc, crc.right, wTipsHeight * nTraffic);
- MoveToEx(mdc, 0, wTipsHeight * (nTraffic + 3), NULL);
- LineTo(mdc, crc.right, wTipsHeight * (nTraffic + 3));
- MoveToEx(mdc, 0, wTipsHeight * (nTraffic + 6), NULL);
- LineTo(mdc, crc.right, wTipsHeight * (nTraffic + 6));
- SelectObject(mdc, oldpen);
- DeleteObject(hp);
- rc.bottom = wTipsHeight;
- rc.top = 0;
- int cx;
- if (wTipsHeight < 24)
- cx = 16;
- else if (wTipsHeight < 32)
- cx = 24;
- else if (wTipsHeight < 48)
- cx = 32;
- else if (wTipsHeight < 64)
- cx = 48;
- else if (wTipsHeight < 128)
- cx = 64;
- else
- cx = 128;
- // OffsetRect(&rc, 0, DPI(16)*3);
- //PIP_ADAPTER_INFO pai = &ipinfo[0];
- // PIP_ADAPTER_ADDRESSES paa = &piaa[0];
- for (int i = 0; i < nTraffic; i++)
- {
- rc.left = 2; // +wTipsHeight;
- DrawText(mdc, traffic[i].FriendlyName, lstrlen(traffic[i].FriendlyName), &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- #if 0
- HICON hIcon = GetIconForCSIDL(CSIDL_CONNECTIONS);
-
- UINT size = MAKELPARAM(cx, cx);
- WCHAR szGuid[64]; // = L":::";
- MultiByteToWideChar(CP_ACP, 0, traffic[i].AdapterName, 64, szGuid , 64);
- SHFILEINFO shfi;
- SHGetFileInfo(szGuid, 0, &shfi, sizeof(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
- hIcon = shfi.hIcon;
-
- if (wTipsHeight >= 16)
- DrawIconEx(mdc, 2, rc.top + (rc.bottom - rc.top - cx) / 2, hIcon, cx, cx, 0, NULL, DI_NORMAL);
- else
- DrawIconEx(mdc, 1, rc.top + 1, hIcon, wTipsHeight - 2, wTipsHeight - 2, 0, NULL, DI_NORMAL);
- DestroyIcon(hIcon);
- #endif
- rc.left = crc.right * 10 / 23;
- rc.right = crc.right * 7 / 10;
- DrawText(mdc, traffic[i].IP4, lstrlen(traffic[i].IP4), &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- int f_in_byte = traffic[i].in_byte;
- if (traffic[i].in_byte < 1000)
- wsprintf(sz, L"↓:%db", traffic[i].in_byte);
- else if (traffic[i].in_byte < 1000000)
- {
- int k_in_byte = f_in_byte / 1000;
- if (k_in_byte >= 100)
- wsprintf(sz, L"↓:%dk", k_in_byte);
- else if (k_in_byte >= 10)
- wsprintf(sz, L"↓:%d.%dk", k_in_byte, f_in_byte / 100 - k_in_byte * 10);
- else
- wsprintf(sz, L"↓:%d.%dk", k_in_byte, f_in_byte / 10 - k_in_byte * 100);
- }
- else if (traffic[i].in_byte < 1000000000)
- {
- int m_in_byte = f_in_byte / 1000000;
- if (m_in_byte >= 100)
- wsprintf(sz, L"↓:%dm", m_in_byte);
- else if (m_in_byte >= 10)
- wsprintf(sz, L"↓:%d.%dm", m_in_byte, f_in_byte / 100000 - m_in_byte * 10);
- else
- wsprintf(sz, L"↓:%d.%dm", m_in_byte, f_in_byte / 10000 - m_in_byte * 100);
- }
- else
- {
- int g_in_byte = f_in_byte / 1000000000;
- if (g_in_byte >= 100)
- wsprintf(sz, L"↓:%dG", g_in_byte);
- else if (g_in_byte >= 10)
- wsprintf(sz, L"↓:%d.%dG", g_in_byte, f_in_byte / 100000000 - g_in_byte * 10);
- else
- wsprintf(sz, L"↓:%d.%dG", g_in_byte, f_in_byte / 10000000 - g_in_byte * 100);
- }
- rc.left = crc.right * 7 / 10 + 2;
- rc.right += crc.right;
- DrawText(mdc, sz, lstrlen(sz), &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- int f_out_byte = traffic[i].out_byte;
- if (traffic[i].out_byte < 1000)
- wsprintf(sz, L"↑:%db", traffic[i].out_byte);
- else if (traffic[i].out_byte < 1000000)
- {
- int k_out_byte = f_out_byte / 1000;
- if (k_out_byte >= 100)
- wsprintf(sz, L"↑:%dk", k_out_byte);
- else if (k_out_byte >= 10)
- wsprintf(sz, L"↑:%d.%dk", k_out_byte, f_out_byte / 100 - k_out_byte * 10);
- else
- wsprintf(sz, L"↑:%d.%dk", k_out_byte, f_out_byte / 10 - k_out_byte * 100);
- }
- else if (traffic[i].out_byte < 1000000000)
- {
- int m_out_byte = f_out_byte / 1000000;
- if (m_out_byte >= 100)
- wsprintf(sz, L"↑:%dm", m_out_byte);
- else if (m_out_byte >= 10)
- wsprintf(sz, L"↑:%d.%dm", m_out_byte, f_out_byte / 100000 - m_out_byte * 10);
- else
- wsprintf(sz, L"↑:%d.%dm", m_out_byte, f_out_byte / 10000 - m_out_byte * 100);
- }
- else
- {
- int g_out_byte = f_out_byte / 1000000000;
- if (g_out_byte >= 100)
- wsprintf(sz, L"↑:%dg", g_out_byte);
- else if (g_out_byte >= 10)
- wsprintf(sz, L"↑:%d.%dg", g_out_byte, f_out_byte / 100000000 - g_out_byte * 10);
- else
- wsprintf(sz, L"↑:%d.%dg", g_out_byte, f_out_byte / 10000000 - g_out_byte * 100);
- }
- rc.left = crc.right * 85 / 100 + 2;
- DrawText(mdc, sz, lstrlen(sz), &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- OffsetRect(&rc, 0, wTipsHeight);
- }
- rc.left = 2; // +wTipsHeight;
- rc.right = crc.right - 2;
- POINT pt;
- GetCursorPos(&pt);
- ScreenToClient(hDlg, &pt);
- for (int i = 0; i < 3; i++)
- {
- SetTextColor(mdc, RGB(192, 192, 0));
- DrawText(mdc, ppcu[i]->szExe, lstrlen(ppcu[i]->szExe), &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- #if 0
- HICON hIcon = OpenProcessIcon(ppcu[i]->dwProcessID,cx);
- if(wTipsHeight>=16)
- DrawIconEx(mdc, 2, rc.top + (rc.bottom - rc.top - cx) / 2, hIcon, cx, cx, 0, NULL, DI_NORMAL);
- else
- DrawIconEx(mdc, 1, rc.top+1, hIcon, wTipsHeight-2, wTipsHeight-2, 0, NULL, DI_NORMAL);
- DestroyIcon(hIcon);
- #endif
- int iCpuUsage = int(ppcu[i]->fCpuUsage * 100);
- wsprintf(sz, L"%d.%.2d%%", iCpuUsage / 100, iCpuUsage % 100);
- DrawText(mdc, sz, lstrlen(sz), &rc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
- RECT cr = rc;
- cr.left = crc.right * 100 / 148;
- cr.right = crc.right * 8 / 10;
- wsprintf(sz, L"%d", ppcu[i]->dwProcessID);
- DrawText(mdc, sz, lstrlen(sz), &cr, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- cr.left = crc.right * 100 / 160;
- cr.right = crc.right * 100 / 148;
- if (PtInRect(&cr, pt))
- SetTextColor(mdc, RGB(255, 255, 255));
- DrawText(mdc, L"X", 1, &cr, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- OffsetRect(&rc, 0, wTipsHeight);
- }
- for (int i = 0; i < 3; i++)
- {
- SetTextColor(mdc, RGB(0, 192, 192));
- DrawText(mdc, ppmu[i]->szExe, lstrlen(ppmu[i]->szExe), &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- #if 0
- HICON hIcon = OpenProcessIcon(ppmu[i]->dwProcessID,cx);
- if(wTipsHeight>=16)
- DrawIconEx(mdc, 2, rc.top+(rc.bottom-rc.top-cx)/2, hIcon, cx, cx, 0, NULL, DI_NORMAL);
- else
- DrawIconEx(mdc, 1, rc.top+1, hIcon, wTipsHeight-2, wTipsHeight-2, 0, NULL, DI_NORMAL);
- DestroyIcon(hIcon);
- #endif
- if (ppmu[i]->dwMemUsage >= 1048576000)
- {
- SIZE_T iMemUsage = (ppmu[i]->dwMemUsage * 100 / 1073741824);
- wsprintf(sz, L"%d.%.2dGB", iMemUsage / 100, iMemUsage % 100);
- }
- else
- {
- SIZE_T iMemUsage = (ppmu[i]->dwMemUsage * 100 / 1048576);
- wsprintf(sz, L"%d.%.2dMB", iMemUsage / 100, iMemUsage % 100);
- }
-
- DrawText(mdc, sz, lstrlen(sz), &rc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
- RECT cr = rc;
- cr.left = crc.right * 100 / 148;
- cr.right = crc.right * 8 / 10;
- wsprintf(sz, L"%d", ppmu[i]->dwProcessID);
- DrawText(mdc, sz, lstrlen(sz), &cr, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- cr.left = crc.right * 100 / 160;
- cr.right = crc.right * 100 / 148;
-
- if (PtInRect(&cr, pt))
- SetTextColor(mdc, RGB(255, 255, 255));
- DrawText(mdc, L"X", 1, &cr, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- OffsetRect(&rc, 0, wTipsHeight);
- }
-
- SetTextColor(mdc, RGB(192, 192, 192));
- #if 0
- HBRUSH hb;
- hb=CreateSolidBrush(RGB(0,38,0););
- FillRect(mdc, &rc, hb);
- DeleteObject(hb);
- #endif
- rc.left = 2;
- rc.right -= 2;
- PROCESSOR_POWER_INFORMATION *pi = (PROCESSOR_POWER_INFORMATION *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROCESSOR_POWER_INFORMATION) * dNumProcessor);
-
- if (pCallNtPowerInformation(ProcessorInformation, NULL, 0, &pi[0], sizeof(PROCESSOR_POWER_INFORMATION) *dNumProcessor) == 0)
- {
- int iCGhz = pi[0].CurrentMhz / 10;
- int iMGhz = pi[0].MaxMhz / 10;
- wsprintf(sz, L"%d个逻辑处理器 当前频率%d.%.2dGHz 最大频率%d.%.2dGHz",
- dNumProcessor, iCGhz / 100, iCGhz % 100, iMGhz / 100, iMGhz % 100);
- }
-
- HeapFree(GetProcessHeap(), 0, pi);
- DrawText(mdc, sz, lstrlen(sz), &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- OffsetRect(&rc, 0, wTipsHeight);
- DWORDLONG iaPage = MemoryStatusEx.ullAvailPageFile * 100 / 1073741824;
- DWORDLONG itPage = MemoryStatusEx.ullTotalPageFile * 100 / 1073741824;
- DWORDLONG ia = MemoryStatusEx.ullAvailPhys * 100 / 1073741824;
- DWORDLONG it = MemoryStatusEx.ullTotalPhys * 100 / 1073741824;
- wsprintf(sz, L"虚拟内存:%d.%.2d/%d.%.2dGB,可用内存:%d.%.2d/%d.%.2dGB",
- iaPage / 100, iaPage % 100, itPage / 100, itPage % 100, ia / 100, ia % 100, it / 100, it % 100);
- DrawText(mdc, sz, lstrlen(sz), &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- DeleteObject(hTipsFont);
- SelectObject(mdc, oldFont);
- }
-
- GetClientRect(hDlg, &rc);
- BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, mdc, 0, 0, SRCCOPY);
- SelectObject(mdc, oldBmp);
- DeleteObject(hMemBmp);
- DeleteDC(mdc);
- return TRUE;
- break;
- }
-
- return (INT_PTR)FALSE;
- }
-
- void GetProcessCpuUsage() //获取进程CPU占用前三
- {
- if (!inTipsProcessX)
- {
- ppcu[0] = &pcu[0];
- ppcu[1] = &pcu[1];
- ppcu[2] = &pcu[2];
- memset(pcu, 0, sizeof pcu);
- pcu[0].fCpuUsage = 0;
- pcu[1].fCpuUsage = 0;
- pcu[2].fCpuUsage = 0;
- }
- DWORD dCurID = GetCurrentProcessId();
- PROCESSENTRY32 pe;
- pe.dwSize = sizeof(PROCESSENTRY32);
- HANDLE hs = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hs != INVALID_HANDLE_VALUE)
- {
- BOOL ret = Process32First(hs, &pe);
- while (ret)
- {
- if (pe.th32ProcessID != dCurID)
- {
- HANDLE hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pe.th32ProcessID);
- if (hProc)
- {
- int n = -1;
- for (int i = 0; i < nProcess + 31; i++)
- {
- if (pProcessTime[i].dwProcessID == pe.th32ProcessID)
- {
- n = i;
- break;
- }
- else if (n == -1 && pProcessTime[i].dwProcessID == NULL)
- n = i;
- }
- FILETIME CreateTime, ExitTime, KernelTime, UserTime;
- if (GetProcessTimes(hProc, &CreateTime, &ExitTime, &KernelTime, &UserTime))
- {
- float nProcCpuPercent = 0;
- BOOL bRetCode = FALSE;
- FILETIME CreateTime, ExitTime, KernelTime, UserTime;
- LARGE_INTEGER lgKernelTime;
- LARGE_INTEGER lgUserTime;
- LARGE_INTEGER lgCurTime;
-
- bRetCode = GetProcessTimes(hProc, &CreateTime, &ExitTime, &KernelTime, &UserTime);
- if (bRetCode)
- {
- lgKernelTime.HighPart = KernelTime.dwHighDateTime;
- lgKernelTime.LowPart = KernelTime.dwLowDateTime;
-
- lgUserTime.HighPart = UserTime.dwHighDateTime;
- lgUserTime.LowPart = UserTime.dwLowDateTime;
-
- lgCurTime.QuadPart = (lgKernelTime.QuadPart + lgUserTime.QuadPart) / 10000;
- if (pProcessTime[n].g_slgProcessTimeOld.QuadPart == 0)
- nProcCpuPercent = 0;
- else
- nProcCpuPercent = (float)((lgCurTime.QuadPart - pProcessTime[n].g_slgProcessTimeOld.QuadPart) * 100 / 1000);
- pProcessTime[n].g_slgProcessTimeOld = lgCurTime;
- pProcessTime[n].dwProcessID = pe.th32ProcessID;
- nProcCpuPercent = nProcCpuPercent / dNumProcessor;
- }
- else
- {
- nProcCpuPercent = 0;
- }
- if (nProcCpuPercent > 100)
- nProcCpuPercent = 0;
- if (!inTipsProcessX)
- {
- PROCESSCPUUSAGE *ppc;
- if (ppcu[0]->fCpuUsage <= nProcCpuPercent)
- {
- ppc = ppcu[2];
- ppcu[2] = ppcu[1];
- ppcu[1] = ppcu[0];
- ppcu[0] = ppc;
- ppcu[0]->dwProcessID = pe.th32ProcessID;
- ppcu[0]->fCpuUsage = nProcCpuPercent;
- lstrcpyn(ppcu[0]->szExe, pe.szExeFile, 24);
- }
- else if (ppcu[1]->fCpuUsage <= nProcCpuPercent)
- {
- ppc = ppcu[2];
- ppcu[2] = ppcu[1];
- ppcu[1] = ppc;
- ppcu[1]->dwProcessID = pe.th32ProcessID;
- ppcu[1]->fCpuUsage = nProcCpuPercent;
- lstrcpyn(ppcu[1]->szExe, pe.szExeFile, 24);
- }
- else if (ppcu[2]->fCpuUsage <= nProcCpuPercent)
- {
- ppcu[2]->dwProcessID = pe.th32ProcessID;
- ppcu[2]->fCpuUsage = nProcCpuPercent;
- lstrcpyn(ppcu[2]->szExe, pe.szExeFile, 24);
- }
- }
- }
- CloseHandle(hProc);
- }
- }
- ret = Process32Next(hs, &pe);
- }
- CloseHandle(hs);
- }
- }
- int GetProcessMemUsage() //获取进程内存占用前三
- {
- if (!inTipsProcessX)
- {
- ppmu[0] = &pmu[0];
- ppmu[1] = &pmu[1];
- ppmu[2] = &pmu[2];
- memset(pmu, 0, sizeof pmu);
- pmu[0].dwMemUsage = 0;
- pmu[1].dwMemUsage = 0;
- pmu[2].dwMemUsage = 0;
- }
- PROCESSENTRY32 pe;
- pe.dwSize = sizeof(PROCESSENTRY32);
- int n = 0;
- HANDLE hs = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hs != INVALID_HANDLE_VALUE)
- {
- BOOL ret = Process32First(hs, &pe);
- while (ret)
- {
- ++n;
- if (lstrcmp(pe.szExeFile, L"Memory Compression") != 0 && !inTipsProcessX)
- {
- HANDLE hProc = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pe.th32ProcessID);
- if (hProc)
- {
- PROCESS_MEMORY_COUNTERS_EX pmc;
- if (GetProcessMemoryInfo(hProc, (PPROCESS_MEMORY_COUNTERS)&pmc, sizeof(pmc)))
- {
- //QueryWorkingSet()
- PROCESSMEMORYUSAGE *ppm;
- if (ppmu[0]->dwMemUsage <= pmc.WorkingSetSize)
- {
- ppm = ppmu[2];
- ppmu[2] = ppmu[1];
- ppmu[1] = ppmu[0];
- ppmu[0] = ppm;
- ppmu[0]->dwProcessID = pe.th32ProcessID;
- ppmu[0]->dwMemUsage = pmc.WorkingSetSize;
- lstrcpyn(ppmu[0]->szExe, pe.szExeFile, 24);
-
- }
- else if (ppmu[1]->dwMemUsage <= pmc.WorkingSetSize)
- {
- ppm = ppmu[2];
- ppmu[2] = ppmu[1];
- ppmu[1] = ppm;
- ppmu[1]->dwProcessID = pe.th32ProcessID;
- ppmu[1]->dwMemUsage = pmc.WorkingSetSize;
- lstrcpyn(ppmu[1]->szExe, pe.szExeFile, 24);
- }
- else if (ppmu[2]->dwMemUsage <= pmc.WorkingSetSize)
- {
- ppmu[2]->dwProcessID = pe.th32ProcessID;
- ppmu[2]->dwMemUsage = pmc.WorkingSetSize;
- lstrcpyn(ppmu[2]->szExe, pe.szExeFile, 24);
- }
- }
- CloseHandle(hProc);
- }
- }
- ret = Process32Next(hs, &pe);
- }
- CloseHandle(hs);
- }
-
- return n;
- }
-
- void DrawTraffic(HDC mdc, LPRECT lpRect, DWORD dwByte, BOOL bInOut)
- {
- WCHAR szInS[] = L"↓:";
- WCHAR szInS2[] = L"";
- WCHAR szOutS[] = L"↑:";
- WCHAR szOutS2[] = L"";
- WCHAR *szT;
- if (bInOut)
- {
- if (TraySave.iMonitorSimple == 1)
- szT = szInS;
- else if (TraySave.iMonitorSimple == 2)
- szT = szInS2;
- else
- szT = TraySave.szTrafficIn;
- }
- else
- {
- if (TraySave.iMonitorSimple == 1)
- szT = szOutS;
- else if (TraySave.iMonitorSimple == 2)
- szT = szOutS2;
- else
- szT = TraySave.szTrafficOut;
- }
- WCHAR sz[24];
- COLORREF rgb;
- if (dwByte < TraySave.dNumValues[0])
- rgb = TraySave.cMonitorColor[1];
- else if (dwByte < TraySave.dNumValues[1])
- rgb = TraySave.cMonitorColor[2];
- else
- rgb = TraySave.cMonitorColor[3];
- SetTextColor(mdc, rgb);
- if (HIWORD(TraySave.iUnit))
- dwByte *= 8;
- float f_byte = (float)dwByte;
- if (dwByte < 1000 && LOWORD(TraySave.iUnit) == 0)
- wsprintf(sz, L"%s%dB", szT, dwByte);
- else if ((dwByte < 1024000 || (dwByte < 1000000 && HIWORD(TraySave.iUnit))) && LOWORD(TraySave.iUnit) != 2)
- {
- if (HIWORD(TraySave.iUnit))
- f_byte /= 1000;
- else
- f_byte /= 1024;
- int k_byte = int(f_byte * 100);
- if (f_byte >= 100)
- wsprintf(sz, L"%s%dK", szT, k_byte / 100);
- else if (f_byte >= 10)
- wsprintf(sz, L"%s%d.%.1dK", szT, k_byte / 100, (k_byte / 10) % 10);
- else
- wsprintf(sz, L"%s%d.%.2dK", szT, k_byte / 100, k_byte % 100);
- }
- else if (dwByte < 1048576000 || (dwByte < 1000000000 && HIWORD(TraySave.iUnit)))
- {
- if (HIWORD(TraySave.iUnit))
- f_byte /= 1000000;
- else
- f_byte /= 1048576;
- int m_byte = int(f_byte * 100);
- if (f_byte >= 100)
- wsprintf(sz, L"%s%dM", szT, m_byte / 100);
- else if (f_byte >= 10)
- wsprintf(sz, L"%s%d.%.1dM", szT, m_byte / 100, (m_byte / 10) % 10);
- else
- wsprintf(sz, L"%s%d.%.2dM", szT, m_byte / 100, m_byte % 100);
- }
- else
- {
- if (HIWORD(TraySave.iUnit))
- f_byte /= 1000000000;
- else
- f_byte /= 1073741824;
- int g_byte = int(f_byte * 100);
- if (f_byte >= 100)
- wsprintf(sz, L"%s%dG", szT, g_byte / 100);
- else if (f_byte >= 10)
- wsprintf(sz, L"%s%d.%.1dG", szT, g_byte / 100, (g_byte / 10) % 10);
- else
- wsprintf(sz, L"%s%d.%.2dG", szT, g_byte / 100, g_byte % 100);
- }
- if (HIWORD(TraySave.iUnit))
- lstrlwr(sz, 16);
- if (VTray && TraySave.bMonitorFloat == FALSE)
- DrawShadowText(mdc, sz, lstrlen(sz), lpRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- else
- DrawShadowText(mdc, sz, lstrlen(sz), lpRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- }
-
- BOOL bEvent = FALSE; //
- BOOL SetTrackMouseEvent(HWND hWnd, DWORD dwFlags)
- {
- TRACKMOUSEEVENT csTME;
- csTME.cbSize = sizeof(csTME);
- csTME.dwFlags = dwFlags;
- csTME.hwndTrack = hWnd; // 指定要 追踪 的窗口
- csTME.dwHoverTime = 300; // 鼠标在按钮上停留超过 300ms ,才认为状态为 HOVER
- return TrackMouseEvent(&csTME);
- }
-
- int iGetAddressTime = 10; //10秒一次获取网卡信息
- INT_PTR CALLBACK TaskBarProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) //任务栏信息窗口过程
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) >= IDC_SELECT_ALL && LOWORD(wParam) <= IDC_SELECT_ALL + 99)
- {
- if (LOWORD(wParam) == IDC_SELECT_ALL)
- TraySave.AdpterName[0] = L'\0';
- else
- {
- int x = LOWORD(wParam) - IDC_SELECT_ALL;
- PIP_ADAPTER_ADDRESSES paa;
- paa = &piaa[0];
- int n = 1;
- while (paa)
- {
- if (paa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && paa->IfType != IF_TYPE_TUNNEL)
- {
- if (n == x)
- {
- lstrcpyA(TraySave.AdpterName, paa->AdapterName);
- break;
- }
- n++;
- }
- paa = paa->Next;
- }
- }
- WriteReg();
- m_last_in_bytes = 0;
- m_last_out_bytes = 0;
- s_in_byte = 0;
- s_out_byte = 0;
- }
- break;
- case WM_MOUSEMOVE:
- if (bEvent == FALSE && TraySave.bMonitorTips)
- {
- SetTrackMouseEvent(hTaskBar, TME_LEAVE | TME_HOVER);
- bEvent = TRUE;
- }
- break;
- case WM_MOUSEHOVER:
- {
- if (!IsWindowVisible(hTaskTips))
- {
- if (!IsWindow(hTaskTips))
- {
- hTaskTips = ::CreateDialog(hInst, MAKEINTRESOURCE(IDD_TIPS), NULL, (DLGPROC)TaskTipsProc);
- SetLayeredWindowAttributes(hTaskTips, 0, 255, LWA_ALPHA);
- }
- nProcess = GetProcessMemUsage();
- if (pProcessTime == NULL)
- {
- pProcessTime = (PROCESSTIME *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof PROCESSTIME *(nProcess + 32));
- memset(pProcessTime, 0, sizeof(PROCESSTIME) * (nProcess + 32));
- }
- GetProcessCpuUsage();
- HDC mdc = GetDC(hMain);
- TraySave.TipsFont.lfHeight = DPI(TraySave.TipsFontSize);
- HFONT hTipsFont = CreateFontIndirect(&TraySave.TipsFont); //创建字体
- HFONT oldFont = (HFONT)SelectObject(mdc, hTipsFont);
- SIZE tSize;
- ::GetTextExtentPoint(mdc, L"虚拟内存虚拟内存虚拟内存虚拟内存虚拟内存虚拟内存虚拟内存虚拟内存", 32, &tSize);
- SelectObject(mdc, oldFont);
- DeleteObject(hTipsFont);
- ::ReleaseDC(hMain, mdc);
- int x, y, w, h;
- w = tSize.cx;
- wTipsHeight = tSize.cy;
- h = wTipsHeight * (nTraffic + 8);
- RECT wrc, src;
- GetWindowRect(hDlg, &wrc);
- GetScreenRect(hDlg, &src, TRUE);
- if (wrc.bottom + h > src.bottom)
- y = wrc.top - h;
- else
- y = wrc.bottom;
- if (wrc.right - (wrc.right - wrc.left) / 2 + w / 2 > src.right)
- x = src.right - w;
- else if (wrc.right - (wrc.right - wrc.left) / 2 - w / 2 < src.left)
- x = src.left;
- else
- x = wrc.right - (wrc.right - wrc.left) / 2 - w / 2;
- SetWindowPos(hTaskTips, HWND_TOPMOST, x, y, w, h, SWP_NOACTIVATE | SWP_SHOWWINDOW);
- HRGN hRgn = CreateRoundRectRgn(0, 0, w + 1, h + 1, 3, 3);
- SetWindowRgn(hTaskTips, hRgn, FALSE);
- }
- }
- break;
- case WM_MOUSELEAVE:
- if (TraySave.bMonitorFloat)
- {
- RECT wrc;
- GetWindowRect(hDlg, &wrc);
- TraySave.dMonitorPoint.x = wrc.left;
- TraySave.dMonitorPoint.y = wrc.top;
- WriteReg();
- bTaskBarMoveing = FALSE;
- // SetTimer(hDlg, 6, 100, NULL);
- }
- POINT pt;
- GetCursorPos(&pt);
- if (WindowFromPoint(pt) != hTaskTips)
- {
- if (pProcessTime != NULL)
- {
- HeapFree(GetProcessHeap(), 0, pProcessTime);
- pProcessTime = NULL;
- }
- DestroyWindow(hTaskTips);
- // ShowWindow(hTaskTips, SW_HIDE);
- SetTimer(hMain, 11, 1000, NULL);
- }
- else
- SetTrackMouseEvent(hTaskTips, TME_LEAVE);
- bEvent = FALSE;
- break;
- case WM_RBUTTONDOWN:
- {
- POINT pt;
- GetCursorPos(&pt);
- ScreenToClient(hDlg, &pt);
- if (TraySave.bMonitorTraffic && pt.x < wTraffic && pt.y < wHeight * 2)
- {
-
- HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCEW(IDR_MENU));
- HMENU subMenu = GetSubMenu(hMenu, 0);
- PIP_ADAPTER_ADDRESSES paa;
- paa = &piaa[0];
- int n = 1;
- CheckMenuRadioItem(subMenu, IDC_SELECT_ALL, IDC_SELECT_ALL + 99, IDC_SELECT_ALL, MF_BYCOMMAND);
- while (paa)
- {
- if (paa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && paa->IfType != IF_TYPE_TUNNEL)
- {
- AppendMenu(subMenu, MF_BYCOMMAND, IDC_SELECT_ALL + n, paa->FriendlyName);
- if (lstrcmpA(paa->AdapterName, TraySave.AdpterName) == 0)
- CheckMenuRadioItem(subMenu, IDC_SELECT_ALL, IDC_SELECT_ALL + 99, IDC_SELECT_ALL + n, MF_BYCOMMAND);
- n++;
- }
- paa = paa->Next;
- }
- POINT point;
- GetCursorPos(&point);
- SetTimer(hDlg, 5, 1200, NULL);
- TrackPopupMenu(subMenu, TPM_LEFTALIGN, point.x, point.y, NULL, hDlg, NULL);
- DestroyMenu(hMenu);
- }
- else
- OpenSetting();
- return TRUE;
- }
- break;
- case WM_LBUTTONDOWN:
- {
- if (TraySave.bMonitorFloat)
- {
- bTaskBarMoveing = TRUE;
- PostMessage(hDlg, WM_NCLBUTTONDOWN, HTCAPTION, lParam);
- }
- return TRUE;
- /*
- else
- RunProcess(szNetCpl);
- */
- }
- break;
- case WM_LBUTTONUP:
- if (!TraySave.bMonitorFloat)
- {
- ShowWindow(hDlg, SW_HIDE);
- SetTimer(hDlg, 9, 100, NULL);
- return TRUE;
- }
- break;
- case WM_TIMER:
- if (wParam == 9)
- {
- KillTimer(hDlg, wParam);
- POINT pt;
- GetCursorPos(&pt);
- mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
- mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
- ShowWindow(hDlg, SW_SHOWNOACTIVATE);
- }
- else if (wParam == 5) ////////////////////////////////////////////////光标移出弹出式菜单自动隐藏菜单
- {
-
- HWND hMenu = FindWindow(L"#32768", NULL);
- POINT pt;
- GetCursorPos(&pt);
- if (WindowFromPoint(pt) != hMenu)
- {
- KillTimer(hDlg, wParam);
- PostMessage(hMenu, WM_CLOSE, NULL, NULL);
- }
- }
- else if (wParam == 3)
- {
- if (IsWindowVisible(hTaskTips))
- {
- nProcess = GetProcessMemUsage();
- GetProcessCpuUsage();
- }
- if (TraySave.bMonitorUsage)
- {
- iCPU = GetCPUUseRate();
- GlobalMemoryStatusEx(&MemoryStatusEx);
- }
- if (TraySave.bMonitorTemperature)
- {
- if (bRing0)
- {
- iTemperature1 = GetCpuTemp(1);
- iTemperature2 = GetCpuTemp(dNumProcessor);
- }
- int iATITemperature = 0;
- int iNVTemperature = 0;
- if (hNVDLL)
- {
- NV_GPU_THERMAL_SETTINGS currentTemp; //获取温度的数据结构
- currentTemp.version = NV_GPU_THERMAL_SETTINGS_VER; //一定要设置,不然调用获取温度函数时候会出错
- for (int GpuIndex = 0; GpuIndex < 4; GpuIndex++)
- {
- if (NvAPI_GPU_GetThermalSettings(hPhysicalGpu[GpuIndex], 15, ¤tTemp) == 0)
- {
- iNVTemperature = currentTemp.sensor[0].currentTemp;
- break;
- }
- }
- }
- if (hATIDLL)
- {
- adlTemperature.iSize = sizeof(ADLTemperature);
- ADL_Overdrive5_Temperature_Get(0, 0, &adlTemperature);
- iATITemperature = adlTemperature.iTemperature / 1000;
- }
- if (iATITemperature != 0 || iNVTemperature != 0)
- {
- if (iATITemperature > iNVTemperature)
- iTemperature2 = iATITemperature;
- else
- iTemperature2 = iNVTemperature;
- }
- }
- if (TraySave.bMonitorTraffic)
- {
- if (hIphlpapi == NULL)
- {
- hIphlpapi = LoadLibrary(L"iphlpapi.dll");
- if (hIphlpapi)
- {
- GetAdaptersAddressesT = (pfnGetAdaptersAddresses)GetProcAddress(hIphlpapi, "GetAdaptersAddresses");
- GetIfTableT = (pfnGetIfTable)GetProcAddress(hIphlpapi, "GetIfTable");
- }
- }
- if (hIphlpapi)
- {
- PIP_ADAPTER_ADDRESSES paa;
- if (iGetAddressTime == 10)
- {
- // DWORD odwIPSize = dwIPSize;
- dwIPSize = 0;
- if (GetAdaptersAddressesT(AF_INET, 0, 0, piaa, &dwIPSize) == ERROR_BUFFER_OVERFLOW)
- {
- // if (dwIPSize != odwIPSize)
- {
-
- HeapFree(GetProcessHeap(), 0, piaa);
- int n = 0;
- piaa = (PIP_ADAPTER_ADDRESSES)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwIPSize);
- if (GetAdaptersAddressesT(AF_INET, 0, 0, piaa, &dwIPSize) == ERROR_SUCCESS)
- {
- paa = &piaa[0];
- while (paa)
- {
- if (paa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && paa->IfType != IF_TYPE_TUNNEL)
- {
- ++n;
- }
- paa = paa->Next;
- }
- if (n != nTraffic)
- {
- HeapFree(GetProcessHeap(), 0, traffic);
- nTraffic = n;
- traffic = (TRAFFIC *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nTraffic * sizeof TRAFFIC);
- }
- }
- }
- }
- iGetAddressTime = 0;
- }
- else
- iGetAddressTime++;
- #if 0
- PIP_ADAPTER_INFO pai;
- if (GetAdaptersInfo(ipinfo, &dwIPSize) == ERROR_BUFFER_OVERFLOW)
- {
- free(ipinfo);
- ipinfo = (PIP_ADAPTER_INFO)malloc(dwIPSize);
- GetAdaptersInfo(ipinfo, &dwIPSize);
- pai = &ipinfo[0];
- nTraffic = 0;
- while (pai)
- {
- ++nTraffic;
- pai = pai->Next;
- }
- free(traffic);
- traffic = (TRAFFIC*)malloc(nTraffic * sizeof TRAFFIC);
- }
- #endif
-
- if (GetIfTableT(mi, &dwMISize, FALSE) == ERROR_INSUFFICIENT_BUFFER)
- {
- dwMISize += sizeof MIB_IFROW * 2;
- HeapFree(GetProcessHeap(), 0, mi);
- mi = (MIB_IFTABLE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwMISize);
- GetIfTableT(mi, &dwMISize, FALSE);
- }
-
- DWORD m_in_bytes = 0;
- DWORD m_out_bytes = 0;
-
- for (DWORD i = 0; i < mi->dwNumEntries; i++)
- {
- int l = 0;
- paa = &piaa[0];
- while (paa)
- {
- if (paa->IfType != IF_TYPE_SOFTWARE_LOOPBACK && paa->IfType != IF_TYPE_TUNNEL)
- {
- if (paa->IfIndex == mi->table[i].dwIndex)
- {
- traffic[l].in_byte = (mi->table[i].dwInOctets - traffic[l].in_bytes) * 8;
- traffic[l].out_byte = (mi->table[i].dwOutOctets - traffic[l].out_bytes) * 8;
- traffic[l].in_bytes = mi->table[i].dwInOctets;
- traffic[l].out_bytes = mi->table[i].dwOutOctets;
-
- PIP_ADAPTER_UNICAST_ADDRESS pUnicast = paa->FirstUnicastAddress;
- // char IP[130];
- while (pUnicast)
- {
- if (AF_INET == pUnicast->Address.lpSockaddr->sa_family) // IPV4 地址,使用 IPV4 转换
- {
- void *pAddr = &((sockaddr_in *)pUnicast->Address.lpSockaddr)->sin_addr;
- byte *bp = (byte *)pAddr;
- wsprintf(traffic[l].IP4, L"%d.%d.%d.%d", bp[0], bp[1], bp[2], bp[3]);
- break;
- }
- // else if (AF_INET6 == pUnicast->Address.lpSockaddr->sa_family)// IPV6 地址,使用 IPV6 转换
- // inet_ntop(PF_INET6, &((sockaddr_in6*)pUnicast->Address.lpSockaddr)->sin6_addr, IP, sizeof(IP));
- pUnicast = pUnicast->Next;
- }
- // MultiByteToWideChar(CP_ACP, 0, IP, 15, traffic[l].IP4, 15);
- traffic[l].FriendlyName = paa->FriendlyName;
- traffic[l].AdapterName = paa->AdapterName;
- if (lstrlen(paa->FriendlyName) > 19)
- {
- paa->FriendlyName[16] = L'.';
- paa->FriendlyName[17] = L'.';
- paa->FriendlyName[18] = L'.';
- paa->FriendlyName[19] = L'\0';
- }
- // wcsncpy_s(traffic[l].FriendlyName, 24, paa->FriendlyName,24);
- if (TraySave.AdpterName[0] == L'\0' || lstrcmpA(paa->AdapterName, TraySave.AdpterName) == 0)
- {
- m_in_bytes += mi->table[i].dwInOctets;
- m_out_bytes += mi->table[i].dwOutOctets;
- }
- }
- ++l;
- }
- paa = paa->Next;
- }
- }
- if (m_last_in_bytes != 0)
- {
- s_in_byte = m_in_bytes - m_last_in_bytes;
- s_out_byte = m_out_bytes - m_last_out_bytes;
- }
- m_last_out_bytes = m_out_bytes;
- m_last_in_bytes = m_in_bytes;
- }
- }
- else
- {
- if (hIphlpapi)
- {
- FreeLibrary(hIphlpapi);
- hIphlpapi = NULL;
- }
- }
- if (TraySave.bSound)
- {
- if ((TraySave.dNumValues[8] != 0 && (s_in_byte > TraySave.dNumValues[8] || s_out_byte > TraySave.dNumValues[8]))
- || (TraySave.dNumValues[9] != 0 && ((DWORD)iTemperature1 > TraySave.dNumValues[9] || (DWORD)iTemperature2 > TraySave.dNumValues[9]))
- || (TraySave.dNumValues[10] != 0 && (DWORD)iCPU > TraySave.dNumValues[10])
- || (TraySave.dNumValues[11] != 0 && MemoryStatusEx.dwMemoryLoad > TraySave.dNumValues[11]))
- {
- MessageBeep(MB_ICONHAND);
- //PlaySound((LPCWSTR)SND_ALIAS_SYSTEMQUESTION, NULL, SND_ASYNC | SND_ALIAS_ID);
- }
- }
- ::InvalidateRect(hTaskBar, NULL, TRUE);
- }
- case WM_ERASEBKGND:
- {
- // PAINTSTRUCT ps;
- HDC hdc = (HDC)wParam; //BeginPaint(hDlg, &ps);
- RECT rc;
- GetClientRect(hDlg, &rc);
- HDC mdc = CreateCompatibleDC(hdc);
- HBITMAP hMemBmp = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
- HBITMAP oldBmp = (HBITMAP)SelectObject(mdc, hMemBmp);
- if (TraySave.cMonitorColor[0] != 0)
- {
- HBRUSH hb = CreateSolidBrush(TraySave.cMonitorColor[0]);
- FillRect(mdc, &rc, hb);
- DeleteObject(hb);
- }
- // if (bErasebkgnd)
- {
- if (VTray && TraySave.bMonitorFloat == FALSE)
- {
- /*
- int s = (rc.right - rc.left - DPI(54)) / 2;
- rc.left += s;
- rc.right -= s;
- */
- }
- else
- {
- InflateRect(&rc, -2, 0);
- }
- HFONT oldFont = (HFONT)SelectObject(mdc, hFont);
- WCHAR sz[16];
- SetBkMode(mdc, TRANSPARENT);
- COLORREF rgb;
- if (TraySave.bMonitorTraffic)
- {
- RECT crc = rc;
- if (VTray && TraySave.bMonitorFloat == FALSE)
- {
- crc.bottom = wHeight;
- DrawTraffic(mdc, &crc, s_out_byte, FALSE);
- OffsetRect(&crc, 0, wHeight);
- DrawTraffic(mdc, &crc, s_in_byte, TRUE);
- }
- else
- {
- crc.bottom /= 2;
- DrawTraffic(mdc, &crc, s_out_byte, FALSE);
- OffsetRect(&crc, 0, crc.bottom);
- DrawTraffic(mdc, &crc, s_in_byte, TRUE);
- }
- }
- if (TraySave.bMonitorTemperature)
- {
- RECT crc = rc;
- if (VTray && TraySave.bMonitorFloat == FALSE)
- {
- if (TraySave.bMonitorTraffic)
- crc.top = wHeight * 2;
- crc.bottom = crc.top + wHeight;
- }
- else
- {
-
- if (TraySave.bMonitorTraffic)
- crc.left = wTraffic;
- else
- crc.left = 0;
- crc.bottom /= 2;
- }
- if (bRing0)
- {
- if (iTemperature1 <= TraySave.dNumValues[2])
- rgb = TraySave.cMonitorColor[4];
- else if (iTemperature1 <= TraySave.dNumValues[3])
- rgb = TraySave.cMonitorColor[5];
- else
- rgb = TraySave.cMonitorColor[6];
- SetTextColor(mdc, rgb);
- if (TraySave.iMonitorSimple == 1)
- wsprintf(sz, L"%.2d℃", iTemperature1);
- else if (TraySave.iMonitorSimple == 2)
- wsprintf(sz, L"%.2d", iTemperature1);
- else
- wsprintf(sz, L"%s%.2d%s", TraySave.szTemperatureCPU, iTemperature1, TraySave.szTemperatureCPUUnit);
-
- if (VTray && TraySave.bMonitorFloat == FALSE)
- DrawShadowText(mdc, sz, lstrlen(sz), &crc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- else
- DrawShadowText(mdc, sz, lstrlen(sz), &crc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- }
- if (bRing0)
- {
- if (VTray && TraySave.bMonitorFloat == FALSE)
- OffsetRect(&crc, 0, wHeight);
- else
- OffsetRect(&crc, 0, crc.bottom - crc.top);
- }
- else
- {
- if (VTray && TraySave.bMonitorFloat == FALSE)
- {
- // crc.bottom += wHeight;
- }
- else
- crc.bottom += (crc.bottom - crc.top);
- }
- if (iTemperature2 <= TraySave.dNumValues[2])
- rgb = TraySave.cMonitorColor[4];
- else if (iTemperature2 <= TraySave.dNumValues[3])
- rgb = TraySave.cMonitorColor[5];
- else
- rgb = TraySave.cMonitorColor[6];
- SetTextColor(mdc, rgb);
- if (TraySave.iMonitorSimple == 0)
- wsprintf(sz, L"%s%.2d%s", TraySave.szTemperatureGPU, iTemperature2, TraySave.szTemperatureGPUUnit);
- else if (TraySave.iMonitorSimple == 1)
- wsprintf(sz, L"%.2d℃", iTemperature2);
- else
- wsprintf(sz, L"%.2d", iTemperature2);
- if (VTray && TraySave.bMonitorFloat == FALSE)
- DrawShadowText(mdc, sz, lstrlen(sz), &crc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- else
- DrawShadowText(mdc, sz, lstrlen(sz), &crc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
-
- }
- if (TraySave.bMonitorUsage)
- {
- if (iCPU <= TraySave.dNumValues[4])
- rgb = TraySave.cMonitorColor[4];
- else if (iCPU <= TraySave.dNumValues[5])
- rgb = TraySave.cMonitorColor[5];
- else
- rgb = TraySave.cMonitorColor[6];
- SetTextColor(mdc, rgb);
- /*
- if(bRing0)
- swprintf_s(sz, 16, L"%.2d%%", iCPU);
- else
- */
- if (TraySave.iMonitorSimple == 1)
- wsprintf(sz, L"%.2d%%", iCPU);
- else if (TraySave.iMonitorSimple == 2)
- wsprintf(sz, L"%.2d", iCPU);
- else
- wsprintf(sz, L"%s%.2d%s", TraySave.szUsageCPU, iCPU, TraySave.szUsageCPUUnit);
-
- int sLen = lstrlen(sz);
- RECT crc = rc;
- if (VTray && TraySave.bMonitorFloat == FALSE)
- {
- if (TraySave.bMonitorTraffic)
- crc.top = wHeight * 2;
- if (TraySave.bMonitorTemperature)
- {
- crc.top += wHeight;
- if (bRing0)
- crc.top += wHeight;
- }
- crc.bottom = crc.top + wHeight;
- DrawShadowText(mdc, sz, sLen, &crc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
- else
- {
- crc.bottom /= 2;
- DrawShadowText(mdc, sz, sLen, &crc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
- }
- /*
- if(bRing0)
- swprintf_s(sz, 16, L"%.2d%%", MemoryStatusEx.dwMemoryLoad);
- else
- */
- if (TraySave.iMonitorSimple == 1)
- wsprintf(sz, L"%.2d%%", MemoryStatusEx.dwMemoryLoad);
- else if (TraySave.iMonitorSimple == 2)
- wsprintf(sz, L"%.2d", MemoryStatusEx.dwMemoryLoad);
- else
- wsprintf(sz, L"%s%.2d%s", TraySave.szUsageMEM, MemoryStatusEx.dwMemoryLoad, TraySave.szUsageMEMUnit);
- sLen = lstrlen(sz);
- if (MemoryStatusEx.dwMemoryLoad <= TraySave.dNumValues[6])
- rgb = TraySave.cMonitorColor[4];
- else if (MemoryStatusEx.dwMemoryLoad <= TraySave.dNumValues[7])
- rgb = TraySave.cMonitorColor[5];
- else
- rgb = TraySave.cMonitorColor[6];
- SetTextColor(mdc, rgb);
- if (VTray && TraySave.bMonitorFloat == FALSE)
- {
- OffsetRect(&crc, 0, wHeight);
- DrawShadowText(mdc, sz, (int)sLen, &crc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
- else
- {
- OffsetRect(&crc, 0, crc.bottom);
- DrawShadowText(mdc, sz, (int)sLen, &crc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
- }
- }
- SelectObject(mdc, oldFont);
- }
- // GetClientRect(hDlg, &rc);
- InflateRect(&rc, 2, 0);
- /*
- BLENDFUNCTION bf1;
- bf1.BlendOp = AC_SRC_OVER;
- bf1.BlendFlags = 0;
- bf1.SourceConstantAlpha = 88;
- bf1.AlphaFormat = AC_SRC_ALPHA;
- ::AlphaBlend(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, mdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, bf1);
- */
- if (TraySave.cMonitorColor[0] != RGB(0, 0, 0))
- {
- BYTE *lpvBits = NULL;
-
- BITMAPINFO binfo;
- memset(&binfo, 0, sizeof(BITMAPINFO));
- binfo.bmiHeader.biBitCount = 32; //每个像素多少位,也可直接写24(RGB)或者32(RGBA)
- binfo.bmiHeader.biCompression = 0;
- binfo.bmiHeader.biHeight = rc.bottom - rc.top;
- binfo.bmiHeader.biPlanes = 1;
- binfo.bmiHeader.biSizeImage = (rc.bottom - rc.top) * (rc.right - rc.left) * 4;
- binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- binfo.bmiHeader.biWidth = rc.right - rc.left;
- lpvBits = (BYTE *)HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE, binfo.bmiHeader.biSizeImage);
- // GetDIBits(mdc, hMemBmp, 0, rc.bottom - rc.top, lpvBits, &bmpInfo, DIB_RGB_COLORS);
-
- GetDIBits(mdc, hMemBmp, 0, rc.bottom - rc.top, lpvBits, &binfo, DIB_RGB_COLORS);
- for (DWORD i = 0; i < binfo.bmiHeader.biSizeImage - 4; i += 4)
- {
- if (lpvBits[i] > 3 || lpvBits[i + 1] != 0 || lpvBits[i + 2] != 0)
- lpvBits[i + 3] = 0x80;
- }
- SetDIBits(mdc, hMemBmp, 0, rc.bottom - rc.top, lpvBits, &binfo, DIB_RGB_COLORS);
- HeapFree(GetProcessHeap(), 0, lpvBits);
- }
- BitBlt(hdc, 0, 0, rc.right - rc.left, rc.bottom - rc.top, mdc, 0, 0, SRCCOPY);
- SelectObject(mdc, oldBmp);
- DeleteObject(hMemBmp);
- DeleteDC(mdc);
- // EndPaint(hDlg, &ps);
-
- return TRUE;
- }
- break;
- }
- return FALSE;
- }
-
- INT_PTR CALLBACK MainProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) //主窗口过程
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- /*
- case WM_ENDSESSION:
- if (lParam == ENDSESSION_LOGOFF)
- {
- DestroyWindow(hTray);
- RunProcess(NULL);
- return TRUE;
- }
- break;
- */
- case WM_TRAYS:
- OpenSetting();
- break;
- case WM_DPICHANGED:
- {
- iDPI = LOWORD(wParam);
- SetTimer(hDlg, 8, 1000, NULL);
- }
- break;
- case WM_CLOSE:
- {
- KillTimer(hDlg, 6);
- KillTimer(hDlg, 3);
- SendMessage(hReBarWnd, WM_SETREDRAW, TRUE, 0);
- HWND hSecondaryTray;
- hSecondaryTray = FindWindow(szSecondaryTray, NULL);
- while (hSecondaryTray)
- {
- HWND hSReBarWnd = FindWindowEx(hSecondaryTray, 0, L"WorkerW", NULL);
- SendMessage(hSReBarWnd, WM_SETREDRAW, TRUE, 0);
- ShowWindow(hSReBarWnd, SW_SHOWNOACTIVATE);
- hSecondaryTray = FindWindowEx(NULL, hSecondaryTray, szSecondaryTray, NULL);
- }
- ShowWindow(hTaskListWnd, SW_SHOW);
- PostQuitMessage(0);
- }
- break;
- case WM_TIMER:
- {
- if (wParam == 8)
- {
- KillTimer(hDlg, wParam);
- SetWH();
- }
- else if (wParam == 11) //释放内存
- {
- KillTimer(hDlg, wParam);
- SetTimer(hDlg, wParam, 60000, NULL);
- HANDLE hProcess = GetCurrentProcess();
- SetProcessWorkingSetSize(hProcess, -1, -1);
- EmptyWorkingSet(hProcess);
- }
- else if (wParam == 6) //处理任务栏图标与信息窗口
- {
- if (TraySave.bMonitor)
- {
- // if (!bTaskBarMoveing)
- // AdjustWindowPos();
- if (IsWindowVisible(hTaskTips))
- ::InvalidateRect(hTaskTips, NULL, TRUE);
- }
- if (TraySave.iPos != 0 || TraySave.bMonitor)
- {
- // if (TraySave.bTaskIcon == FALSE)
- {
- GetShellAllWnd();
- SetTaskBarPos(hTaskListWnd, hTray, hTaskWnd, hReBarWnd, TRUE);
- }
- HWND hSecondaryTray;
- hSecondaryTray = FindWindow(szSecondaryTray, NULL);
- while (hSecondaryTray)
- {
- HWND hSReBarWnd = FindWindowEx(hSecondaryTray, 0, L"WorkerW", NULL);
- if (hSReBarWnd)
- {
- HWND hSTaskListWnd = FindWindowEx(hSReBarWnd, NULL, L"MSTaskListWClass", NULL);
- if (hSTaskListWnd)
- {
- SetTaskBarPos(hSTaskListWnd, hSecondaryTray, hSReBarWnd, hSReBarWnd, FALSE);
- }
- }
- hSecondaryTray = FindWindowEx(NULL, hSecondaryTray, szSecondaryTray, NULL);
- }
- }
- }
- else if (wParam == 3) //处理任务栏风格
- {
- if (TraySave.bMonitor)
- {
- if (!bTaskBarMoveing)
- {
- AdjustWindowPos();
- }
- }
- {
- HWND hTray = FindWindow(szShellTray, NULL);
- if (hTray)
- {
- if (iProject == 0)
- iWindowMode = 0;
- else if (iProject == 1)
- iWindowMode = 1;
- else
- {
- iWindowMode = 0;
- EnumWindows(IsZoomedFunc, (LPARAM)MonitorFromWindow(hTray, MONITOR_DEFAULTTONEAREST));
- }
- SetWindowCompositionAttribute(hTray, TraySave.aMode[iWindowMode], TraySave.dAlphaColor[iWindowMode]);
- LONG_PTR exStyle = GetWindowLongPtr(hTray, GWL_EXSTYLE);
- exStyle |= WS_EX_LAYERED;
- SetWindowLongPtr(hTray, GWL_EXSTYLE, exStyle);
- SetLayeredWindowAttributes(hTray, 0, (BYTE)TraySave.bAlpha[iWindowMode], LWA_ALPHA);
- }
- HWND hSecondaryTray = FindWindow(szSecondaryTray, NULL);
- while (hSecondaryTray)
- {
- if (iProject == 0)
- iWindowMode = 0;
- else if (iProject == 1)
- iWindowMode = 1;
- else
- {
- iWindowMode = 0;
- EnumWindows(IsZoomedFunc, (LPARAM)MonitorFromWindow(hSecondaryTray, MONITOR_DEFAULTTONEAREST));
- }
- SetWindowCompositionAttribute(hSecondaryTray, TraySave.aMode[iWindowMode], TraySave.dAlphaColor[iWindowMode]);
- LONG_PTR exStyle = GetWindowLongPtr(hSecondaryTray, GWL_EXSTYLE);
- exStyle |= WS_EX_LAYERED;
- SetWindowLongPtr(hSecondaryTray, GWL_EXSTYLE, exStyle);
- SetLayeredWindowAttributes(hSecondaryTray, 0, (BYTE)TraySave.bAlpha[iWindowMode], LWA_ALPHA);
- hSecondaryTray = FindWindowEx(NULL, hSecondaryTray, szSecondaryTray, NULL);
- }
- }
- if (TraySave.aMode[0] == ACCENT_DISABLED && TraySave.aMode[1] == ACCENT_DISABLED) //默认则关闭定时器
- KillTimer(hDlg, 3);
- }
- }
- break;
- case WM_IAWENTRAY: //////////////////////////////////////////////////////////////////////////////////通知栏左右键处理
- {
- if (wParam == WM_IAWENTRAY)
- {
- if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
- {
- OpenSetting();
- }
- }
- break;
- }
- break;
- }
- return FALSE;
- }
-
- INT_PTR CALLBACK SettingProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) //设置窗口过程
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (message)
- {
- case WM_INITDIALOG:
- return (INT_PTR)TRUE;
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->code)
- {
- case NM_CLICK:
- case NM_RETURN:
- {
- HWND g_hLink = GetDlgItem(hDlg, IDC_SYSLINK);
- PNMLINK pNMLink = (PNMLINK)lParam;
- LITEM item = pNMLink->item;
- if ((((LPNMHDR)lParam)->hwndFrom == g_hLink) && (item.iLink == 0))
- {
- CloseHandle(pShellExecute(NULL, L"open", L"https://gitee.com/cgbsmy/TrayS", NULL, NULL, SW_SHOW));
- //mailto:cgbsmy@live.com?subject=TrayS
- }
- else
- {
- CloseHandle(pShellExecute(NULL, L"open", L"https://www.52pojie.cn/thread-1182669-1-1.html", NULL, NULL, SW_SHOW));
- }
- break;
- }
- }
- break;
- case WM_HSCROLL: //////////////////////////////////////////////////////////////////////////////////透明度处理
- {
- HWND hSlider = GetDlgItem(hDlg, IDC_SLIDER_ALPHA);
- HWND hSliderB = GetDlgItem(hDlg, IDC_SLIDER_ALPHA_B);
- if (hSlider == (HWND)lParam)
- {
- TraySave.bAlpha[iProject] = (int)SendDlgItemMessage(hDlg, IDC_SLIDER_ALPHA, TBM_GETPOS, 0, 0);
- }
- else if (hSliderB == (HWND)lParam)
- {
- DWORD bAlphaB = (int)SendDlgItemMessage(hDlg, IDC_SLIDER_ALPHA_B, TBM_GETPOS, 0, 0);
- bAlphaB = bAlphaB << 24;
- TraySave.dAlphaColor[iProject] = bAlphaB + (TraySave.dAlphaColor[iProject] & 0xffffff);
- }
- SetTimer(hDlg, 3, 500, NULL);
- break;
- }
- case WM_TIMER:
- if (wParam == 3)
- {
- KillTimer(hDlg, wParam);
- WriteReg();
- }
- break;
- case WM_COMMAND:
- if (HIWORD(wParam) == EN_CHANGE && !bSettingInit)
- {
- if (LOWORD(wParam) >= IDC_EDIT1 && LOWORD(wParam) <= IDC_EDIT12)
- {
- int index = LOWORD(wParam) - IDC_EDIT1;
- TraySave.dNumValues[index] = GetDlgItemInt(hDlg, LOWORD(wParam), NULL, 0);
- if (index == 0 || index == 1 || index == 8)
- TraySave.dNumValues[index] *= 1048576;
- SetTimer(hDlg, 3, 500, NULL);
- }
- else if (LOWORD(wParam) == IDC_EDIT_TIME)
- {
- TraySave.FlushTime = GetDlgItemInt(hDlg, LOWORD(wParam), NULL, 0);
- if (TraySave.aMode[0] != ACCENT_DISABLED || TraySave.aMode[1] != ACCENT_DISABLED)
- SetTimer(hMain, 3, TraySave.FlushTime, NULL);
- SetTimer(hDlg, 3, 500, NULL);
- }
- else if (LOWORD(wParam) >= IDC_EDIT14 && LOWORD(wParam) <= IDC_EDIT23)
- {
- GetDlgItemText(hDlg, IDC_EDIT14, TraySave.szTrafficOut, 8);
- GetDlgItemText(hDlg, IDC_EDIT15, TraySave.szTrafficIn, 8);
- GetDlgItemText(hDlg, IDC_EDIT16, TraySave.szTemperatureCPU, 8);
- GetDlgItemText(hDlg, IDC_EDIT17, TraySave.szTemperatureGPU, 8);
- GetDlgItemText(hDlg, IDC_EDIT18, TraySave.szTemperatureCPUUnit, 4);
- GetDlgItemText(hDlg, IDC_EDIT19, TraySave.szTemperatureGPUUnit, 4);
- GetDlgItemText(hDlg, IDC_EDIT20, TraySave.szUsageCPU, 8);
- GetDlgItemText(hDlg, IDC_EDIT21, TraySave.szUsageMEM, 8);
- GetDlgItemText(hDlg, IDC_EDIT22, TraySave.szUsageCPUUnit, 4);
- GetDlgItemText(hDlg, IDC_EDIT23, TraySave.szUsageMEMUnit, 4);
- SetTimer(hDlg, 3, 1500, NULL);
- if (TraySave.iMonitorSimple == 0)
- SetWH();
- }
- }
- else if (LOWORD(wParam) >= IDC_RADIO_DEFAULT && LOWORD(wParam) <= IDC_RADIO_ACRYLIC)
- {
- if (IsDlgButtonChecked(hDlg, IDC_RADIO_DEFAULT))
- TraySave.aMode[iProject] = ACCENT_DISABLED;
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_TRANSPARENT))
- TraySave.aMode[iProject] = ACCENT_ENABLE_TRANSPARENTGRADIENT;
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_BLURBEHIND))
- TraySave.aMode[iProject] = ACCENT_ENABLE_BLURBEHIND;
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_ACRYLIC))
- TraySave.aMode[iProject] = ACCENT_ENABLE_ACRYLICBLURBEHIND;
- WriteReg();
- if (TraySave.aMode[0] != ACCENT_DISABLED || TraySave.aMode[1] != ACCENT_DISABLED)
- SetTimer(hMain, 3, TraySave.FlushTime, NULL);
- else
- KillTimer(hMain, 3);
-
- }
- else if (LOWORD(wParam) >= IDC_RADIO_LEFT && LOWORD(wParam) <= IDC_RADIO_RIGHT)
- {
- if (IsDlgButtonChecked(hDlg, IDC_RADIO_LEFT))
- {
- TraySave.iPos = 0;
- }
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_CENTER))
- {
- TraySave.iPos = 1;
- }
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_RIGHT))
- {
- TraySave.iPos = 2;
- }
- WriteReg();
- }
- else if (LOWORD(wParam) >= IDC_RADIO_BYTE && LOWORD(wParam) <= IDC_RADIO_MB)
- {
- if (IsDlgButtonChecked(hDlg, IDC_RADIO_AUTO))
- TraySave.iUnit = 0;
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_KB))
- TraySave.iUnit = 1;
- else if (IsDlgButtonChecked(hDlg, IDC_RADIO_MB))
- TraySave.iUnit = 2;
- if (IsDlgButtonChecked(hDlg, IDC_RADIO_BIT))
- TraySave.iUnit |= 0x10000;
- WriteReg();
- }
- if (LOWORD(wParam) == IDC_RADIO_NORMAL || LOWORD(wParam) == IDC_RADIO_MAXIMIZE)
- {
- if (IsDlgButtonChecked(hDlg, IDC_RADIO_NORMAL))
- iProject = 0;
- else
- iProject = 1;
- if (TraySave.aMode[iProject] == ACCENT_DISABLED)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_DEFAULT);
- else if (TraySave.aMode[iProject] == ACCENT_ENABLE_TRANSPARENTGRADIENT)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_TRANSPARENT);
- else if (TraySave.aMode[iProject] == ACCENT_ENABLE_BLURBEHIND)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_BLURBEHIND);
- else if (TraySave.aMode[iProject] == ACCENT_ENABLE_ACRYLICBLURBEHIND)
- CheckRadioButton(hSetting, IDC_RADIO_DEFAULT, IDC_RADIO_ACRYLIC, IDC_RADIO_ACRYLIC);
- SendDlgItemMessage(hSetting, IDC_SLIDER_ALPHA, TBM_SETPOS, TRUE, TraySave.bAlpha[iProject]);
- BYTE bAlphaB = TraySave.dAlphaColor[iProject] >> 24;
- SendDlgItemMessage(hSetting, IDC_SLIDER_ALPHA_B, TBM_SETPOS, TRUE, bAlphaB);
- ::InvalidateRect(GetDlgItem(hSetting, IDC_BUTTON_COLOR), NULL, FALSE);
- }
- else if (LOWORD(wParam) == IDC_CHECK_SOUND)
- {
- TraySave.bSound = IsDlgButtonChecked(hDlg, IDC_CHECK_SOUND);
- WriteReg();
- }
- else if (LOWORD(wParam) == IDC_CHECK_TIPS)
- {
- TraySave.bMonitorTips = IsDlgButtonChecked(hDlg, IDC_CHECK_TIPS);
- WriteReg();
- }
- else if (LOWORD(wParam) == IDC_CHECK_TRAYICON)
- {
- TraySave.bTrayIcon = IsDlgButtonChecked(hDlg, IDC_CHECK_TRAYICON);
- WriteReg();
- CloseTaskBar();
- if (TraySave.bTrayIcon)
- pShell_NotifyIcon(NIM_ADD, &nid);
- else
- pShell_NotifyIcon(NIM_DELETE, &nid);
- }
- else if (LOWORD(wParam) == IDC_CHECK_MONITOR)
- {
- TraySave.bMonitor = IsDlgButtonChecked(hDlg, IDC_CHECK_MONITOR);
- WriteReg();
- if (!TraySave.bMonitor)
- {
- CloseTaskBar();
- }
- }
- else if (LOWORD(wParam) == IDC_CHECK_TRAFFIC)
- {
- TraySave.bMonitorTraffic = IsDlgButtonChecked(hDlg, IDC_CHECK_TRAFFIC);
- WriteReg();
- SetWH();
- }
- else if (LOWORD(wParam) == IDC_CHECK_TEMPERATURE)
- {
- TraySave.bMonitorTemperature = IsDlgButtonChecked(hDlg, IDC_CHECK_TEMPERATURE);
- if (TraySave.bMonitorTemperature)
- LoadTemperatureDLL();
- else
- FreeTemperatureDLL();
- WriteReg();
- SetWH();
- }
- else if (LOWORD(wParam) == IDC_CHECK_MONITOR_SIMPLE)
- {
- TraySave.iMonitorSimple = IsDlgButtonChecked(hDlg, IDC_CHECK_MONITOR_SIMPLE);
- WriteReg();
- SetWH();
- }
- else if (LOWORD(wParam) == IDC_CHECK_USAGE)
- {
- TraySave.bMonitorUsage = IsDlgButtonChecked(hDlg, IDC_CHECK_USAGE);
- WriteReg();
- SetWH();
- }
- else if (LOWORD(wParam) == IDC_CHECK_MONITOR_PDH)
- {
- TraySave.bMonitorPDH = IsDlgButtonChecked(hDlg, IDC_CHECK_MONITOR_PDH);
- WriteReg();
- }
- else if (LOWORD(wParam) == IDC_CHECK_MONITOR_LEFT)
- {
- TraySave.bMonitorLeft = IsDlgButtonChecked(hDlg, IDC_CHECK_MONITOR_LEFT);
- WriteReg();
- }
- else if (LOWORD(wParam) == IDC_CHECK_MONITOR_FLOAT)
- {
- TraySave.bMonitorFloat = IsDlgButtonChecked(hDlg, IDC_CHECK_MONITOR_FLOAT);
- WriteReg();
- CloseTaskBar();
- }
- else if (LOWORD(wParam) == IDC_CHECK_TRANSPARENT)
- {
- TraySave.bMonitorTransparent = IsDlgButtonChecked(hDlg, IDC_CHECK_TRANSPARENT);
- OpenTaskBar();
- WriteReg();
- }
- else if (LOWORD(wParam) == IDC_CHECK_AUTORUN)
- {
- if (IsDlgButtonChecked(hDlg, IDC_CHECK_AUTORUN))
- AutoRun(TRUE, TRUE, szAppName);
- else
- AutoRun(TRUE, FALSE, szAppName);
- }
- else if (LOWORD(wParam) == IDC_RESTORE_DEFAULT)
- {
- DeleteFile(szTraySave);
- // RegDeleteKey(HKEY_CURRENT_USER, szSubKey);
- SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
- }
- else if (LOWORD(wParam) == IDCANCEL)
- {
- /*
- SendMessage(hMain, WM_TIMER, 11, 1000);
- DestroyWindow(hDlg);
- return (INT_PTR)TRUE;
- */
- // SendMessage(hReBarWnd, WM_SETREDRAW, TRUE, 0);
- bResetRun = TRUE;
- SendMessage(hMain, WM_CLOSE, NULL, NULL);
- return (INT_PTR)TRUE;
- }
- else if (LOWORD(wParam) == IDC_CLOSE)
- {
- SendMessage(hMain, WM_CLOSE, NULL, NULL);
- }
- else if (LOWORD(wParam) == IDC_BUTTON_FONT || LOWORD(wParam) == IDC_BUTTON_TIPS_FONT)
- {
- typedef UINT_PTR(CALLBACK * LPCFHOOKPROC)(HWND, UINT, WPARAM, LPARAM);
- typedef struct tagCHOOSEFONTW
- {
- DWORD lStructSize;
- HWND hwndOwner; // caller's window handle
- HDC hDC; // printer DC/IC or NULL
- LPLOGFONTW lpLogFont; // ptr. to a LOGFONT struct
- INT iPointSize; // 10 * size in points of selected font
- DWORD Flags; // enum. type flags
- COLORREF rgbColors; // returned text color
- LPARAM lCustData; // data passed to hook fn.
- LPCFHOOKPROC lpfnHook; // ptr. to hook function
- LPCWSTR lpTemplateName; // custom template name
- HINSTANCE hInstance; // instance handle of.EXE that
- // contains cust. dlg. template
- LPWSTR lpszStyle; // return the style field here
- // must be LF_FACESIZE or bigger
- WORD nFontType; // same value reported to the EnumFonts
- // call back with the extra FONTTYPE_
- // bits added
- WORD ___MISSING_ALIGNMENT__;
- INT nSizeMin; // minimum pt size allowed &
- INT nSizeMax; // max pt size allowed if
- // CF_LIMITSIZE is used
- }
- CHOOSEFONT;
- TraySave.TraybarFont.lfHeight = TraySave.TraybarFontSize;
- TraySave.TipsFont.lfHeight = TraySave.TipsFontSize;
- CHOOSEFONT cf;
- cf.lStructSize = sizeof cf;
- cf.hwndOwner = hDlg;
- cf.hDC = NULL;
- if (LOWORD(wParam) == IDC_BUTTON_FONT)
- cf.lpLogFont = &TraySave.TraybarFont;
- else
- cf.lpLogFont = &TraySave.TipsFont;
- cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_EFFECTS;
- cf.nFontType = SCREEN_FONTTYPE;
- cf.rgbColors = RGB(0, 0, 0);
- typedef BOOL(WINAPI *pfnChooseFont)(CHOOSEFONT *lpcf);
- HMODULE hComdlg32 = LoadLibrary(L"comdlg32.dll");
- if (hComdlg32)
- {
- pfnChooseFont ChooseFont = (pfnChooseFont)GetProcAddress(hComdlg32, "ChooseFontW");
- if (ChooseFont)
- {
- if (ChooseFont(&cf))
- {
- if (LOWORD(wParam) == IDC_BUTTON_FONT)
- {
- TraySave.TraybarFontSize = TraySave.TraybarFont.lfHeight;
- otleft = -1;
- SetWH();
- AdjustWindowPos();
- }
- else
- TraySave.TipsFontSize = TraySave.TipsFont.lfHeight;
- WriteReg();
- }
- }
- FreeLibrary(hComdlg32);
- }
- }
- else if (LOWORD(wParam) == IDC_BUTTON_COLOR || (LOWORD(wParam) >= IDC_BUTTON_COLOR_BACKGROUND && LOWORD(wParam) <= IDC_BUTTON_COLOR_HIGH))
- {
- CHOOSECOLOR stChooseColor;
- stChooseColor.lStructSize = sizeof(CHOOSECOLOR);
- stChooseColor.hwndOwner = hDlg;
- if (LOWORD(wParam) == IDC_BUTTON_COLOR)
- {
- stChooseColor.rgbResult = TraySave.dAlphaColor[iProject];
- stChooseColor.lpCustColors = (LPDWORD)&TraySave.dAlphaColor[iProject];
- }
- else
- {
- stChooseColor.rgbResult = TraySave.cMonitorColor[LOWORD(wParam) - IDC_BUTTON_COLOR_BACKGROUND];
- stChooseColor.lpCustColors = TraySave.cMonitorColor;
- }
- stChooseColor.Flags = CC_RGBINIT | CC_FULLOPEN;
- stChooseColor.lCustData = 0;
- stChooseColor.lpfnHook = NULL;
- stChooseColor.lpTemplateName = NULL;
- typedef BOOL(WINAPI * pfnChooseColor)(LPCHOOSECOLOR lpcc);
- HMODULE hComdlg32 = LoadLibrary(L"comdlg32.dll");
- if (hComdlg32)
- {
- pfnChooseColor ChooseColor = (pfnChooseColor)GetProcAddress(hComdlg32, "ChooseColorW");
- if (ChooseColor)
- {
- if (ChooseColor(&stChooseColor))
- {
- if (LOWORD(wParam) == IDC_BUTTON_COLOR)
- {
- TraySave.dAlphaColor[iProject] = stChooseColor.rgbResult;
- DWORD bAlphaB = (int)SendDlgItemMessage(hDlg, IDC_SLIDER_ALPHA_B, TBM_GETPOS, 0, 0);
- bAlphaB = bAlphaB << 24;
- TraySave.dAlphaColor[iProject] = bAlphaB + (TraySave.dAlphaColor[iProject] & 0xffffff);
- }
- else
- {
- TraySave.cMonitorColor[LOWORD(wParam - IDC_BUTTON_COLOR_BACKGROUND)] = stChooseColor.rgbResult;
- }
- ::InvalidateRect(GetDlgItem(hMain, LOWORD(wParam)), NULL, FALSE);
- }
- }
- FreeLibrary(hComdlg32);
- }
- WriteReg();
- // SendMessage(hMain, WM_TRAYS, NULL, NULL);
- }
- break;
- }
-
- return (INT_PTR)FALSE;
- }
-
- INT_PTR CALLBACK ColorButtonProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) //颜色按钮控件过程
- {
- switch (message)
- {
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hWnd, &ps);
- RECT rc;
- GetClientRect(hWnd, &rc);
- HBRUSH hb;
- int id = GetDlgCtrlID(hWnd);
- if (id >= IDC_BUTTON_COLOR_BACKGROUND && id <= IDC_BUTTON_COLOR_HIGH)
- {
- hb = CreateSolidBrush(TraySave.cMonitorColor[id - IDC_BUTTON_COLOR_BACKGROUND]);
- }
- else
- hb = CreateSolidBrush(TraySave.dAlphaColor[iProject] & 0xffffff);
- FillRect(hdc, &rc, hb);
- DeleteObject(hb);
- EndPaint(hWnd, &ps);
- return TRUE;
- }
- }
- return CallWindowProc(oldColorButtonPoroc, hWnd, message, wParam, lParam);
- }
-
- int DrawShadowText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UINT uFormat) //绘制阴影文字
- {
- // COLORREF cColor = GetTextColor(hDC);
- // return DrawShadowText(hDC, lpString, nCount, lpRect, uFormat, cColor, RGB(066, 66,66), 1, 1);
- if (TraySave.cMonitorColor[0] == RGB(0, 0, 1))
- {
- COLORREF cColor = GetTextColor(hDC);
- SetTextColor(hDC, RGB(11, 11, 11));
- OffsetRect(lpRect, 1, 0);
- DrawText(hDC, lpString, nCount, lpRect, uFormat);
- OffsetRect(lpRect, 0, 1);
- DrawText(hDC, lpString, nCount, lpRect, uFormat);
- OffsetRect(lpRect, 1, 0);
- DrawText(hDC, lpString, nCount, lpRect, uFormat);
- OffsetRect(lpRect, 0, 1);
- DrawText(hDC, lpString, nCount, lpRect, uFormat);
- OffsetRect(lpRect, -2, -2);
- SetTextColor(hDC, cColor);
- }
-
- return DrawText(hDC, lpString, nCount, lpRect, uFormat);
- }
|