Maks150988
Advanced Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Колбэк: Код: function ThreadCallback(LpParameter: PThreadParams): DWORD; stdcall; var i: Integer; h: THandle; s1,s2: WideString; begin Result := 0; SetThreadPriority(thread, THREAD_PRIORITY_LOWEST); h := GetDlgItem(LpParameter.Handle, IDC_TITLE); s1 := LpParameter.pszAnsi; Dispose(LpParameter); i := 0; repeat Inc(i); s2 := FormatW('i = %d', [i]); SendMessageW(h, WM_SETTEXT, 0, LPARAM(LPWSTR(s2))); Sleep(150); until (i >= 100) or terminate; if not terminate then SendMessageW(h, WM_SETTEXT, 0, LPARAM(LPWSTR(s1))); CloseHandle(thread); thread := 0; end; | Пуск: Код: SendMessageW(hWnd, WM_COMMAND, MakeWParam(IDC_STOP, BN_CLICKED), 0); if ((thread = 0) and terminate) then begin New(params); if (params <> nil) then begin params.Handle := hWnd; params.pszAnsi := 'text'; terminate := FALSE; thread := CreateThread( nil, 0, @ThreadCallback, params, 0, ThreadID ); end; end; | Стоп: Код: terminate := TRUE; if (thread <> 0) then WaitForSingleObject(thread, 500); if (thread <> 0) then begin GetExitCodeThread(thread, dwRet); TerminateThread(thread, dwRet); CloseHandle(thread); thread := 0; end; | |