Solved

Progress bar and redetecting a device

Posted on 2003-12-10
3
263 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
Comment Utility
Please show your code.
0
 

Author Comment

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

Author Comment

by:xenia27
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

771 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

10 Experts available now in Live!

Get 1:1 Help Now