我编写了一个Win32备份程序,该程序运行良好-但是一旦出现回调事件,它将立即挂起。
在IDC_F_BACKUP和IDC_F_SAVEAS正常工作的情况下调用该函数,但是无论何时输入和输出文件夹 定义并单击“开始”(IDC START),任何其他回调事件(例如,单击鼠标或移动窗口) 将冻结该应用程序(它的图标更改为默认的windoews)。
据我了解,回调函数应在很短的时间内返回。我不知道该怎么实现 要求,因为每当按下“开始”按钮时,备份就会运行30分钟以上。
这是我的Windows程序
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* ========================================================================
** Callback loop for the Windows procedure
** ========================================================================
*/
{
switch(msg) {
//case WM_MOVE:
//case WM_SHOWWINDOW:
//case WM_WINDOWPOSCHANGING:
case WM_PAINT:
case WM_CREATE:
DisplaySettings();
ActivityMonitor(L"\0");
break;
case WM_CLOSE:
DestroyWindow(hWnd);
DestroyWindow(hWnd);
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND: {
switch(LOWORD(wParam)) {
case IDC_START: {
DWORD p;
const WCHAR szEndMsg[]=L"====> backup successfully completed <====";
if((szInpPath[0]==L'?') || (szOutpPath[0]==L'?')) {
MessageBoxW( NULL, L"Path not found", L"Error",MB_OK );
}else {
// create and initialize error log file:
strCopyW(&szOutpPath[nOP_End], (WCHAR*)L"\\skipped_files.log", MAX_PATH);
//MessageBoxW( NULL, szOutpPath, L"Log file", MB_OK );
hLog = _wfopen(szOutpPath, L"a+");
Test((hLog!=0), L"can not create log file");
szOutpPath[nOP_End] = L'\0';
fwprintf(hLog, L"\n\n\n");
for(p=0; p<20; p++) fwprintf(hLog, L"----");
fwprintf(hLog, L"\nBackup starting at %s", szInpPath);
fwprintf(hLog, L"\nFollowing files could not be archived:\n");
// go ...
BackupDirectory(); // <========== this function runs those 30 minutes ....
ActivityMonitor(L" ");
ActivityMonitor(szEndMsg);
fwprintf(hLog, szEndMsg);
InvalidateRect( hWnd, &rcMonitor, TRUE ); // invalidate the monitor area
UpdateWindow(hWnd);
//RedrawWindow(hWnd, &rcMonitor, 0, RDW_UPDATENOW);
fclose(hLog);
DisplaySettings();
szInpPath[nIP_End] = L'\0'; // restore input path
szOutpPath[nOP_End] = L'\0'; // restore output path
}
break;
}
case IDC_F_BACKUP:
nIP_End = SelectPath(hWnd, szInpPath, L"Select the folder to be backed up");
DisplaySettings();
break;
case IDC_F_SAVEAS:
nOP_End = SelectPath(hWnd, szOutpPath, L"Create a folder for this backup");
DisplaySettings();
break;
case IDC_VERSION:
MessageBoxW( NULL, L"\n FolderClone.exe Version 1.1 /MN"
L"\n Create a zip-backup of the selected"
L"\n directory (archive all files per folder,"
L"\n directory structure left unchanged).", L" ? ",MB_OK );
break;
case IDC_F_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
}//switch(LOWORD(wParam))
break;
default:
return DefWindowProcW(hWnd, msg, wParam, lParam);
}//WM_COMMAND
return 0L;
}//switch(msg)
return (0L);
}