Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » using only one window (not win32)

This thread is locked; no one can reply to it. rss feed Print
using only one window (not win32)
IronBob
Member #3,248
February 2003
avatar

i want to use only one window. when it starts the program it opens a console and then another window. how do i keep it to one window. i looked in docs and it said win_set_window(HWND wnd); ... but im not using win32 in the program and i cant use the HWND. how do i get it to only one window outside of win32.

23yrold3yrold
Member #1,134
March 2001
avatar

Compile (or rather, link) with the -mwindows switch.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

IronBob
Member #3,248
February 2003
avatar

ok it works. but ive got one more question. how can i stop it from saying the thing about "closing the program my cause errors" when i click the X.

DanielH
Member #934
January 2001
avatar

Check the manual under Using Allegro.

int set_close_button_callback(void (*proc)(void));

IronBob
Member #3,248
February 2003
avatar

ok i cant find set_close_button_callback(). all i see is set_window_close_hook() and set_window_close_button().

[edit]i figured out that its set_window_close_hook() that im looking for but i dont know what i need to enter as an argument for it to close without asking for the "loss of data" thing.

Wetimer
Member #1,622
November 2001

void close_my_game()
{
// do something which will cause your game to close like:
gameover = true;
}

in main:
set_window_close_hook(close_my_game);

<code>if(Windows.State = Crash) Computer.halt();</code>

spellcaster
Member #1,493
September 2001
avatar

Aren't the set_windows_close_XXX functions depricated?

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Evert
Member #794
November 2000
avatar

Quote:

Compile (or rather, link) with the -mwindows switch.

Better still, link with --Wl,--subsystem,windows instead. -mwindows, while shorter and easier to remember, is depricated.

Quote:

Aren't the set_windows_close_XXX functions depricated?

Yes, but emulated for backward compatibility.

gnolam
Member #2,030
March 2002
avatar

How 'bout int set_close_button_callback(void (*proc)(void)); then - that one isn't deprecated, right?

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

spellcaster
Member #1,493
September 2001
avatar

But if they are depricated, doesn't this mean that they
a) won't work as expected (so they go dpericated in the first place)
b) there's a better alternative to use (and that's why they got depricated)

Just curious...

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Evert
Member #794
November 2000
avatar

Quote:

But if they are depricated, doesn't this mean that they

they didn't work as expected. By default, the closebutton handler would close the Allegro window from a callback function, which was something the docs explicidly told you not to do.
Hence, a better alternative was introduced, which makes the old broken functions obsolete. However, some programs used these functions, and in order not to break old sourecode, backward comptaibility inline functions were added.

spellcaster
Member #1,493
September 2001
avatar

Quote:

Hence, a better alternative was introduced,

Ok, what is the better alternative?

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Evert
Member #794
November 2000
avatar

Quote:

Ok, what is the better alternative?

Disable the close button unless the user registers a callback function (using set_close_button_callback()), because it doesn't do anything useful if s/he doesn't.

Frankly, it looks more like a bugfix to me, since Allegro's original handler was broken...

IronBob
Member #3,248
February 2003
avatar

ok well i already tryed using the int set_close_button_callback(void (*proc)(void)); and it says "proc" not found. if i cant get that to work should i just use an empty function?

Evert
Member #794
November 2000
avatar

Quote:

and it says "proc" not found. if i cant get that to work should i just use an empty function?

Post some code, please.
It should look something like this:

void my_callback(void)
{
   //do some stuff
}

...


set_close_button_callback(my_callback);

IronBob
Member #3,248
February 2003
avatar

#include <allegro.h>

int main()
{
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    set_window_close_hook(void (*proc)(void));
    readkey();
    return 0;
} END_OF_MAIN();

MiquelFire
Member #3,110
January 2003
avatar

It should be:
<code>
#include <allegro.h>

void func_name(void)
{
// do something
}

int main()
{
allegro_init();
install_keyboard();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
set_window_close_hook(func_name);
readkey();
return 0;
} END_OF_MAIN();

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

spellcaster
Member #1,493
September 2001
avatar

Oh come on.. Winston posted the solution to your problem already.
Please read the replies you get. Please. Please. Please.

Please.

Pleeeeeeeeeeeeeeeeeeeeeeeeeeeeease.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

IronBob
Member #3,248
February 2003
avatar

ok fine ... i got it.

Go to: