MessageBoxTimeout

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 1958
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 32 times
Been thanked: 125 times
Contact:

MessageBoxTimeout

Post by srvet_claudio » Sun Oct 06, 2013 1:15 am

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: 963
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 136 times
Been thanked: 43 times

Post by bpd2000 » Sun Oct 06, 2013 1:51 am

Excellent
Thank you Dr. Claudio
BPD
Convert Dream into Reality through HMG

User avatar
Rathinagiri
Posts: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 142 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Sun Oct 06, 2013 5:08 am

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: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Sun Oct 06, 2013 8:42 am

srvet_claudio wrote:MessageBoxTimeout: an undocumented API function.
Perfect :!: :!: :!:

as always 8-)
YouShouldConfirm.JPG
You should confirm !
YouShouldConfirm.JPG (13.92 KiB) Viewed 2425 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: 1958
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 32 times
Been thanked: 125 times
Contact:

Post by srvet_claudio » Sun Oct 06, 2013 8:40 pm

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: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Mon Oct 07, 2013 9:04 am

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: 475
Joined: Mon Oct 01, 2012 12:37 pm
Location: Thessaloniki, Greece
Has thanked: 121 times
Been thanked: 12 times
Contact:

Post by quartz565 » Mon Oct 07, 2013 11:40 pm

Thank you Dr. Claudio

Wonderful !!
Best Regards,
Nikos.

os: Windows Server 2012 - 64
hw: HP Server E5606, 2.13GHz, 8.00 GB - Intel Xeon CPU

apichit
Posts: 31
Joined: Thu Jun 07, 2012 9:39 am

Post by apichit » Tue Nov 26, 2013 7:30 am

Help me please!
I copy source code to Timeout.prg but cannot compile it.
Attachments
Timeout.zip
(1.5 KiB) Downloaded 118 times

User avatar
serge_girard
Posts: 1907
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 318 times
Been thanked: 74 times
Contact:

Post by serge_girard » Tue Nov 26, 2013 7:56 am

Really Nice Stuff !

Thank you Claudio, Serge

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 247 times
Been thanked: 91 times
Contact:

Post by esgici » Tue Nov 26, 2013 9:17 am

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