Solved

Progress bar and redetecting a device

Posted on 2003-12-10
3
266 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now