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