Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2004.04.25;
Скачать: [xml.tar.bz2];

Вниз

Как определить, "занято" ли окно/приложение?   Найти похожие ветки 

 
Gas   (2004-02-21 14:05) [0]

для того чтобы послать в окно данные (из буфера обмена), необходимо узнать, занято оно или нет, чтобы не потерять их.
Заранее спасибо.


 
Cobalt ©   (2004-02-21 14:06) [1]

IsHangApplication, если не ошибаюсь.
Дальше ищите сами.


 
Gas   (2004-02-21 14:13) [2]

IsHangApplication - не нашел такого в хелпе, можете уточнить?


 
Cobalt ©   (2004-02-21 14:21) [3]

Хм, гугль тоже промолчал в ответ...
Наверное, это ложная память.
Извиняюсь за введение в заблуждение.

Насчёт потери данных - это вряд ли. Если только приложение не подвисло намертво...
Ну, в принципе, можно сделать доп. кодовый поток, из него послать чужому окну SendMessage. Если через N время поток не закончится - значит висит.
ИМХО


 
DVM ©   (2004-02-21 14:25) [4]

You call the IsHungAppWindow function to determine if Microsoft® Windows® considers that a specified application is not responding, or "hung". An application is considered to be not responding if it is not waiting for input, is not in startup processing, and has not called PeekMessage within the internal timeout period of 5 seconds.

Syntax

BOOL IsHungAppWindow(          HWND hWnd
);
Parameters

hWnd
[in] Handle to the window.
Return Value

Returns TRUE if the window stops responding, otherwise returns FALSE. Ghost windows always return TRUE.


 
Gas   (2004-02-21 14:26) [5]

Дело в следующем: надо передать данные из Excel в другую прогу, которая отсылает их на сервер по интернету, других средств кроме как рук нет, и хотелось это дело автоматизировать. Дело в том, что из-за интерфейса этой проги нельзя в ней сразу указать все данные, и при передаче она подвисает и не на что не реагирует, можно было бы конечно банально поставить таймер и отправлять данные по нему, но так как связь не всегда одинаковая и сервак бывает перегружен, возможны различные времена "отрабоки" посылки данных прогой. Поэтому хотелось бы определять когда она послала данные ("отвисла") и только тогда передавать ей новую порцию.


 
Gas   (2004-02-21 14:42) [6]

DVM ©
IsHungAppWindow тоже в хелпе нет...
у меня Delphi 6, гугл сказал что IsHungAppWindow находиться в библиотеке user32.dll, но что-то через uses не могу ее подключить...
Что я делаю не так?


 
DVM ©   (2004-02-21 15:14) [7]


> Что я делаю не так?

Minimum operating systems Windows 2000


 
DVM ©   (2004-02-21 15:15) [8]

Although you can access this function by using LoadLibrary and GetProcAddress combined in Windows versions prior to Windows XP, the function is not accessible using the standard Include file and library linkage. The header files included in Windows XP Service Pack 1 (SP1) and Windows Server 2003 document this function and make it accessible using the appropriate Include file and library linkage. However, this function is not intended for general use. It is recommended that you do not use it in new programs because it might be altered or unavailable in subsequent versions of Windows.


 
Gas   (2004-02-21 15:20) [9]

w2000 sp4
user32.dll лежит в system32


 
DVM ©   (2004-02-21 15:30) [10]

// 1. The Documented way

{
 An application can check if a window is responding to messages by
 sending the WM_NULL message with the SendMessageTimeout function.

 Um zu überprüfen, ob ein anderes Fenster (Anwendung) noch reagiert,
 kann man ihr mit der SendMessageTimeout() API eine WM_NULL Nachricht schicken.
}

function AppIsResponding(ClassName: string): Boolean;
const
 { Specifies the duration, in milliseconds, of the time-out period }
 TIMEOUT = 50;
var
 Res: DWORD;
 h: HWND;
begin
 h := FindWindow(PChar(ClassName), nil);
 if h <> 0 then
   Result := SendMessageTimeOut(H,
     WM_NULL,
     0,
     0,
     SMTO_NORMAL or SMTO_ABORTIFHUNG,
     TIMEOUT,
     Res) <> 0
 else
   ShowMessage(Format("%s not found!", [ClassName]));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if AppIsResponding("OpusApp") then
   { OpusApp is the Class Name of WINWORD }
   ShowMessage("App. responding");
end;

// 2. The Undocumented way

