#include 'ApiGdi.ch' #include 'Dll.ch' #include 'Xbp.ch' #define CRLF (Chr(13) + Chr(10)) #define INTERNET_MAX_PATH_LENGTH 2048 #define INTERNET_ERROR_BASE 12000 #define ERROR_INTERNET_EXTENDED_ERROR (INTERNET_ERROR_BASE + 3) #define FORMAT_MESSAGE_FROM_SYSTEM 0x00001000 #define MB_BEEPDEFAULT 0xffffffff // A simple beep. If the sound card is not available, // the sound is generated using the speaker. #define MB_OK 0x00000000 // The sound specified as the Windows Default Beep sound. #define MB_ICONERROR 0x00000010 // The sound specified as the Windows Critical Stop sound. #define MB_ICONHAND MB_ICONERROR #define MB_ICONSTOP MB_ICONERROR #define MB_ICONQUESTION 0x00000020 // The sound specified as the Windows Question sound. #define MB_ICONWARNING 0x00000030 // The sound specified as the Windows Exclamation sound. #define MB_ICONEXCLAMATION MB_ICONWARNING #define MB_ICONINFORMATION 0x00000040 // The sound specified as the Windows Asterisk sound. #define MB_ICONASTERISK MB_ICONINFORMATION PROCEDURE Main() LOCAL oDlg, nInd ODlg := XbpDialog():new(AppDesktop(), NIL, {0,0}, {800,600}, NIL, .f.):create() CenterControl(oDlg) SetAppWindow(oDlg:drawingArea) oDlg:show() Confirmbox(NIL, 'About to play MB_BEEPDEFAULT three times') for nInd := 1 to 3 if MessageBeep_(MB_BEEPDEFAULT) == 0 Confirmbox(NIL, GetLastError_()) endif Sleep(30) next Confirmbox(NIL, 'About to play MB_OK three times') for nInd := 1 to 3 if MessageBeep_(MB_OK) == 0 Confirmbox(NIL, GetLastError_()) endif Sleep(30) next Confirmbox(NIL, 'About to play (?????) MB_ICONERROR three times') for nInd := 1 to 3 if MessageBeep_(MB_ICONERROR) == 0 Confirmbox(NIL, GetLastError_()) endif Sleep(30) next Confirmbox(NIL, 'About to play (?????) MB_ICONQUESTION three times') for nInd := 1 to 3 if MessageBeep_(MB_ICONQUESTION) == 0 Confirmbox(NIL, GetLastError_()) endif Sleep(30) next Confirmbox(NIL, 'About to play MB_ICONWARNING three times') for nInd := 1 to 3 if MessageBeep_(MB_ICONWARNING) == 0 Confirmbox(NIL, GetLastError_()) endif Sleep(30) next Confirmbox(NIL, 'About to play MB_ICONINFORMATION three times') for nInd := 1 to 3 if MessageBeep_(MB_ICONINFORMATION) == 0 Confirmbox(NIL, GetLastError_()) endif Sleep(30) next ConfirmBox(NIL, 'Finished', 'THE END', (XBPMB_OK,XBPMB_INFORMATION + XBPMB_SYSMODAL)) oDlg:destroy() RETURN PROCEDURE DbeSys() RETURN PROCEDURE AppSys() Set(_SET_CHARSET, CHARSET_ANSI) RETURN //////////// // STATIC FUNCTION MessageBeep_(nMsgType) // // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebeep // // Returns: 0 -> an error occurred // <> 0 -> Ok ///// STATIC cCall LOCAL nDll if cCall == NIL nDll := ApiLoadDll_('User32.dll') cCall := DllPrepareCall(nDll, DLL_STDCALL, 'MessageBeep') endif if nMsgType == NIL nMsgType := MB_BEEPDEFAULT endif RETURN DllExecuteCall(cCall, nMsgType) //////////// // FUNCTION ApiLoadDll_(cDll) // ///// STATIC aDllLoaded := {} // Dlls carregadas: {{cDllName, nDllHandle}, ...} LOCAL nDllHandle cDll := Lower(AllTrim(cDll)) if Right(cDll, 4) <> '.dll' cDll += '.dll' endif nDllHandle := AScan(aDllLoaded, {|x| x[01] == cDll}) if nDllHandle > 0 nDllHandle := aDllLoaded[nDllHandle, 02] else nDllHandle := DllLoad(cDll) AAdd(aDllLoaded, {cDll, nDllHandle}) endif RETURN nDllHandle //////////// // FUNCTION GetLastError_() // // Returns the error message or "" ///// STATIC cErrorInternet, cGetLast, cFormatError LOCAL nHandle, nLastErr, nExtErr, nLen, cMessage if cGetLast == NIL nHandle := ApiLoadDll_('WinInet.dll') cErrorInternet := DllPrepareCall(nHandle, DLL_STDCALL, 'InternetGetLastResponseInfoA') nHandle := ApiLoadDll_('Kernel32.dll') cGetLast := DllPrepareCall(nHandle, DLL_STDCALL, 'GetLastError') cFormatError := DllPrepareCall(nHandle, DLL_STDCALL, 'FormatMessageA') // DWORD WINAPI FormatMessage(_In_ DWORD dwFlags, // _In_opt_ LPCVOID lpSource, // _In_ DWORD dwMessageId, // _In_ DWORD dwLanguageId, // _Out_ LPTSTR lpBuffer, // _In_ DWORD nSize, // _In_opt_ va_list *Arguments) endif cMessage := '' nLastErr := DllExecuteCall(cGetLast) if nLastErr == ERROR_INTERNET_EXTENDED_ERROR .or.; nLastErr == 0 nExtErr := 0 cMessage := Replicate(Chr(0), INTERNET_MAX_PATH_LENGTH) nLen := 0 DllExecuteCall(cErrorInternet, @nExtErr, @cMessage, @nLen) if nExtErr > 0 cMessage := StrTran(Left(cMessage, nLen), Chr(0), '') if !Empty(cMessage) if Right(cMessage, 2) == CRLF cMessage := Left(cMessage, (Len(cMessage) - 2)) endif cMessage := ('Internet Extended Error: ' + LTrim(Str(nExtErr)) + ', ' + cMessage) endif elseif nLastErr <> 0 cMessage := ('Internet Extended Error ' + LTrim(Str(nLastErr)) + ' without InternetGetLastReponseInfo() information.') endif else cMessage := Replicate(Chr(0), INTERNET_MAX_PATH_LENGTH) nLen := DllExecuteCall(cFormatError, FORMAT_MESSAGE_FROM_SYSTEM,; NIL,; nLastErr,; 0,; @cMessage,; INTERNET_MAX_PATH_LENGTH,; NIL) cMessage := ('GetLastError(): ' + LTrim(Str(nLastErr)) + + ', ' + Left(cMessage, nLen)) endif RETURN cMessage