我正在尝试在我的过程进行时显示进度条...在我的应用程序中,会出现我必须读取文件并操作它们的情况(需要一些时间才能完成)..想要显示进度条在此操作期间..我正在调用的特定函数是 win 32 ...因此,如果您检查下面的代码,我可以在对话框窗口中创建进度条并创建线程现在我不知道如何发布消息以及从何处获取消息和处理...请帮助我..提前致谢
//my function
int Myfunction(....)
{
MSG msg;
HWND dialog = CreateWindowEx(0,WC_DIALOG,L"Proccessing...",WS_OVERLAPPEDWINDOW|WS_VISIBLE,
600,300,280,120,NULL,NULL,NULL,NULL);
HWND pBar = CreateWindowEx(NULL,PROGRESS_CLASS,NULL,WS_CHILD|WS_VISIBLE,40,20,200, 20,
dialog,(HMENU)IDD_PROGRESS,NULL,NULL);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
Dispatch(&message);
}
SendMessage(pBar,PBM_SETRANGE,0,MAKELPARAM(0,noOfFile));
HANDLE getHandle = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)SetFilesForOperation(...),
NULL,NULL,0);
}
LPARAM SetFilesForOperation(...)
{
for(int index = 0;index < noOfFiles; index++)
{
*checkstate = *(checkState + index);
if(*checkstate == -1)
{
*(getFiles+i) = new TCHAR[MAX_PATH];
wcscpy(*(getFiles+i),*(dataFiles +index));
i++;
}
else
{
(*tempDataFiles)->Add(*(dataFiles+index));
*(checkState + localIndex) = *(checkState + index);
localIndex++;
}
PostMessage(pBar,PBM_SETPOS,(WPARAM)index,0);
}
}
EDIT2:使用 AFXTHREAD
//instead of createthread i used AfxBegin thread
ptrThread = AfxBeginThread((AFX_THREADPROC)SetFilesForOperation(pBar,checkstate,checkState,noOfFiles,i,getFilesforcompression,dataFiles,&tempDataFiles,localIndex),
NULL,THREAD_PRIORITY_ABOVE_NORMAL,NULL,NULL,NULL);
for(int index = 0;index < noOfFiles; index++)
{
MSG msg;
*checkstate = *(checkState + index);
if(*checkstate == -1)
{
*(getFilesforcompression+i) = new TCHAR[MAX_PATH];
//*(getFilesforcompression+i) = L"C:\\Documents and Settings\\rakesh\\Desktop\\try2_Extracted";
wcscpy(*(getFilesforcompression+i),*(dataFiles +index));
i++;
}
else
{
(*tempDataFiles)->Add(*(dataFiles+index));
*(checkState + localIndex) = *(checkState + index);
localIndex++;
}
//PostMessage( pBar, PBM_SETPOS, (WPARAM)index, 0 );
PostMessage( pBar, PBM_SETRANGE, 0, MAKELPARAM( 0, noOfFiles ) );
//PostMessage( pBar, PBM_SETPOS, (WPARAM)index, 0 );
PostMessage( pBar, PBM_STEPIT, (WPARAM)index, 0 );
PostMessage( pBar, MSG_PROGRESS_VALUE, 0, 0 );
while(1)
{
while(PeekMessage( &msg, NULL, NULL, NULL, PM_NOREMOVE))
{
AfxGetThread()->PumpMessage();
Sleep(10);
}