Message Timer

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Message Timer

Post by Jeff Barnes »

Is there a function to display a Message box with a timer?

What I would like to do is display a box like MsgYesNo() but one that will time out after xx seconds.

It will be used for an auto quit routine but I need to give the user the option to keep the program running. If they do not respond in xx time then the program will close.
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Re: Message Timer

Post by Jack »

I use
MsgWait("Message","Info",2)
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: Message Timer

Post by Jeff Barnes »

Thanks Jack but I need something that gives the user the option to click a button to cancel the timer.
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Message Timer

Post by ukoenig »

Jeff,

maybe a solution ?
1. pressing < cancel > continues and closes the message
2. do nothing, the dialog gets closed reaching 100 %

Image

Image

Image

Best regards
Uwe :?:
Last edited by ukoenig on Sat Mar 29, 2014 10:56 am, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Message Timer

Post by Rick Lipkin »

Jeff

I can't remember where I found this code .. you can easily modify it with a button to close the dialog ..

Rick Lipkin

Code: Select all

//----------------
Func MsgWait( cMessage,nSeconds )

Local oDlg,cSay,oSay

If empty( cMessage )
   cMessage := "Please Wait"
Endif

If empty( nSeconds )
   nSeconds := 1
Endif

cSay := cMessage

DEFINE DIALOG oDlg FROM 10, 10 TO 16, 45

     oDlg:nStyle := nOr( WS_THICKFRAME, WS_POPUP )

   *  oDLG:NSTYLE := nOR( DS_MODALFRAME,  ;
   *                      WS_MINIMIZEBOX        ,  ;
   *                      WS_VISIBLE, WS_CAPTION,  ;
   *                      WS_SYSMENU, WS_THICKFRAME, WS_MAXIMIZEBOX )


     @ 1,2 SAY oSay var cSay of oDLG UPDATE

     oDLG:bStart := { || _HowLong( oDLG, oSAY, @cSAY, nSeconds ) }

ACTIVATE DIALOG oDLG CENTERED

//-----------------
Static Func _HowLong( oDlg,oSay,cSay,nSeconds )

oSay:ReFresh()
SysWait( nSeconds )

oDlg:End()
Return(nil)
 
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Message Timer

Post by ukoenig »

Rick,

I tested it, but Jeff wants to cancel during countdown.
I think using a METER, it shows the reached status.

Best regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
fafi
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Message Timer

Post by fafi »

Hello..

I'm trying to convert to xharbour

regards
fafi

Code: Select all

/***********************************************************************
   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
   ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
   PARTICULAR PURPOSE.

   Copyright 1998 Microsoft Corporation.  All Rights Reserved.
***********************************************************************/

/***********************************************************************
*
*  MsgBox.c
*
*  Abstract:
*
*      Sample program to demonstrate how a program can display a
*      timed message box.
*
***********************************************************************/

#define STRICT
#include <windows.h>


/***********************************************************************
*
*      Overview
*
*      The key to creating a timed message box is exiting the dialog
*      box message loop internal to the message box. Because the
*      message loop for a message box is part of USER, you cannot
*      modify the message loop without using hooks and other such methods.
*
*
*      However, all message loops exit when they receive a
*      WM_QUIT message. Additionally, if a nested message loop
*      receives a WM_QUIT message, the nested message loop must break 
*      the loop and then re-post the quit message so that the next 
*      outer layer can process it.
*
*      Therefore, you can make the nested message loop exit by
*      calling the PostQuitMessage function. 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,
*      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 to run.
*
*      Essentially, you have "tricked" the nested message loop into
*      determining that the application is terminating. When the quit message
*      returns, you consume the quit message. This method effectively cancels
*      the fake quit message that you generated.
*
***********************************************************************/

/***********************************************************************
*
*  Global variables
*
***********************************************************************/
HWND g_hwndTimedOwner;
BOOL g_bTimedOut;


