Author Topic: Message / Error Boxes  (Read 5387 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Message / Error Boxes
« on: September 21, 2009 »
How would I use messagebox to display an error message when using TinyPTC_Ext for C / C++ ? As I dont have a window handle / or window instance; meaning the lib takes care of setting up the window stuff.

Thanks,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Message / Error Boxes
« Reply #1 on: September 21, 2009 »
No need for window handle to display a message box, even though tinyptc_ext have a function to retrieve it, just use "ptc_getwindow();"

Code: [Select]
MessageBox(NULL,"Hello","Caption",MB_OK);
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Message / Error Boxes
« Reply #2 on: September 22, 2009 »
NULL == HWND_DESKTOP

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Message / Error Boxes
« Reply #3 on: September 22, 2009 »
In a little confused:

Should I use:

1/ MessageBox( ptc_getwindow(), "Boo!","Something went tits up");
2/ MessageBox( hwnd_desktop, "Boo!","Something went tits up");
3/ MessageBox( Null, "Boo!","Something went tits up"); // and null is the quivalent of hwnd_desktop?
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Message / Error Boxes
« Reply #4 on: September 22, 2009 »
2 and 3 would need to be
Code: [Select]
MessageBox(HWND_DESKTOP, "Boo!","Something went tits up");
MessageBox(NULL, "Boo!","Something went tits up");
and you need a 4th parameter of MB_OK on all 3.

It doesn't matter which you use.  The difference is which window ends up being the parent of the message box, but you don't really care.

Jim
« Last Edit: September 22, 2009 by Jim »
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Message / Error Boxes
« Reply #5 on: September 22, 2009 »
Cheers :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Message / Error Boxes
« Reply #6 on: November 02, 2009 »
ive noticed with using MSVCRTS.lib that it now changes that command to MessageBoxW and the need for (LPSCRT) before messages.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Message / Error Boxes
« Reply #7 on: November 02, 2009 »
I don't think that's the reason, I think you need to go to Project->Properties
Configuration Properties->General->Character Set
and change
Use Unicode Character Set
to
Use Multi-Byte Character Set

Visual Studio these days defaults to a mode where all strings instead of having a single byte for every character it has 2.  That means that it can better deal with foreign languages and all the variety of alphabets that requires.  This is a good thing for real-life applications, in my opinion.  Not so good for tiny-code demos though.

That means that almost every Windows API call that used to take a byte string needs another version that takes a double-byte string.  One is called eg. MessageBoxA the other is called MessageBoxW.
When you include windows.h, it checks to see if you have chosen to build for unicode or not, and does something like this

#ifdef _UNICODE
  #define MessageBox MessageBoxW
#else
  #define MessageBox MessageBoxA
#endif

That makes a 'normal' MessageBox call hook up to the right routine.  I think you've got a mix of ascii (multibyte) and unicode in your app due to mismatch between these two settings.

Jim
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Message / Error Boxes
« Reply #8 on: November 06, 2009 »
Thanks for the heads up dude!

Im also a bit stuck wether or not break; is needed if an error occurs as it tells me I cant use it in the following instance.

for example:

if (sound ==0 )
{
   MessageBox( Null, "Boo!", "Something went tits up", MB_OK);
   break;
}
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Message / Error Boxes
« Reply #9 on: November 06, 2009 »
If you want to quit the program then you need to use
exit(0);
If you use exit, you should #include <stdlib.h>

break is used to jump out of while/do/for loops and to control the drop-through in switch/case statements.
e.g.
for (x=0; x<5; x++)
{  if (x==2) break; }
will only count 0,1,2, but the program will continue.

Do you not have a book that tells you what break does?

Jim








Challenge Trophies Won: