網站公告 :


Delphi K.Top討論區 » 會員作品發表區(限本人創作發表) » [計時器小工具] 時間到了!!換人玩了!!
發表新文章
 
主題:[計時器小工具] 時間到了!!換人玩了!!
瀏覽次數:1538
dllee
站務副站長




發表:315
回覆:2470
積分:1695
註冊:2002-04-15

發送簡訊給我
#1 發表時間:2005-09-11 00:13:12 IP:211.76.xxx.xxx 未訂閱


這個小工具是為了我的兒子女兒因為與我共用一台電腦彼此分時使用,為了防止兒子女兒超過時間還繼續玩,因此寫了這個小工具,利用電腦計時,時間到了會強制切到一個占滿整個畫面同時會是最上層的視窗,即使切到其他視窗,會立刻切回來:

必需輸入正確的密碼(每次啟動時預設為 0000,可在開始計啟動前設定)才能離開,這個功能在日後,將加入 StatPlus 中,這也是之前提過強迫休息的一個測試,即在時間到了之後,那個占滿整個畫面的視窗要出現固定的時間才會回到原來的狀態,以達到強迫休息的目的。

請注意,如果密碼設定了其他的數值而且忘記了,那就真的很難回到正常狀態喔,叫出工作管理員也無效,請勿按下 Alt+F4 關閉,不然... 您一定會後悔 真的喔,我為了測試,就真的後悔了 確認該存的都存了,不然按了 Alt+F4 可別怪我沒有先提醒喔


C# 初學者請多指教 吃軟也吃硬 dllee.ktop.com.tw dllee's sharespace Fieldbus
------
http://blog.yam.com/dllee/

附加檔案:78205_testTimeUp.zip

dllee
站務副站長




發表:315
回覆:2470
積分:1695
註冊:2002-04-15

發送簡訊給我
#2 發表時間:2005-09-11 20:43:50 IP:211.76.xxx.xxx 未訂閱

公開原始碼(本post內)。

但不包含 StatPlusAPI.h/StatPlusAPI.cpp 的部分,也就是以下函式:
ApplicationSetTopMost();
WindowSetTopMost();
ApplicationClearTopMost();
WindowClearTopMost();
這些函式的作法在本討論區應該可以找到。

■testTimeUpUnit.h

//---------------------------------------------------------------------------

#ifndef testTimeUpUnitH
#define testTimeUpUnitH
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:        // IDE-managed Components
    TTimer *Timer1;
    TPanel *Panel1;
    TButton *Button1;
    TLabel *Label1;
    TEdit *EditPassword;
    TRadioGroup *TimeList;
    void __fastcall Button1Click(TObject *Sender);
    void __fastcall Timer1Timer(TObject *Sender);
private:        // User declarations
public:                // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


■testTimeUpUnit.cpp

//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "testTimeUpUnit.h"
#include "StatPlusAPI.h"
#include "StatPlusTimeUpUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    for(int i=5;i<=200;i+=5)
    TimeList->Items->AddObject(String(i)+String("分鐘"),(TObject*)i);
    TimeList->ItemIndex=5;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if(MessageBox(NULL,"確定要開始了嗎?\n"
        "結束時如果忘記密碼可是很難回到正常畫面喔...",
        "真的確定嗎?",
        MB_OKCANCEL)!=IDOK) return;
    FormStatPlusTimeUp->Password=EditPassword->Text;
    Timer1->Interval=60000*(int)TimeList->Items->Objects[TimeList->ItemIndex];
    Timer1->Enabled=true;
    this->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    Timer1->Enabled=false;
    Application->BringToFront();
    ApplicationSetTopMost();
    FormStatPlusTimeUp->Show();
    FormStatPlusTimeUp->SetFocus();
    WindowSetTopMost(FormStatPlusTimeUp->Handle);
}
//---------------------------------------------------------------------------


■StatPlusTimeUpUnit.h

//---------------------------------------------------------------------------

#ifndef StatPlusTimeUpUnitH
#define StatPlusTimeUpUnitH
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TFormStatPlusTimeUp : public TForm
{
__published:        // IDE-managed Components
    TLabel *Label;
    TTimer *Timer1;
    TTimer *Timer2;
    void __fastcall FormKeyPress(TObject *Sender, char &Key);
    void __fastcall Timer1Timer(TObject *Sender);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
    void __fastcall Timer2Timer(TObject *Sender);
private:        // User declarations
    char KeyString[256];
    unsigned char KeyCount;
public:                // User declarations
    __fastcall TFormStatPlusTimeUp(TComponent* Owner);
    AnsiString DefaultMessage;
    AnsiString Password;
    POINT    LastMousePos;
    bool    CanCloseNow;
};
//---------------------------------------------------------------------------
extern PACKAGE TFormStatPlusTimeUp *FormStatPlusTimeUp;
//---------------------------------------------------------------------------
#endif