/***********************************************************************
*
*  MessageBoxTimer
*
*      The timer callback function that posts the fake quit message.
*      This function causes the message box to exit because the message box 
*      has determined that the application is exiting.
*
***********************************************************************/
void CALLBACK MessageBoxTimer(HWND hwnd, 
                              UINT uiMsg, 
                              UINT idEvent, 
                              DWORD dwTime)
{
   g_bTimedOut = TRUE;
   if (g_hwndTimedOwner)
      EnableWindow(g_hwndTimedOwner, TRUE);
   PostQuitMessage(0);
}


/***********************************************************************
*
*  TimedMessageBox
*
*      The same as the standard MessageBox, except that TimedMessageBox
*      also accepts a timeout. If the user does not respond within the
*      specified timeout, the value 0 is returned instead of one of the
*      ID* values.
*
***********************************************************************/
int TimedMessageBox(HWND hwndOwner,
                    LPCTSTR pszMessage,
                    LPCTSTR pszTitle,
                    UINT flags,
                    DWORD dwTimeout)
{
   UINT idTimer;
   int iResult;

   g_hwndTimedOwner = NULL;
   g_bTimedOut = FALSE;

   if (hwndOwner && IsWindowEnabled(hwndOwner))
      g_hwndTimedOwner = hwndOwner;

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

   iResult = MessageBox(hwndOwner, pszMessage, pszTitle, flags);

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

   //
   // See if there is a WM_QUIT message in the queue if we timed out.
   // Eat the message so we do not quit the whole application.
   if (g_bTimedOut)
   {
      MSG msg;
      PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
      iResult = -1;
   }

   return iResult;
}


/***********************************************************************
*
*  WinMain
*
*      Program entry point. Demonstrate TimedMessageBox().
*
***********************************************************************/
int WINAPI WinMain(HINSTANCE hinst,
                   HINSTANCE hinstPrev,
                   LPSTR pszCmdLine,
                   int nCmdShow)
{

      UINT uiResult;

      //
      // Ask the user a question. Give the user five seconds to
      // answer the question.
      uiResult = TimedMessageBox(NULL, 
                                 "Does a triangle have three sides?",
                                 "Quiz", 
                                 MB_YESNO,
                                 // NULL first parameter is important.
                                 5000); 


      switch (uiResult) {
      case IDYES:
         MessageBox(NULL, 
                     "That's right!", 
                     "Result", 
                     MB_OK);
         break;

      case IDNO:
         MessageBox(NULL, 
                     "Believe it or not, triangles "
                     "really do have three sides.", 
                     "Result",
                     MB_OK);
         break;

      case -1:
         MessageBox(NULL, 
                     "I sensed some hesitation there.  "
                     "The correct answer is Yes.", 
                     "Result", 
                     MB_OK);
         break;
      }

      return 0;
}

 
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Message Timer

Post by cnavarro »

Fafi

Lo he pasado a Harbour ( no utilizo XHarbour, aunque no creo que haya muchas diferencias )
Puedes probarlo de dos formas y modificarlo si lo necesitas

I've had to Harbour (do not use xHarbour, but do not think there are many differences)
You can try it in two ways and modify if needed

Code: Select all

#include "fivewin.ch"

Function Main()
Local nOp 
               //"What do you want", "Hello", "The correct answer is: YES", "You have not pressed"
 MiWinMain( "Que quieres","Hola","La Respuesta correcta es: SI", "No has pulsado", 10000 )

Return nil
 
O directamente, y en este caso, puedes probar a eliminar la function MIWINMAIN y MWinMain

Or directly, and in this case, you can try to eliminate function MIWINMAIN and MWinMain

Code: Select all

#include "fivewin.ch"

Function Main()
Local nOp
                                   //"If you do not press it close", "I've read?" 
    nOp := Timermensaje( "Si no pulsas lo cierro", "Lo has leido?", 10000 )
    Do Case
       Case nOp = 0
            ? "No has pulsado"        //"You have not pressed"
       Case nOp = 6
            ? "Has pulsado SI"        //"You pressed YES"
       Case nOp = 7
            ? "Has pulsado NO"       //"You pressed NO"
    EndCase
