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

Вниз

Как автоматически ответить на диалоговое окно?   Найти похожие ветки 

 
lipskiy   (2004-02-09 01:39) [0]

Через заданное время нужно автоматически ответить на MessageDlg, желательно индицировать время, но необязательно. Как это можно сделать?


 
nikkie   (2004-02-09 02:04) [1]

/**********************************************************************
*
* Overview
*
* The key to creating a timed message box is exiting the dialog
* box message loop internal to the message box. Since the
* message loop for a message box is part of USER, you cannot
* modify it without using hooks and other such methods.
*
* However, all message loops exit when they receive a
* WM_QUIT message. Furthermore, a nested message loop, if it
* receives a WM_QUIT message, must break the loop and then re-post
* the quit message so that the next outer layer can process it.
*
* Therefore, you can get the nested message loop to exit by
* calling PostQuitMessage(). The nested message loop will
* clean up and post a new quit message. When the MessageBox
* returns, you peek to see if there is a quit message. If so,
* then it means that the message loop was abnormally terminated.
* You also consume the WM_QUIT message instead of re-posting it
* so that the application continues running.
*
* Essentially, you have "tricked" the nested message loop into
* thinking that the application is terminating. When it returns,
* you "eat" the quit message, effectively canceling the fake
* quit that you generated.
*
**********************************************************************/

void CALLBACK
MessageBoxTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
{
PostQuitMessage(0);
}

/***********************************************************************
*
* TimedMessageBox
*
* The same as the standard MessageBox, except it also accepts
* a timeout. If the user does not respond within the
* specified timeout, then the value 0 is returned instead
* of one of the ID* values.
*
**********************************************************************/

UINT
TimedMessageBox(
HWND hwndParent,
LPCTSTR ptszMessage,
LPCTSTR ptszTitle,
UINT flags,
DWORD dwTimeout)
{
UINT idTimer;
UINT uiResult;
MSG msg;

/*
* Set a timer to dismiss the message box.
*/
idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MessageBoxTimer);

uiResult = MessageBox(hwndParent, ptszMessage, ptszTitle, flags);

/*
* Finished with the timer.
*/
KillTimer(NULL, idTimer);

/*
* See if there is a WM_QUIT message in the queue. If so,
* then you timed out. Eat the message so you don"t quit the
* entire application.
*/
if (PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE)) {

/*
* If you timed out, then return zero.
*/
uiResult = 0;
}

return uiResult;
}

я думаю, что MessageBox можно безболезненно заменить на MessageDlg, если хочется именно его использовать.


 
lipskiy   (2004-02-09 02:43) [2]

На самом деле мне хочется именно MessageBox использовать, но для MessageDlg у меня есть код, который позволяет выводить окно поверх остальных (есть такая проблема - когда главная форма погашена, то диалоги возникают под окнами). Так вот этот код для MessageBox почему-то не работает, поэтому и использую MessageDlg.

Я к сожалению не силен в сях, не смогу перевести код на дельфи. Может поможете? Общий принцип понятен, но вот детально...



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

Форум: "Основная";
Текущий архив: 2004.02.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.008 c
1-53450
lokid7
2004-02-06 17:11
2004.02.17
Взаимодействие между двумя классами


1-53616
Анатолий
2004-02-07 12:30
2004.02.17
Опять по автоматическому обнновлению программы


9-53349
Comrad
2003-08-07 11:40
2004.02.17
DDraw.dcu


14-53711
Jony
2004-01-28 14:03
2004.02.17
Как добраться до зараженного файла?


1-53622
don_dampster
2004-02-07 08:12
2004.02.17
ShellListView





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский