MessageBoxTimeout

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

MessageBoxTimeout

Post 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
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: MessageBoxTimeout

Post by bpd2000 »

Excellent
Thank you Dr. Claudio
BPD
Convert Dream into Reality through HMG
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: MessageBoxTimeout

Post by Rathinagiri »

Great feature Claudio. Wonderful.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: MessageBoxTimeout

Post 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 9204 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
Viva INTERNATIONAL HMG :D
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: MessageBoxTimeout

Post by srvet_claudio »

Thanks Friends :D

PS: the return timeout constant is:

Code: Select all

#define MB_TIMEDOUT 32000
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: MessageBoxTimeout

Post 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
Viva INTERNATIONAL HMG :D
User avatar
quartz565
Posts: 667
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Contact:

Re: MessageBoxTimeout

Post by quartz565 »

Thank you Dr. Claudio

Wonderful !!
Best Regards,
Nikos.

os: Windows Server 2019 - 64
apichit
Posts: 33
Joined: Thu Jun 07, 2012 9:39 am

Re: MessageBoxTimeout

Post by apichit »

Help me please!
I copy source code to Timeout.prg but cannot compile it.
Attachments
Timeout.zip
(1.5 KiB) Downloaded 474 times
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: MessageBoxTimeout

Post by serge_girard »

Really Nice Stuff !

Thank you Claudio, Serge
There's nothing you can do that can't be done...
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: MessageBoxTimeout

Post 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
Viva INTERNATIONAL HMG :D
Post Reply