Return nil

 
Lo que no he probado es a cambiar los valores de retorno ( solo el 0 ), aunque creo que la solucion está en cambiar esas constantes aqui

What I have not tried is to change the return values ​​(only 0), though I think the solution is to change these constants here

Code: Select all

      PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
 

Code: Select all

//---------------------------------------------------------------------------//

#pragma BEGINDUMP
#define STRICT
#include <windows.h>
#include "hbapi.h"

/***********************************************************************
   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
   ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
   PARTICULAR PURPOSE.

   Copyright 1998 Microsoft Corporation.  All Rights Reserved.
***********************************************************************/

/***********************************************************************
*
*  MsgBox.c
*
*  Abstract:
*
*      Sample program to demonstrate how a program can display a
*      timed message box.
*
***********************************************************************/

//#include <windows.h>


/***********************************************************************
*
*      Overview
*
*      The key to creating a timed message box is exiting the dialog
*      box message loop internal to the message box. Because the
*      message loop for a message box is part of USER, you cannot
*      modify the message loop without using hooks and other such methods.
*
*
*      However, all message loops exit when they receive a
*      WM_QUIT message. Additionally, if a nested message loop
*      receives a WM_QUIT message, the nested message loop must break 
*      the loop and then re-post the quit message so that the next 
*      outer layer can process it.
*
*      Therefore, you can make the nested message loop exit by
*      calling the PostQuitMessage function. 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,
*      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 to run.
*
*      Essentially, you have "tricked" the nested message loop into
*      determining that the application is terminating. When the quit message
*      returns, you consume the quit message. This method effectively cancels
*      the fake quit message that you generated.
*
***********************************************************************/

/***********************************************************************
*
*  Global variables
*
***********************************************************************/
HWND g_hwndTimedOwner;
BOOL g_bTimedOut;


/***********************************************************************
*
*  MessageBoxTimer
*
*      The timer callback function that posts the fake quit message.
*      This function causes the message box to exit because the message box 
*      has determined that the application is exiting.
*
***********************************************************************/
void CALLBACK MessageBoxTimer(HWND hwnd, 
                              UINT uiMsg, 
                              UINT idEvent, 
                              DWORD dwTime)
{
   g_bTimedOut = TRUE;
   if (g_hwndTimedOwner)
      EnableWindow(g_hwndTimedOwner, TRUE);
   PostQuitMessage(0);
}


/***********************************************************************
*
*  TimedMessageBox
*
*      The same as the standard MessageBox, except that TimedMessageBox
*      also accepts a timeout. If the user does not respond within the
*      specified timeout, the value 0 is returned instead of one of the
*      ID* values.
*
***********************************************************************/
int TimedMessageBox(HWND hwndOwner,
                    LPCTSTR pszMessage,
                    LPCTSTR pszTitle,
                    UINT flags,
                    DWORD dwTimeout)
{
   UINT idTimer;
   int iResult;

   g_hwndTimedOwner = NULL;
   g_bTimedOut = FALSE;

   if (hwndOwner && IsWindowEnabled(hwndOwner))
      g_hwndTimedOwner = hwndOwner;

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

   iResult = MessageBox(hwndOwner, pszMessage, pszTitle, flags);

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

   //
   // See if there is a WM_QUIT message in the queue if we timed out.
   // Eat the message so we do not quit the whole application.
   if (g_bTimedOut)
   {
      MSG msg;
      PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
      iResult = 0; //-1;
   }

   return iResult;
}


/***********************************************************************
*
*  WinMain
*
*      Program entry point. Demonstrate TimedMessageBox().
*
***********************************************************************/
int WINAPI MWinMain(HINSTANCE hinst,
                   HINSTANCE hinstPrev,
                   LPSTR pszCmdLine,
                   int nCmdShow,
                   LPCTSTR pszMessage,
                   LPCTSTR pszTitle,
                   LPCTSTR pszMensaje,
                   LPCTSTR pszTitMensaje,
                   DWORD dwTimeout )

{

      UINT uiResult;

      //
      // Ask the user a question. Give the user five seconds to
      // answer the question.
      uiResult = TimedMessageBox(NULL, 
                                 pszMessage, //"Does a triangle have three sides?",
                                 pszTitle,   //"Quiz", 
                                 MB_YESNO,
                                 // NULL first parameter is important.
                                 dwTimeout ); //5000); 


      switch (uiResult) {
      case IDYES:
         MessageBox(NULL, 
                     "That's right!", 
                     "Result", 
                     MB_OK);
         break;

      case IDNO:
         MessageBox(NULL, 
                     "Believe it or not, triangles "
                     "really do have three sides.", 
                     "Result",
                     MB_OK);
         break;

      case -1:
         MessageBox(NULL,
                     pszMensaje,
                     pszTitMensaje,
                     MB_OK );
                     /* 
                     "I sensed some hesitation there.  "
                     "The correct answer is Yes.", 
                     "Result", 
                     MB_OK);
                     */
         break;
      }

      return 0;
}

