Solved

Progress bar and redetecting a device

Posted on 2003-12-10
3
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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