Page 1 of 3

MessageBoxTimeout

Posted: Sun Oct 06, 2013 1:15 am
by srvet_claudio
MessageBoxTimeout: an undocumented API function.

Code: Select all

// by Dr. Claudio Soto (October 2013)

#include "hmg.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_TOPMOST 0x40000
#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


Function Main

// HMG_MessageBoxTimeout (Text, Caption, nTypeButton, nMilliseconds) ---> Return iRetButton

   nTypeButton   = MB_OKCANCEL + MB_ICONQUESTION + MB_SYSTEMMODAL
   nMilliseconds = 3000
   nRet = HMG_MessageBoxTimeout ("Hello World!", "MessageBoxTimeout", nTypeButton, nMilliseconds)


DEFINE WINDOW Form_1 ;
	AT 0,0 ;
	WIDTH 400 ;
	HEIGHT 200 ;
	TITLE 'Hello World!' ;
	MAIN ;

   @ 50, 50 LABEL Label_1 VALUE "" AUTOSIZE

END WINDOW

DO CASE
   CASE nRet == IDOK
        Form_1.Label_1.Value := "OK"
   CASE nRet == IDCANCEL 
        Form_1.Label_1.Value := "CANCEL"
   OTHERWISE
        Form_1.Label_1.Value := "TimeOut --> nRet = " + HB_NTOS (nRet)
ENDCASE
 

CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil


#pragma BEGINDUMP

#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"

#include <windows.h>
#include "hbapi.h"


int WINAPI MessageBoxTimeout(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds) 
{
   typedef BOOL (WINAPI *PMessageBoxTimeout)(HWND,LPCTSTR,LPCTSTR,UINT,WORD,DWORD);
   static PMessageBoxTimeout pMessageBoxTimeout = NULL;
   if (pMessageBoxTimeout == NULL) 
   {
      HMODULE hLib = LoadLibrary (_TEXT("User32.dll"));
      #ifdef UNICODE
         pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(hLib, "MessageBoxTimeoutW");
      #else
         pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(hLib, "MessageBoxTimeoutA");
      #endif
   }
   if(pMessageBoxTimeout == NULL)
      return FALSE;
   return pMessageBoxTimeout(hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds);
}


//       HMG_MessageBoxTimeout (Text, Caption, nTypeButton, nMilliseconds) ---> Return iRetButton
HB_FUNC (HMG_MESSAGEBOXTIMEOUT)
{
   HWND  hWnd           = GetActiveWindow();
   TCHAR *lpText        = HMG_parc (1);
   TCHAR *lpCaption     = HMG_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 ((int) iRet);
}


#pragma ENDDUMP

Re: MessageBoxTimeout

Posted: Sun Oct 06, 2013 1:51 am
by bpd2000
Excellent
Thank you Dr. Claudio

Re: MessageBoxTimeout

Posted: Sun Oct 06, 2013 5:08 am
by Rathinagiri
Great feature Claudio. Wonderful.

Re: MessageBoxTimeout

Posted: Sun Oct 06, 2013 8:42 am
by esgici
srvet_claudio wrote:MessageBoxTimeout: an undocumented API function.
Perfect :!: :!: :!:

as always 8-)
You should confirm !
You should confirm !
YouShouldConfirm.JPG (13.92 KiB) Viewed 9338 times

Code: Select all

   nTypeButton   = MB_OKCANCEL + MB_YESNOCANCEL + MB_SYSTEMMODAL
   
   nMilliseconds = 30000
   
   nRet := 0
   
   WHILE nRet # 6
      nRet = HMG_MessageBoxTimeout ("Is Dr. Soto a genius ? ", "You SHOULD Confirm !", nTypeButton, nMilliseconds)
   ENDDO   
Viva HMG, viva Dr. Soto :D

Re: MessageBoxTimeout

Posted: Sun Oct 06, 2013 8:40 pm
by srvet_claudio
Thanks Friends :D

PS: the return timeout constant is:

Code: Select all

#define MB_TIMEDOUT 32000

Re: MessageBoxTimeout

Posted: Mon Oct 07, 2013 9:04 am
by esgici
srvet_claudio wrote:PS: the return timeout constant is:

Code: Select all

#define MB_TIMEDOUT 32000
Thank to hint Dr.

Viva HMG :D

Re: MessageBoxTimeout

Posted: Mon Oct 07, 2013 11:40 pm
by quartz565
Thank you Dr. Claudio

Wonderful !!

Re: MessageBoxTimeout

Posted: Tue Nov 26, 2013 7:30 am
by apichit
Help me please!
I copy source code to Timeout.prg but cannot compile it.

Re: MessageBoxTimeout

Posted: Tue Nov 26, 2013 7:56 am
by serge_girard
Really Nice Stuff !

Thank you Claudio, Serge

Re: MessageBoxTimeout

Posted: Tue Nov 26, 2013 9:17 am
by esgici
Hi Apichit
apichit wrote:Help me please!
I copy source code to Timeout.prg but cannot compile it.
Please clarify cannot compile :?

Here compiled and run fine :arrow:

Happy HMG :D