//---------------------------------------------------------------------------//
HB_FUNC( MIWINMAIN )   //
{
  
  MWinMain( ( HINSTANCE ) hb_parnl( 6 ), ( HINSTANCE ) hb_parnl( 7 ), 
                ( LPSTR ) hb_parnl( 8 ), hb_parnl( 9 ), 
                hb_parc( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parc( 4 ),
                hb_parnl( 5 )  );
}
//---------------------------------------------------------------------------//
HB_FUNC( TIMERMENSAJE )
{
      UINT uiResult;
      uiResult = TimedMessageBox(NULL, 
                                 hb_parc( 1 ), //pszMessage, //"Does a triangle have three sides?",
                                 hb_parc( 2 ), //pszTitle,   //"Quiz", 
                                 MB_YESNO,
                                 // NULL first parameter is important.
                                 hb_parnl( 3 ) ); //dwTimeout ); //5000); 

     hb_retnl( uiResult );        
}
//---------------------------------------------------------------------------//

#pragma ENDDUMP
 
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
fafi
Posts: 169
Joined: Mon Feb 25, 2008 2:42 am

Re: Message Timer

Post by fafi »

Thank's Mr. Cavarro

I've had another way with xHarbour

regards
fafi

Code: Select all

#include "fivewin.ch"

#define MB_USERICON 128
#define MB_ICONASTERISK 64
#define MB_ICONEXCLAMATION 0x30
#define MB_ICONWARNING 0x30
#define MB_ICONERROR 16
#define MB_ICONHAND 16
#define MB_ICONQUESTION 32
#define MB_OK 0
#define MB_ABORTRETRYIGNORE 2
#define MB_APPLMODAL 0
#define MB_DEFAULT_DESKTOP_ONLY 0x20000
#define MB_HELP 0x4000
#define MB_RIGHT 0x80000
#define MB_RTLREADING 0x100000
#define MB_DEFBUTTON1 0
#define MB_DEFBUTTON2 256
#define MB_DEFBUTTON3 512
#define MB_DEFBUTTON4 0x300
#define MB_ICONINFORMATION 64
#define MB_ICONSTOP 16
#define MB_OKCANCEL 1
#define MB_RETRYCANCEL 5

#define MB_SETFOREGROUND 0x10000
#define MB_SYSTEMMODAL 4096
#define MB_TASKMODAL 0x2000
#define MB_YESNO 4
#define MB_YESNOCANCEL 3
#define MB_ICONMASK 240
#define MB_DEFMASK 3840
#define MB_MODEMASK 0x00003000
#define MB_MISCMASK 0x0000C000
#define MB_NOFOCUS 0x00008000
#define MB_TYPEMASK 15
#define MB_TOPMOST 0x40000
#define MB_CANCELTRYCONTINUE 6

#define IDOK 1
#define IDCANCEL 2
#define IDABORT 3
#define IDRETRY 4
#define IDIGNORE 5
#define IDYES 6
#define IDNO 7
#define IDCLOSE 8
#define IDHELP 9
#define IDTRYAGAIN 10
#define IDCONTINUE 11

#define MB_TIMEDOUT 32000

function Main()

MsgInfoTimeout(3)

MsgYesNoTimeout(5)

MsgOkCancelTimeout(5)

return nil


Procedure MsgInfoTimeout( nTimeout )
Local nFlag, nMilliSeconds, nRet

   nFlag := MB_OK + MB_SETFOREGROUND + MB_SYSTEMMODAL + MB_ICONINFORMATION
   nMilliSeconds := nTimeout * 1000
   nRet := MessageBoxTimeout ("Test a timeout of " + hb_ntos (nTimeout) + " seconds.", "MsgInfo Timeout", nFlag, nMilliSeconds)

DO CASE
   CASE nRet == IDOK
        MsgInfo ( "OK" , "Result" )
   CASE nRet == MB_TIMEDOUT
        MsgInfo ( "TimeOut in " + hb_ntos (nTimeout) + " seconds." , "Result" )
   OTHERWISE
        MsgInfo ( "TimeOut --> nRet = " + hb_ntos (nRet) , "Result" )
ENDCASE

Return


Procedure MsgYesNoTimeout( nTimeout )
Local nFlag, nMilliSeconds, nRet

   nFlag := MB_YESNO + MB_SETFOREGROUND + MB_SYSTEMMODAL + MB_ICONQUESTION
   nMilliSeconds := nTimeout * 1000
   nRet := MessageBoxTimeout ("Test a timeout of " + hb_ntos (nTimeout) + " seconds.", "MsgYesNo Timeout", nFlag, nMilliSeconds)

DO CASE
   CASE nRet == IDYES
        MsgInfo ( "YES" , "Result" )
   CASE nRet == IDNO
        MsgInfo ( "NO" , "Result" )
   CASE nRet == MB_TIMEDOUT
        MsgInfo ( "TimeOut in " + hb_ntos (nTimeout) + " seconds." , "Result" )
   OTHERWISE
        MsgInfo ( "TimeOut --> nRet = " + hb_ntos (nRet) , "Result" )
ENDCASE

Return


Procedure MsgOkCancelTimeout( nTimeout )
Local nFlag, nMilliSeconds, nRet

   nFlag := MB_OKCANCEL + MB_SETFOREGROUND + MB_SYSTEMMODAL + MB_ICONQUESTION
   nMilliSeconds := nTimeout * 1000
   nRet := MessageBoxTimeout ("Test a timeout of " + hb_ntos (nTimeout) + " seconds.", "MsgOkCancel Timeout", nFlag, nMilliSeconds)

DO CASE
   CASE nRet == IDOK
        MsgInfo ( "OK" , "Result" )
   CASE nRet == IDCANCEL 
        MsgInfo ( "CANCEL" , "Result" )
   CASE nRet == MB_TIMEDOUT
        MsgInfo ( "TimeOut in " + hb_ntos (nTimeout) + " seconds." , "Result" )
   OTHERWISE
        MsgInfo ( "TimeOut --> nRet = " + hb_ntos (nRet) , "Result" )
ENDCASE

Return



#pragma BEGINDUMP

#ifdef __POCC__
#define _WIN32_WINNT  0x0500
#else
#define _WIN32_WINNT  0x0400
#endif

#include <windows.h>

#include "hbapi.h"

#ifdef __XHARBOUR__
#include "hbverbld.h"
#if defined( HB_VER_CVSID ) && ( HB_VER_CVSID < 9639 )
#define HB_ISCHAR( n )  ISCHAR( n )
#endif
#if defined( HB_VER_CVSID ) && ( HB_VER_CVSID < 9798 )
#define HB_ISNIL( n )   ISNIL( n )
#endif
#endif

// JK HMG 1.2 Experimental Build 16g
// MessageBoxIndirect( [hWnd], cText, [cCaption], [nStyle], [xIcon], [hInst], [nHelpId], [nProc], [nLang] )
// Contributed by Andy Wos <andywos@unwired.com.au>

HB_FUNC( MESSAGEBOXINDIRECT )
{
   MSGBOXPARAMS mbp;

   mbp.cbSize             = sizeof( MSGBOXPARAMS );
   mbp.hwndOwner          = HB_ISNIL( 1 ) ? GetActiveWindow() : ( HWND ) hb_parnl( 1 );
   mbp.hInstance          = HB_ISNIL( 6 ) ? GetModuleHandle( NULL ) : ( HINSTANCE ) hb_parnl( 6 );
   mbp.lpszText           = HB_ISCHAR( 2 ) ? hb_parc( 2 ) : ( HB_ISNIL( 2 ) ? NULL : MAKEINTRESOURCE( hb_parni( 2 ) ) );
   mbp.lpszCaption        = HB_ISCHAR( 3 ) ? hb_parc( 3 ) : ( HB_ISNIL( 3 ) ? "" : MAKEINTRESOURCE( hb_parni( 3 ) ) );
   mbp.dwStyle            = ( DWORD ) hb_parni( 4 );
   mbp.lpszIcon           = HB_ISCHAR( 5 ) ? hb_parc( 5 ) : ( HB_ISNIL( 5 ) ? NULL : MAKEINTRESOURCE( hb_parni( 5 ) ) );
   mbp.dwContextHelpId    = HB_ISNIL( 7 ) ? 0 : ( DWORD ) hb_parni( 7 );
   mbp.lpfnMsgBoxCallback = HB_ISNIL( 8 ) ? NULL : ( MSGBOXCALLBACK ) hb_parnl( 8 );
   mbp.dwLanguageId       = HB_ISNIL( 9 ) ? MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) : ( DWORD ) hb_parni( 9 );

   hb_retni( ( int ) MessageBoxIndirect( &mbp ) );
}

typedef int ( WINAPI * PMessageBoxTimeout )( HWND, LPCSTR, LPCSTR, UINT, WORD, DWORD );
static PMessageBoxTimeout pMessageBoxTimeout = NULL;

int WINAPI MessageBoxTimeout( HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds )
{
   if( pMessageBoxTimeout == NULL )
   {
      HMODULE hLib = LoadLibrary( "User32.dll" );

      pMessageBoxTimeout = ( PMessageBoxTimeout ) GetProcAddress( hLib, "MessageBoxTimeoutA" );
   }

   if( pMessageBoxTimeout == NULL )
      return FALSE;

   return pMessageBoxTimeout( hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds );
}

//       HMG_MessageBoxTimeout (Text, Caption, nTypeButton, nMilliseconds) ---> Return iRetButton
HB_FUNC( MESSAGEBOXTIMEOUT )
{
   HWND         hWnd           = GetActiveWindow();
   const char * lpText         = ( const char * ) hb_parc( 1 );
   const char * lpCaption      = ( const char * ) hb_parc( 2 );
   UINT         uType          = HB_ISNIL( 3 ) ? MB_OK : ( UINT ) hb_parnl( 3 );
   WORD         wLanguageId    = MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL );
   DWORD        dwMilliseconds = HB_ISNIL( 4 ) ? ( DWORD ) 0xFFFFFFFF : ( DWORD ) hb_parnl( 4 );

   int iRet = MessageBoxTimeout( hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds );

   hb_retni( iRet );
}

#pragma ENDDUMP 




 
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Message Timer

Post by cnavarro »

It is very well
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Post Reply