201 lines
5.4 KiB
C++
201 lines
5.4 KiB
C++
// ---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "GlobalUnit.h"
|
|
#include "ProgressThreadUnit.h";
|
|
#include "ProgressFormUnit.h"
|
|
|
|
#define OPERATION_USER_LOGIN 5
|
|
#define OPERATION_STYLE_UPDATE 9
|
|
#define OPERATION_STYLE_COMPARE 10
|
|
// ---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma resource "*.dfm"
|
|
TProgressForm *ProgressForm;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
__fastcall TProgressForm::TProgressForm(TComponent* Owner) : TForm(Owner)
|
|
{
|
|
m_nMaxPos = m_pgProgBar->Max;
|
|
m_nPos = 0;
|
|
|
|
m_nNextMinPos = 0;
|
|
m_nNextMaxPos = m_nMaxPos;
|
|
m_iOperation = m_iOperationResult = 0;
|
|
|
|
m_pTimer = new TTimer(this);
|
|
m_pTimer->Enabled = false;
|
|
m_pTimer->Interval = 200;
|
|
m_pTimer->OnTimer = TimerProc;
|
|
|
|
m_pThread = new TProgressThread(true, this);
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
__fastcall TProgressForm::~TProgressForm() {
|
|
if (m_pThread)
|
|
delete m_pThread;
|
|
|
|
if (m_pTimer) {
|
|
delete m_pTimer;
|
|
}
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::WMNCHitTest(TWMNCHitTest &Msg) {
|
|
TForm::Dispatch(&Msg);
|
|
|
|
if (Msg.Result == HTCLIENT && Msg.YPos < Top + 24 && Msg.XPos < Left + 274)
|
|
Msg.Result = HTCAPTION;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::ProgressPaint(TObject *Sender) {
|
|
#if 0
|
|
int x = 0;
|
|
// 左侧平铺
|
|
if (m_nPos > 0) {
|
|
for (int i = 0; i < m_nPos / m_nTileWidth + 1; i++) {
|
|
m_pbProgress->Canvas->Draw(x + m_nTileWidth*i, 0, m_bmpTileLeft);
|
|
}
|
|
x += m_nTileWidth;
|
|
}
|
|
|
|
// 右侧平铺
|
|
x = m_nPos;
|
|
if (m_nPos < m_nMaxPos) {
|
|
for (int i = 0; i < (m_nMaxPos - m_nPos) / m_nTileWidth + 1; i++) {
|
|
m_pbProgress->Canvas->Draw(x + m_nTileWidth*i, 0, m_bmpTileRight);
|
|
}
|
|
x += m_nTileWidth;
|
|
}
|
|
#endif
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::UMOperateFailed(TMessage &Message) {
|
|
m_pThread->Terminate();
|
|
ModalResult = Message.WParam;
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::UMOperatePercent(TMessage &Message)
|
|
{
|
|
m_nPos = m_nNextMinPos + Message.WParam * (m_nNextMaxPos - m_nNextMinPos) / 100;
|
|
m_pgProgBar->Position = m_nPos;
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::UMOperateComplete(TMessage &Message) {
|
|
m_pThread->Terminate();
|
|
ModalResult = mrOk;
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::UMOperateNextRange(TMessage &Message) {
|
|
m_nNextMinPos = Message.WParam * m_nMaxPos / 100;
|
|
m_nNextMaxPos = (Message.LParam == 0 ? m_nMaxPos :
|
|
Message.LParam * m_nMaxPos / 100);
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::FormCreate(TObject *Sender) {
|
|
#if 0
|
|
// 绘制圆角窗体
|
|
HRGN hRgn = CreateRoundRectRgn(0, 0, Width + 1, Height + 2, 20, 20);
|
|
SetWindowRgn(Handle, hRgn, false);
|
|
DeleteObject(hRgn);
|
|
#endif
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
int __fastcall TProgressForm::User_Login()
|
|
{
|
|
m_iOperation = OPERATION_USER_LOGIN;
|
|
this->Caption = L"正在登录...";
|
|
m_pTimer->Enabled = true;
|
|
m_pThread->Start();
|
|
|
|
return ShowModal();
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
int __fastcall TProgressForm::Style_Update()
|
|
{
|
|
m_iOperation = OPERATION_STYLE_UPDATE;
|
|
this->Caption = L"正在更新...";
|
|
m_pThread->Start();
|
|
|
|
return ShowModal();
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
int __fastcall TProgressForm::Compare_Style( int idStyle )
|
|
{
|
|
m_iOperation = OPERATION_STYLE_COMPARE;
|
|
this->Caption = L"正在核查...";
|
|
m_iParam = idStyle;
|
|
m_pThread->Start();
|
|
|
|
return ShowModal();
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::Operation()
|
|
{
|
|
switch (m_iOperation) {
|
|
case OPERATION_USER_LOGIN:
|
|
m_iOperationResult = f_CS_Login(&g_infoUser, true);
|
|
PostMessage(Handle, MSG_OPERATE_COMPLETE, 0, 0);
|
|
m_pgProgBar->Position = 100;
|
|
break;
|
|
|
|
case OPERATION_STYLE_UPDATE:
|
|
f_CS_UpdateStyle(g_infoUser.accountInfo.ID, Handle);
|
|
m_pgProgBar->Position = 0;
|
|
break;
|
|
|
|
case OPERATION_STYLE_COMPARE:
|
|
f_CM_CompareStyle( 2, m_iParam, NULL, Handle );
|
|
m_pgProgBar->Position = 0;
|
|
break;
|
|
}
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::TimerProc(TObject* Sender)
|
|
{
|
|
m_nPos += 2;
|
|
|
|
/*
|
|
if( m_nPos>=m_nMaxPos ){
|
|
m_nPos -= m_nMaxPos;
|
|
}
|
|
*/
|
|
if (m_nPos >= m_pgProgBar->Max) {
|
|
m_nPos = 0;
|
|
}
|
|
|
|
m_pgProgBar->Position = m_nPos;
|
|
m_pgProgBar->Invalidate();
|
|
}
|
|
// ---------------------------------------------------------------------------
|
|
|
|
void __fastcall TProgressForm::OnCancelClick(TObject *Sender) {
|
|
if (m_iOperation == OPERATION_USER_LOGIN ||
|
|
m_iOperation == OPERATION_STYLE_UPDATE) {
|
|
m_pTimer->Enabled = false;
|
|
f_CS_CancelOperation();
|
|
m_pThread->Terminate();
|
|
ModalResult = mrCancel;
|
|
|
|
if (m_iOperation == OPERATION_USER_LOGIN) {
|
|
// Send the cancel information
|
|
PostMessage(m_hMain, MSG_UPDATA_LOGOFF, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
// ---------------------------------------------------------------------------
|