{
 // Translated form C to Delphi by Thomas Stutz
 // Original Code:
 // (c)1999 Ashot Oganesyan K, SmartLine, Inc
 // mailto:ashot@aha.ru, http://www.protect-me.com, http://www.codepile.com

The code doesn"t use the Win32 API SendMessageTimout function to
determine if the target application is responding but calls
undocumented functions from the User32.dll.

--> For NT/2000/XP the IsHungAppWindow() API:

The function IsHungAppWindow retrieves the status (running or not responding)
of the specified application

IsHungAppWindow(Wnd: HWND): // handle to main app"s window
BOOL;

--> For Windows 95/98/ME we call the IsHungThread() API

The function IsHungThread retrieves the status (running or not responding) of
the specified thread

IsHungThread(DWORD dwThreadId): // The thread"s identifier of the main app"s window
BOOL;

Unfortunately, Microsoft doesn"t provide us with the exports symbols in the
User32.lib for these functions, so we should load them dynamically using the
GetModuleHandle and GetProcAddress functions:
}

// For Win9X/ME
function IsAppRespondig9X(dwThreadId: DWORD): Boolean;
type
 TIsHungThread = function(dwThreadId: DWORD): BOOL; stdcall;
var
 hUser32: THandle;
 IsHungThread: TIsHungThread;
begin
 Result := True;
 hUser32 := GetModuleHandle("user32.dll");
 if (hUser32 > 0) then
 begin
   @IsHungThread := GetProcAddress(hUser32, "IsHungThread");
   if Assigned(IsHungThread) then
   begin
     Result := not IsHungThread(dwThreadId);
   end;
 end;
end;

// For Win NT/2000/XP
function IsAppRespondigNT(wnd: HWND): Boolean;
type
 TIsHungAppWindow = function(wnd:hWnd): BOOL; stdcall;
var
 hUser32: THandle;
 IsHungAppWindow: TIsHungAppWindow;
begin
 Result := True;
 hUser32 := GetModuleHandle("user32.dll");
 if (hUser32 > 0) then
 begin
   @IsHungAppWindow := GetProcAddress(hUser32, "IsHungAppWindow");
   if Assigned(IsHungAppWindow) then
   begin
     Result := not IsHungAppWindow(wnd);
   end;
 end;
end;

function IsAppRespondig(Wnd: HWND): Boolean;
begin
if not IsWindow(Wnd) then
begin
  ShowMessage("Incorrect window handle!");
  Exit;
end;
if Win32Platform = VER_PLATFORM_WIN32_NT then
  Result := IsAppRespondigNT(wnd)
else
  Result := IsAppRespondig9X(GetWindowThreadProcessId(Wnd,nil));
end;

// Example: Check if Word is hung/responding

procedure TForm1.Button3Click(Sender: TObject);
var
 Res: DWORD;
 h: HWND;
begin
 // Find Winword by classname
 h := FindWindow(PChar("OpusApp"), nil);
 if h <> 0 then
 begin
   if IsAppRespondig(h) then
     ShowMessage("Word is responding!")
   else
     ShowMessage("Word is not responding!");
 end
 else
   ShowMessage("Word is not open!");
end;


 
Gas   (2004-02-21 15:43) [11]

Тоже самое нашел , спасибо за верные наставления.
достаточно использовать вот это.
function IsAppRespondingNT(wnd: HWND): Boolean;
type
TIsHungAppWindow = function(wnd:hWnd): BOOL; stdcall;
var
hUser32: THandle;
IsHungAppWindow: TIsHungAppWindow;
begin
Result := True;
hUser32 := GetModuleHandle("user32.dll");
if (hUser32 > 0) then
begin
 @IsHungAppWindow := GetProcAddress(hUser32, "IsHungAppWindow");
 if Assigned(IsHungAppWindow) then
 begin
  Result := not IsHungAppWindow(wnd);
 end;
end;
end;

[b]большое спасибо[/b].
Вопрос закрыт.



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2004.04.25;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.075 c
1-1081581846
volser
2004-04-10 11:24
2004.04.25
Рекурсивное удаление каталога


7-1077458116
DuhcmanSoft
2004-02-22 16:55
2004.04.25
Работа с процессами в ОС Win2k


11-1064908577
Yrasikombo
2003-09-30 11:56
2004.04.25
В Delphi 7 выдает ошибку "File not found: Exptlntf.dcu "


4-1077345889
Костя
2004-02-21 09:44
2004.04.25
ExitWindowsEx


3-1080736757
прогерШ
2004-03-31 16:39
2004.04.25
Как отменить при мультиселекте все выделения?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский