NO

Author Topic: MessageBoxTimeout  (Read 8047 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
MessageBoxTimeout
« on: August 17, 2010, 09:29:39 AM »
For WinXP ->
Wine 1.2: function doesn't exist
http://www.codeproject.com/KB/cpp/MessageBoxTimeout.aspx
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
//#include "MessageBoxTimeout.h"

#pragma lib "user32.lib"

int WINAPI MessageBoxTimeout(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,
UINT uType,WORD wLanguageId,DWORD dwMilliseconds);

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 =GetModuleHandle(TEXT("user32"));
if (!hLib) hLib = LoadLibrary(TEXT("user32")); // if user32 not imported already
#ifdef UNICODE
//pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(GetModuleHandle(_T("user32")), "MessageBoxTimeoutW");
pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(hLib, "MessageBoxTimeoutW");
#else
//pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(GetModuleHandle(_T("user32")), "MessageBoxTimeoutA");
pMessageBoxTimeout = (PMessageBoxTimeout)GetProcAddress(hLib, "MessageBoxTimeoutA");
#endif
}
if(pMessageBoxTimeout == NULL)
return FALSE;
return pMessageBoxTimeout(hWnd, lpText, lpCaption, uType, wLanguageId, dwMilliseconds);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
int iRc = MessageBoxTimeout(0, TEXT("Test"), TEXT("MessageBoxTimeout"), MB_OK, 0, 2000);
return 0;
}
« Last Edit: August 17, 2010, 10:43:21 AM by timovjl »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 797
    • http://www.vortex.masmcode.com
Re: MessageBoxTimeout
« Reply #1 on: August 17, 2010, 01:04:32 PM »
Hi timovjl,

My apologies if I am missing something but MessageBoxTimeout is already exported by \PellesC\Lib\Win\user32.lib :

Code: [Select]
\PellesC\Bin\podump.exe /IMPORTS \PellesC\Lib\Win\user32.lib
.
.
.
USER32.dll: MessageBoxTimeoutA (_MessageBoxTimeoutA@24)
USER32.dll: MessageBoxTimeoutW (_MessageBoxTimeoutW@24)
.
.

Code: [Select]
#include <windows.h>

WINUSERAPI int WINAPI MessageBoxTimeoutA(HWND,LPCSTR,LPCSTR,UINT,WORD,DWORD);

#define MessageBoxTimeout MessageBoxTimeoutA

#define TIMEOUT_VALUE 5000

 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)

{
MessageBoxTimeout(0,"MessageBoxTimeout demo\nTimeout value = 5000 ms","Hello!",MB_OK,LANG_NEUTRAL,TIMEOUT_VALUE);
return 0;
}
« Last Edit: August 17, 2010, 01:06:11 PM by Vortex »
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: MessageBoxTimeout
« Reply #2 on: August 17, 2010, 02:53:43 PM »
Thanks Vortex!
I missed that.

Unicode support:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#ifdef UNICODE
int WINAPI MessageBoxTimeoutW(HWND hWnd,LPCWSTR lpText, LPCWSTR lpCaption,
        UINT uType, WORD wLanguageId, DWORD dwMilliseconds);
#define MessageBoxTimeout MessageBoxTimeoutW
#else
int WINAPI MessageBoxTimeoutA(HWND hWnd,LPCSTR lpText, LPCSTR lpCaption,
        UINT uType, WORD wLanguageId, DWORD dwMilliseconds);
#define MessageBoxTimeout MessageBoxTimeoutA
#endif

#define TIMEOUT_VALUE 5000

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
MessageBoxTimeout(0,TEXT("MessageBoxTimeout demo\nTimeout value = 5000 ms"),TEXT("Hello!"),MB_OK,LANG_NEUTRAL,TIMEOUT_VALUE);
return 0;
}
May the source be with you