Page 1 of 1
Timed message box (easy)
Posted: Tue Mar 13, 2007 9:22 pm
by netmaestro
Sometimes it pays to dig through the API dlls and look for those little undocumented gems:
Code: Select all
OpenLibrary (0, "user32.dll")
Prototype MessageBoxTimed(hWnd.l, lpText.s,lpCaption.s, uType.l, wLanguageID.w, dwMilliseconds.l)
Global MessageBoxTimed.MessageBoxTimed = GetFunction(0,"MessageBoxTimeoutA")
MessageBoxTimed(0,"What do you know for sure?","Hey there!",#MB_OK|#MB_SYSTEMMODAL|#MB_ICONQUESTION, 0, 3000)
There's a W version in there too for unicode.
Posted: Tue Mar 13, 2007 9:30 pm
by Trond
It doesn't show any message box here.
Posted: Tue Mar 13, 2007 9:34 pm
by netmaestro
What are you running, w2k? Maybe it's not in that. It's in XP and Vista.
Posted: Tue Mar 13, 2007 9:43 pm
by ts-soft
For Unicode and Ansi:
Code: Select all
Import "user32.lib"
MessageBoxTimed(a.l,b.p-unicode,c.p-unicode,d.l,e.l,f.l) As "_MessageBoxTimeoutW@24"
EndImport
MessageBoxTimed(0,"What do you know for sure?","Hey there!",#MB_OK|#MB_SYSTEMMODAL|#MB_ICONQUESTION, 0, 3000)
But this doesn't work with the user32.lib from pb
The user32.lib from PellesC works fine!
Posted: Tue Mar 13, 2007 10:08 pm
by Trond
I use XP pro. The function seems to be loaded ok as well, but the message box doesn't appear.
Posted: Tue Mar 13, 2007 10:14 pm
by netmaestro
All I can think of would be possibly that languageid parameter is tripping you up being from Norway. If it isn't that I'm stumped.
Posted: Tue Mar 13, 2007 10:49 pm
by Trond
The function returns 0, so does GetLastError_() after it.
Posted: Tue Mar 13, 2007 11:16 pm
by netmaestro
Well it's a bit of a hail mary pass, but it's worth a shot anyway:
Code: Select all
OpenLibrary (0, "user32.dll")
Prototype MessageBoxTimed(hWnd.l, lpText.s,lpCaption.s, uType.l, wLanguageID.w, dwMilliseconds.l)
Global MessageBoxTimed.MessageBoxTimed = GetFunction(0,"MessageBoxTimeoutA")
GetKeyboardLayout_(@layout.l)
langid.w = layout&$FFFF
MessageBoxTimed(0,"What do you know for sure?","Hey there!",#MB_OK|#MB_SYSTEMMODAL|#MB_ICONQUESTION, langid, 3000)
Posted: Wed Mar 14, 2007 6:32 pm
by ts-soft
User32.dll is allways loaded, so you can use this:
Code: Select all
Prototype MessageBoxTimed(hWnd.l, lpText.s,lpCaption.s, uType.l, wLanguageID.w, dwMilliseconds.l)
Global MessageBoxTimed.MessageBoxTimed = GetProcAddress_(GetModuleHandle_("user32.dll"),"MessageBoxTimeoutA")
MessageBoxTimed(0,"What do you know for sure?","Hey there!",#MB_OK|#MB_SYSTEMMODAL|#MB_ICONQUESTION, 0, 3000)
Posted: Wed Mar 14, 2007 7:02 pm
by DarkDragon
ts-soft wrote:User32.dll is allways loaded...
No, kernel32.dll is always loaded. User32.dll is just sometimes loaded.
Posted: Wed Mar 14, 2007 7:12 pm
by ts-soft
@DarkDragon
I have never see any exe compiled by pb that have no DLL Dependency to User32.dll, so the DLL is loaded. Kernel32.dll is also loaded
Posted: Wed Mar 14, 2007 7:22 pm
by DarkDragon
ts-soft wrote:@DarkDragon
I have never see any exe compiled by pb that have no DLL Dependency to User32.dll, so the DLL is loaded. Kernel32.dll is also loaded
Hmm... ok.
Afaik LoadLibrary_ (what PB's OpenLibrary uses) returns the same handle if it was already loaded. So there's no real difference between your's and the one of netmaestro except the one of netmaestro maybe has more future, if Fred takes the "user32.dll" out of the standardly linked libraries.
Posted: Wed Mar 14, 2007 7:25 pm
by ts-soft
@DarkDragon
Better is import of user32.lib, but the version included in pb is to old. Many functions are missing