private void ShowForegroundWindow(object sender, EventArgs e) { var FW = GetForegroundWindow(); /* * StringBuilder SB = new StringBuilder(); * //char[] filepath = new char[10000]; * //uint maxfilepathlength = 1000; * try * { * GetWindowText(FW, SB, 1000); * } * catch (Exception ex) * { * Debug.Write(ex.Message); * } */ //Debug.Write(SB); //QueryFullProcessImageName(new IntPtr(GetCurrentProcessID(FW)), 0, filepath, ref maxfilepathlength); var P = Process.GetProcessById(GetCurrentProcessID(FW)); var PP = FindHostedProcess.Find(); if (PP == null) { return; } TB.Text = PP.ProcessName + "|" + PP.MainModule.FileName + "|" + PP.MainWindowTitle; //Bitmap img = Consts.Base64String2Icon(Consts.Icon2Base64String(System.Drawing.Icon.ExtractAssociatedIcon(PP.MainModule.FileName))).ToBitmap(); Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(PP.MainModule.FileName); Icon icon2 = Consts.Base64String2Icon(Consts.Icon2Base64String(icon)); IMG.Source = Consts.ChangeBitmapToImageSource(icon2.ToBitmap()); }
private void GenerateNIC() { NIC = new NotifyIconComponent(); NIC.NotifyIconText = "一个静悄悄的图标"; NIC.ContextMenuStripItems.Add("显示/隐藏主界面"); NIC.ContextMenuStripItems[0].Click += Visibility_Click; NIC.ContextMenuStripItems[0].Font = new Font(NIC.ContextMenuStripItems[0].Font, NIC.ContextMenuStripItems[0].Font.Style | System.Drawing.FontStyle.Bold); NIC.ContextMenuStripItems.Add("设置挂机标题"); NIC.ContextMenuStripItems[1].Click += ShowEnterName_Click; NIC.ContextMenuStripItems.Add("退出"); NIC.ContextMenuStripItems[2].Click += Exit_Click; NIC.NotifyIconDoubleClick = Visibility_Click; NIC.NotifyIconIcon = Consts.Base64String2Icon(Consts.IconClockStr); }
public static List <Actions> GetActions(string StartDateTime, string EndDateTime) { DateTime SDT, EDT; try { SDT = Convert.ToDateTime(StartDateTime); EDT = Convert.ToDateTime(EndDateTime); } catch { return(null); } List <Actions> res = new List <Actions>(); using (SQLiteConnection con = new SQLiteConnection("Data Source=Actions.db;Version=3;")) { con.Open(); using (SQLiteDataAdapter ada = new SQLiteDataAdapter("SELECT * FROM Actions WHERE TimeStamp >= " + SDT.Ticks + " and TimeStamp <= " + EDT.Ticks + " ORDER BY TimeStamp", con)) { DataTable DT = new DataTable(); ada.Fill(DT); foreach (DataRow r in DT.Rows) { if (res.Count > 999) { MessageBox.Show("条目过多,仅显示1000条。"); break; } Actions A = new Actions(); A.DateTime = new DateTime((long)r["TimeStamp"]); //D.Year + "-" + D.Month + "-" + D.Day + " " + D.Hour + ":" + D.Minute + ":" + D.Second; A.Type = (int)(long)r["Type"]; A.Action = r["Action"].ToString(); A.Title = r["Title"].ToString(); if (r["Icon"] != null && r["Icon"].ToString() != "") { A.Icon = Consts.Base64String2Icon(r["Icon"].ToString()); } res.Add(A); } } } return(res); }
double GetShowData() { ShowDataList.Clear(); SectorDataList.Clear(); Consts.ResetNextBrush(); var Actions = Data.GetActions(StartYMDTextBlock.Text + " " + StartHMSTextBlock.Text, EndYMDTextBlock.Text + " " + EndHMSTextBlock.Text); var lastmove = new DateTime(0); if (Actions.Count > 0) { lastmove = Actions[0].DateTime; } foreach (var a in Actions) { Data.ShowData last = null; if (ShowDataList.Count != 0) { last = ShowDataList.Last(); } if (a.Type == 0) { if (last == null || last.Action != a.Action || last.Title != a.Title) { if (a.DateTime - lastmove > Consts.ActiveTimeSpan) { var fishdata = new Data.ShowData() { I = Consts.Base64String2Icon(Consts.IconFishStr), Start = lastmove, End = a.DateTime, Action = Consts.CatchFishString, IsCatchFish = true, Title = "" }; ShowDataList.Add(fishdata); last = ShowDataList.Last(); } var SD = new Data.ShowData() { I = a.Icon, Start = a.DateTime, End = a.DateTime, Action = a.Action, Title = a.Title, }; SD.IsCatchFish = CatchFishEvents.Any(str => { return(str == SD.ActionTitle); }); if (last != null) { last.End = SD.Start; } ShowDataList.Add(SD); lastmove = a.DateTime; } else { last.End = a.DateTime; } } else { if ((a.DateTime - lastmove) > Consts.ActiveTimeSpan) { if (ShowDataList.Count == 0) { goto End; } var lastshowdata = new Data.ShowData(ShowDataList.Last()); var fishdata = new Data.ShowData() { I = Consts.Base64String2Icon(Consts.IconFishStr), Start = lastmove, End = a.DateTime, Action = Consts.CatchFishString, IsCatchFish = true, Title = "" }; ShowDataList.Last().End = lastmove; ShowDataList.Add(fishdata); lastshowdata.Start = lastshowdata.End = a.DateTime; ShowDataList.Add(lastshowdata); } End :; lastmove = a.DateTime; } } var tmplist = ShowDataList; ShowDataList = new List <Data.ShowData>(); foreach (var i in tmplist) { if (ShowDataList.Count > 0 && i.Action == ShowDataList.Last().Action&& i.Title == ShowDataList.Last().Title) { ShowDataList.Last().End = i.End; } else if (i.Ticks > Consts.MinimumCountTimeSpan.Ticks) { ShowDataList.Add(i); } else if (ShowDataList.Count > 0) { ShowDataList.Last().End = i.End; } } if (ShowDataList.Count == 0) { return(0); } double totalTime = (ShowDataList.Last().End - ShowDataList[0].Start).Ticks; foreach (var data in ShowDataList) { bool newdata = true; foreach (var old in SectorDataList) { if (old.Action == data.Action && old.Title == data.Title) { newdata = false; old.Ticks += data.Ticks; data.Color = old.Color; } } if (newdata) { data.Color = Consts.NextBrush; var TSD = new Data.ShowData(data); SectorDataList.Add(TSD); } } SectorDataList.Sort((Data.ShowData x, Data.ShowData y) => { return(y.Ticks.CompareTo(x.Ticks)); }); return(totalTime); }