■StatPlusTimeUpUnit.cpp

//---------------------------------------------------------------------------

#include
#pragma hdrstop

#include "StatPlusTimeUpUnit.h"
#include "StatPlusAPI.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormStatPlusTimeUp *FormStatPlusTimeUp;
//---------------------------------------------------------------------------
__fastcall TFormStatPlusTimeUp::TFormStatPlusTimeUp(TComponent* Owner)
    : TForm(Owner)
{
    this->DoubleBuffered=true;
    DefaultMessage="時間到了! 換人了!\n\nㄕˊ ㄐㄧㄢ ㄉㄠˋ ˙ㄌㄜ!\n\nㄏㄨㄢˋ ㄖㄣˊ ˙ㄌㄜ!\n\n";
    this->Label->Caption=DefaultMessage;
    KeyCount=0;
    CanCloseNow=true;
}
//---------------------------------------------------------------------------
void __fastcall TFormStatPlusTimeUp::FormKeyPress(TObject *Sender,
        char &Key)
{
    if(Key==0x1B)    // Esc
    {
    KeyCount=0;
    this->Label->Caption=DefaultMessage;
    }
    else if(Key==0x08) // BackSpace
    {
    if(KeyCount!=0) KeyCount--;
    this->Label->Caption=DefaultMessage+AnsiString::StringOfChar('*', KeyCount);
    }
    else if(Key==0x0D) // Enter
    {
    if(Password==AnsiString(KeyString,KeyCount))
    {
        Timer2Timer(Sender); // Close
    }
    KeyCount=0;
    this->Label->Caption=DefaultMessage;
    }
    else        // 一般字元
    {
    KeyString[KeyCount]=Key;
    KeyCount++;
    this->Label->Caption=DefaultMessage+AnsiString::StringOfChar('*', KeyCount);
    }
}
//---------------------------------------------------------------------------
void __fastcall TFormStatPlusTimeUp::Timer1Timer(TObject *Sender)
{ // 每 50mS 把視窗設為前景並設定一次滑鼠位置
    Application->BringToFront();
    ApplicationSetTopMost();
    SetCursorPos(Screen->Width/2,8);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
}
//---------------------------------------------------------------------------
void __fastcall TFormStatPlusTimeUp::FormShow(TObject *Sender)
{
    GetCursorPos(&LastMousePos);
    Timer1->Enabled=true;
    Timer2->Enabled=true; // 最多等 10 分鐘就關閉
    CanCloseNow=false;    // 無法按 Alt+F4
}
//---------------------------------------------------------------------------
void __fastcall TFormStatPlusTimeUp::FormCloseQuery(TObject *Sender,
        bool &CanClose)
{
    CanClose=CanCloseNow;
}
//---------------------------------------------------------------------------
// 最多不讓使用者操作 10 分鐘,以免無法回到正常畫面
void __fastcall TFormStatPlusTimeUp::Timer2Timer(TObject *Sender)
{
    this->Timer1->Enabled=false;
    this->Timer2->Enabled=false;
    CanCloseNow=true;
    ApplicationClearTopMost();
    WindowClearTopMost(this->Handle);
    Close();
    Application->MainForm->Show();
    SetCursorPos(Application->MainForm->Left+100,Application->MainForm->Top+20);
}
//---------------------------------------------------------------------------



C# 初學者請多指教 吃軟也吃硬 dllee.ktop.com.tw StatPlus 系統資源監測器 @ KTOP dllee's sharespace Fieldbus

------
http://blog.yam.com/dllee/

dllee
站務副站長




發表:315
回覆:2470
積分:1695
註冊:2002-04-15

發送簡訊給我
#3 發表時間:2005-10-15 22:53:51 IP:211.76.xxx.xxx 未訂閱

今天應我兒子的要求作了更新,希望能更好用一些。

對於有子女的父母們,可以試試這個小工具,來管制小朋友打電動的時間,
如果使用上有任何問題或建議,可以留言,有空的話,我就會更新它。


C# 初學者請多指教 吃軟也吃硬 dllee.ktop.com.tw dllee's sharespace Beckhoff Fieldbus VMASK

------
http://blog.yam.com/dllee/

系統時間:2010-09-03 19:08:31,  線上使用者 259 / Max 3,401,主題數:92,416,回覆數:208,133。  聯絡我們 | Delphi.ktop討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!

趴趴狗旅遊網大花蓮旅遊網大花蓮民宿網花蓮市旅遊網花蓮市民宿網大南投旅遊網大南投民宿網
日月潭風景區日月潭旅遊網日月潭民宿網台東旅遊網台東民宿網集集旅遊網集集民宿網
關子嶺旅遊網關子嶺民宿網白河旅遊網白河民宿網
. . . . . . . .