?
Solved

Progress bar and redetecting a device

Posted on 2003-12-10
3
Medium Priority
?
271 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

777 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