Code:
void Writer(void *args)
{
Writing = TRUE;
Stop = FALSE;
HANDLE hf;
HWND hProgress = CreateWindowEx(0, PROGRESS_CLASS, NULL,
WS_CHILD | WS_VISIBLE,
20, 20, 260, 17,
hwnd, NULL, hInst, NULL);
if (InitPort())
{
MessageBox(hwnd,L"asdfasdf", L"asdf", 0);
Writing = FALSE;
return;
}
hf = CreateFile(FileName,
GENERIC_READ,
0,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);
if (hf == INVALID_HANDLE_VALUE)
{
MessageBox(hwnd,L"asdf", L"asdf", 0);
Writing = FALSE;
return;
}
DWORD sz = GetFileSize(hf, NULL); // asdfasdf
unsigned CycleCount = sz/(256*20);
SendMessage(hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 20));
DWORD tmpBytesRead;
DWORD Written;
int szName = strlen(TempName);
if (!WriteFile(hComPort, TempName, szName, &Written, NULL))
{
MessageBox(hwnd,L"asdf", L"Ошибка", 0);
Writing = FALSE;
return;
}
if (!WriteFile(hComPort, &STX, 1, &Written, NULL))
{
MessageBox(hwnd,L"asdf", L"asdf", 0);
WriteFile(hComPort, &Eof, 1, &Written, NULL);
Writing = FALSE;
return;
}
int ProgressPos = 0;
unsigned Index = 0;
int CycleIndex = 0;
char buff[256];
int ReadSize = 256;
while (Index < sz)
{
SendMessage(hProgress, PBM_SETPOS, ProgressPos, 0);
CycleIndex++;
if (CycleIndex == CycleCount)
{
CycleIndex = 0;
ProgressPos++;
}
if (Stop)
{
WriteFile(hComPort, &Eof, 1, &Written, NULL);
Writing = FALSE;
CloseHandle(hf);
CloseHandle(hComPort);
return;
}
if ((sz-Index) < 256) ReadSize = sz-Index;
if (!ReadFile(hf, buff, ReadSize, &tmpBytesRead, NULL))
{
MessageBox(hwnd,L"asdf", L"asdf", 0);
WriteFile(hComPort, &Eof, 1, &Written, NULL);
Writing = FALSE;
CloseHandle(hf);
CloseHandle(hComPort);
return;
}
if (Stop) // asdf
{
WriteFile(hComPort, &Eof, 1, &Written, NULL);
Writing = FALSE;
CloseHandle(hf);
CloseHandle(hComPort);
return;
}
if (!WriteFile(hComPort, buff, ReadSize, &Written, NULL))
{
MessageBox(hwnd,L"asdf", L"asdf", 0);
WriteFile(hComPort, &Eof, 1, &Written, NULL);
Writing = FALSE;
CloseHandle(hf);
CloseHandle(hComPort);
return;
}
Index = Index + ReadSize;
}
WriteFile(hComPort, &Eof, 1, &Written, NULL);
Writing = FALSE;
CloseHandle(hf);
CloseHandle(hComPort);
MessageBox(hwnd,L"asdf", L"asdf", 0);
return;
}
Bookmarks