Solved

Progress bar and redetecting a device

Posted on 2003-12-10
3
267 Views
Last Modified: 2010-08-05
Hi,

I have this problem...
I have a function (I'm using VC++ 6.0) for detecting COM Ports and showing the progress while detecting.  It works fine but when the second time I call this function.  The progress bar won't show correctly.

First I call "CreateThread" to create a thread to take care of progress bar.  And then, I keep going on detecting COM Ports.  The progress function is a dialog...so I update the progress by calling "SendMessage" and "GetDlgItem"

However, it seems the progress function stucks before I call GetDlgItem...so the whole function won't have the correct handle....Hence, it won't update the progress bar.

My problem is how can I make some adjustments to make this function work?  Or is there any codes I can reference to?  Or some codes I can study?  I don't know if I explain well but please help me!!!  >"<

Xenia
0
Comment
Question by:xenia27
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 9918335
Please show your code.
0
 

Author Comment

by:xenia27
ID: 9918716
Can I send the codes to your email address??  I guess this will be better..thanks...^^
0
 

Author Comment

by:xenia27
ID: 9919324
Ok..here is the codes

first I call CreateThread like this
MainFunc
DlgThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE )ProgressDlg, NULL, 0, &ThreadID);

if (DlgThread != NULL)
  CloseHandle(DlgThread);

Then, I continue doing the detecting part with for loops..and each for-loop, I update the the progress with this
SendMessage(hwndPB, PBM_SETPOS, 50, 0); or
SendMessage(hwndPB, PBM_SETPOS, 100, 0);  Depends on the progress..
***********************************************************
The function of "ProgressDlg" is mainly calling a dialog "DialogBox(hInst, (LPCSTR)IDD_DetectProgress, gHwnd, ProgressDlgProc);"

***********************************************************
The function of "ProgressDlgProc":
BOOL CALLBACK ProgressDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
          case WM_INITDIALOG:
                        hwndDlg = hDlg;
                        hwndPB = GetDlgItem(hDlg, IDC_DetectProgress);
                        StopForProgressBar = FALSE;
                        SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
                        SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);
                  return 0;
      }

      return FALSE;
}

************************************************************

First time I call MainFunc is working fine but the second time I call it...it will detect COM Port correctly; however, the progress won't show at all..only the dialog box but no progress...I have no idea what's wrong?  Please help me to solve this problem...Thanks a lot!!!


Xenia
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question