且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

线程和进度栏问题

更新时间:2022-04-15 22:41:33

在开始阅读之前,请通过发送 ^ ]消息.这将允许您设置栏的比例.

然后在您的读取线程中,发送 PBM_SETPOS [ ^ ]消息想要更新.例如,如果将范围设置为读取的数据的兆字节数,则每次读取该数量时都发送此消息.

如果某种程度上您的读取线程不允许这样做(例如,您使用一条语句而不是较小的块读取所有数据),则可以 ^ ],并每分钟发送一次PBM_SETPOS.但这不是一种非常准确的方法.
Before you begin the reading, initialise the range of your progressbar by sending a PBM_SETRANGE [^]message. This will allow you to set the scale for your bar.

Then in your read-thread, send a PBM_SETPOS[^] message every time you want an update. For example if you set your range to the number of megabytes of data read, send this message every time you''ve read that amount.

If somehow your read-thread doesn''t allow for this (e.g. you read all your data with one statement instead of in smaller chunks) you could set a timer[^] and send a PBM_SETPOS every minute. This isn''t a very accurate way to do it though.


可能是这样的:):
It could be something like this :) :
BEGIN_MESSAGE_MAP(CYourDialog, CDialog)
...
ON_MESSAGE(WM_USER, OnProgress)
...
END_MESSAGE_MAP()

LONG CYourDialog::OnProgress(WPARAM wParam, LPARAM lParam)
{
  int iCur = (int) wParam;
  int iEnd = (int) lParam;

  if (iEnd) {
    m_ctlProgress.SetRange32(0, iEnd);
  } else {
    m_ctlProgress.SetPos(iCur);
  }

  return 0;
}

/*static*/ UINT CYourDialog::ThreadProc(void* pcDlgPointer)
{
  CYourDialog* pcDlg = (CYourDialog*) pcDlgPointer;

  if (pcDlg->GetSafeHwnd()) {
    CYourData cData;
    cData.Init(..);

    int iLen = cData.Length();
    pcDlg->PostMessage(WM_USER, (WPARAM) 0, (LPARAM) iLen);

    int iCurPos(0);
    BYTE byBuffer[CYourData::sm_iMaxLengthPerStep];

    while (pcDlg->IsRunning() && iCurPos < iLen) {
      iCurPos += cData.GetNext(iCurPos, byBuffer, CYourData::sm_iMaxLengthPerStep);
      ...
      pcDlg->PostMessage(WM_USER, (WPARAM) iCurPos, (LPARAM) 0);
      Sleep(0);
    }
  }

  return 0;
}