//------------------------------------------------------------------------------
/*
Copyright (C) 2007 by Roland Bennett
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//------------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//------------------------------------------------------------------------------
#include "formMain.h"
#include "formAddItem.h"
#include "formRules.h"
#include "formAbout.h"
#include <DateUtils.hpp>
#include <Dialogs.hpp>
#include <IniFiles.hpp>
#include <stdio.h>
#include <winuser.h>
#include <psapi.h>
#include <StrUtils.hpp>
//------------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
#pragma warn -8004
//------------------------------------------------------------------------------
// Imagelist constants.
#define IMG_INDEX_RESERVED (0)
#define IMG_INDEX_TASK_PLAY (1)
#define IMG_INDEX_TASK_PAUSE (2)
#define IMG_INDEX_SIGMA_WINDOW (3)
#define IMG_INDEX_WINDOW (4)
#define IMG_INDEX_SIGMA_TASK (5)
#define IMG_INDEX_TT_PLAY (6)
#define IMG_INDEX_TT (7)
#define IMG_INDEX_DOWN_ARROW (8)
#define IMG_INDEX_UP_ARROW (9)
//------------------------------------------------------------------------------
TMainForm *MainForm;
//------------------------------------------------------------------------------
// Used in compare callback functions and in the class.
static enum { sortWindow,
sortTime,
sortModule,
sortPercentage,
sortStarted
} sortColumn;
static const AnsiString WINDOW_TOTAL_COLUMN_NAME = "WINDOW TOTAL:";
static const AnsiString TASK_TOTAL_COLUMN_NAME = "TASK TOTAL:";
//------------------------------------------------------------------------------
// Used during call to p_display_list->Sort()
int __fastcall CompareListItems(void *Item1, void *Item2)
{
int result = 0;
TMainForm::ListItem *p_item1, *p_item2;
p_item1 = reinterpret_cast<TMainForm::ListItem*>(Item1);
p_item2 = reinterpret_cast<TMainForm::ListItem*>(Item2);
// Prevent an access violation. Without this code...crash?!
if (p_item1->item_name.AnsiCompare(p_item2->item_name) == 0)
{
return (0);
}
// Force totals to always be at the bottom of the list.
if (AnsiCompareStr(p_item1->item_name, TASK_TOTAL_COLUMN_NAME) == 0)
{
return (+1);
}
if (AnsiCompareStr(p_item2->item_name, TASK_TOTAL_COLUMN_NAME) == 0)
{
return (-1);
}
if (AnsiCompareStr(p_item1->item_name, WINDOW_TOTAL_COLUMN_NAME) == 0)
{
return (+1);
}
if (AnsiCompareStr(p_item2->item_name, WINDOW_TOTAL_COLUMN_NAME) == 0)
{
return (-1);
}
switch (sortColumn)
{
case sortWindow : result = p_item1->item_name.AnsiCompare(p_item2->item_name);
break;
case sortTime : result = p_item2->active_time.AnsiCompare(p_item1->active_time);
break;
case sortModule : result = p_item1->module_name.AnsiCompare(p_item2->module_name);
break;
case sortPercentage : result = p_item1->percentage.AnsiCompare(p_item2->percentage);
break;
case sortStarted : result = p_item1->started_time.AnsiCompare(p_item2->started_time);
break;
default : result = p_item1->item_name.AnsiCompare(p_item2->item_name);
}; // end switch (sortColumn)
// If the two items are equal, sort again by item_name as second priority.
if (result == 0)
{
result = p_item1->item_name.AnsiCompare(p_item2->item_name);
}
return (result);
}
//------------------------------------------------------------------------------
// Used during call to TList::Sort()
int __fastcall CompareTimes(void *Item1, void *Item2)
{
TMainForm::ItemInfo *p_item1, *p_item2;
p_item1 = reinterpret_cast<TMainForm::ItemInfo*>(Item1);
p_item2 = reinterpret_cast<TMainForm::ItemInfo*>(Item2);
return (p_item2->active_time_seconds - p_item1->active_time_seconds);
}
//------------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner),
MAX_WINDOW_NAME_LENGTH(200),
MAX_MODULE_NAME_LENGTH(200),
isWindows9598(false),
/*
// Now in global scope, for use in callback compare functions.
WINDOW_TOTAL_COLUMN_NAME("WINDOW TOTAL:"),
TASK_TOTAL_COLUMN_NAME("TASK TOTAL:"),
*/
FilterCutoffSeconds(120),
IdleCutoffSeconds(60),
TASK_LIST_FILE_NAME("TaskList.txt"),
ignoreWindowCaptions(false),
promptWhenClosing(true),
saveTasksOnly(false),
isAutoSaveEnabled(false),
isUptimeFileEnabled(true),
total_active_seconds(0),
current_pie_slice(-1),
saveHourFractions(false),
lockStationAfterIdleSeconds(0)
{
p_window_list = new TList();
p_custom_list = new TList();
p_display_list = new TList();
p_current_window_name = new char[MAX_WINDOW_NAME_LENGTH];
p_module_name = new char[MAX_MODULE_NAME_LENGTH];
isFilterViewEnabled = false;
sortColumn = sortWindow;
last_idle_check_ticks = GetTickCount();
app_start_time = Now();
switch (DayOfWeek(app_start_time))
{
case 1: app_start_day = "Sun"; break;
case 2: app_start_day = "Mon"; break;
case 3: app_start_day = "Tue"; break;
case 4: app_start_day = "Wed"; break;
case 5: app_start_day = "Thu"; break;
case 6: app_start_day = "Fri"; break;
case 7: app_start_day = "Sat"; break;
default: app_start_day = "?";
}
AlphaBlend = true;
AlphaBlendValue = 200;
Caption = Application->Title;
DoubleBuffered = false;
list->OwnerData = true; // "Virtual" mode.
list->DoubleBuffered = true;
tree->DoubleBuffered = true;
// Enable Drag&Drop for the tree.
tree->DragMode = dmAutomatic;
// Must be none, otherwise OnCompare event will be called before SubItems
// are added. Manually call AlphaSort() after SubItems have been added.
list->SortType = Comctrls::stNone;
// Place window in bottom left corner.
Left = Screen->WorkAreaWidth - Width;
Top = Screen->WorkAreaHeight - Height;
opendialog->InitialDir = ExtractFileDir(Application->ExeName);
savedialog->InitialDir = ExtractFileDir(Application->ExeName);
timerWindowWatcher->Interval = 1000;
timerWindowWatcher->Enabled = true;
timerDisplay->Interval = 1000;
timerDisplay->Enabled = false;
timerPopupMenu->Interval = 5000;
timerPopupMenu->Enabled = false;
// Most likely will place this app in Startup folder.
WindowState = wsMinimized;
systemtray->Minimize();
// Some API functions do not work on Windows 95/98.
OSVERSIONINFO info;
memset(&info, 0, sizeof(OSVERSIONINFO));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&info);
if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
isWindows9598 = true;
else
isWindows9598 = false;
loadSettings();
if (FileExists(TASK_LIST_FILE_NAME))
{
loadTaskList(TASK_LIST_FILE_NAME);
}
pagecontrol->ActivePage = sheetList;
popul
没有合适的资源?快使用搜索试试~ 我知道了~
formMain.zip_windows forms
共1个文件
cpp:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 123 浏览量
2022-09-14
23:42:09
上传
评论
收藏 15KB ZIP 举报
温馨提示
This is a useful source code to demonstrate multi threading
资源推荐
资源详情
资源评论
收起资源包目录
formMain.zip (1个子文件)
formMain.cpp 74KB
共 1 条
- 1
资源评论
小波思基
- 粉丝: 70
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功