Timed message box (easy)

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Timed message box (easy)

Post 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.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It doesn't show any message box here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

What are you running, w2k? Maybe it's not in that. It's in XP and Vista.
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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 :cry:
The user32.lib from PellesC works fine!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I use XP pro. The function seems to be loaded ok as well, but the message box doesn't appear.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

The function returns 0, so does GetLastError_() after it.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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)
 
BERESHEIT
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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) 
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

ts-soft wrote:User32.dll is allways loaded...
No, kernel32.dll is always loaded. User32.dll is just sometimes loaded.
bye,
Daniel
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
DarkDragon
Addict
Addict
Posts: 2345
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post 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.
bye,
Daniel
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@DarkDragon
Better is import of user32.lib, but the version included in pb is to old. Many functions are missing
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply