Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Using native Windows GUI with Allegro

Credits go to Arthur Kalliokoski for helping out!
This thread is locked; no one can reply to it. rss feed Print
Using native Windows GUI with Allegro
Paul whoknows
Member #5,081
September 2004
avatar

It is possible to use windows GUI (menu bar, combobox, labels, listbox, etc) with Allegro?
I looked at the manual and I only found Shawn's old-AtariST-based-GUI, which is really ugly (btw, I think Allegro 4.2 deserves a better GUI).
I decided to use windowed mode for my level editor and I want to use Windows GUI for that, I also want to use several additional windows if were necessary.

My level editor should look like this:

http://www.freeimagelibrary.com/images/PaulPaul/ss2_3.png

I know there are a lot of free GUIs for Allegro, but I don't want to use them, most Allegro GUIs were designed for games, not for applications, and my level editor should look like a serious application.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Archon
Member #4,195
January 2004
avatar

Quote:

It is possible to use windows GUI (menu bar, combobox, labels, listbox, etc) with Allegro?

Yes.

You should be able to 'blit' Allegro into a picture-box (or any other widget) because they all have HWNDs/HDCs.

Obviously you'll lose that cross-platform ability - maybe someone will recommend wxwidgets or other.

Specter Phoenix
Member #1,425
July 2001
avatar

Off-Topic Question: If Windows uses HWNDs/HDCs what do other OSes use? If anything.

Paul whoknows
Member #5,081
September 2004
avatar

I think I'll need some help:-/
Here is typical "Hellow world" windows program.
How should I add allegro in a program like this?
How can I blit something on it?

1 sizeof(WNDCLASSEX);
2// tyty.cpp : Defines the entry point for the application.
3//
4 
5#include "stdafx.h"
6#include "resource.h"
7 
8#define MAX_LOADSTRING 100
9 
10// Global Variables:
11HINSTANCE hInst; // current instance
12TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
13TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
14 
15// Foward declarations of functions included in this code module:
16ATOM MyRegisterClass(HINSTANCE hInstance);
17BOOL InitInstance(HINSTANCE, int);
18LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
19LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
20 
21int APIENTRY WinMain(HINSTANCE hInstance,
22 HINSTANCE hPrevInstance,
23 LPSTR lpCmdLine,
24 int nCmdShow)
25{
26 // TODO: Place code here.
27 MSG msg;
28 HACCEL hAccelTable;
29 
30 // Initialize global strings
31 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
32 LoadString(hInstance, IDC_TYTY, szWindowClass, MAX_LOADSTRING);
33 MyRegisterClass(hInstance);
34 
35 // Perform application initialization:
36 if (!InitInstance (hInstance, nCmdShow))
37 {
38 return FALSE;
39 }
40 
41 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TYTY);
42 
43 // Main message loop:
44 while (GetMessage(&msg, NULL, 0, 0))
45 {
46 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
47 {
48 TranslateMessage(&msg);
49 DispatchMessage(&msg);
50 }
51 }
52 
53 return msg.wParam;
54}
55 
56 
57 
58//
59// FUNCTION: MyRegisterClass()
60//
61// PURPOSE: Registers the window class.
62//
63// COMMENTS:
64//
65// This function and its usage is only necessary if you want this code
66// to be compatible with Win32 systems prior to the 'RegisterClassEx'
67// function that was added to Windows 95. It is important to call this function
68// so that the application will get 'well formed' small icons associated
69// with it.
70//
71ATOM MyRegisterClass(HINSTANCE hInstance)
72{
73 WNDCLASSEX wcex;
74 
75 wcex.cbSize =
76 wcex.style = CS_HREDRAW | CS_VREDRAW;
77 wcex.lpfnWndProc = (WNDPROC)WndProc;
78 wcex.cbClsExtra = 0;
79 wcex.cbWndExtra = 0;
80 wcex.hInstance = hInstance;
81 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TYTY);
82 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
83 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
84 wcex.lpszMenuName = (LPCSTR)IDC_TYTY;
85 wcex.lpszClassName = szWindowClass;
86 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
87 
88 return RegisterClassEx(&wcex);
89}
90 
91//
92// FUNCTION: InitInstance(HANDLE, int)
93//
94// PURPOSE: Saves instance handle and creates main window
95//
96// COMMENTS:
97//
98// In this function, we save the instance handle in a global variable and
99// create and display the main program window.
100//
101BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
102{
103 HWND hWnd;
104 
105 hInst = hInstance; // Store instance handle in our global variable
106 
107 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
108 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
109 
110 if (!hWnd)
111 {
112 return FALSE;
113 }
114 
115 ShowWindow(hWnd, nCmdShow);
116 UpdateWindow(hWnd);
117 
118 return TRUE;
119}
120 
121//
122// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
123//
124// PURPOSE: Processes messages for the main window.
125//
126// WM_COMMAND - process the application menu
127// WM_PAINT - Paint the main window
128// WM_DESTROY - post a quit message and return
129//
130//
131LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
132{
133 int wmId, wmEvent;
134 PAINTSTRUCT ps;
135 HDC hdc;
136 TCHAR szHello[MAX_LOADSTRING];
137 LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
138 
139 switch (message)
140 {
141 case WM_COMMAND:
142 wmId = LOWORD(wParam);
143 wmEvent = HIWORD(wParam);
144 // Parse the menu selections:
145 switch (wmId)
146 {
147 case IDM_ABOUT:
148 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
149 break;
150 case IDM_EXIT:
151 DestroyWindow(hWnd);
152 break;
153 default:
154 return DefWindowProc(hWnd, message, wParam, lParam);
155 }
156 break;
157 case WM_PAINT:
158 hdc = BeginPaint(hWnd, &ps);
159 // TODO: Add any drawing code here...
160 RECT rt;
161 GetClientRect(hWnd, &rt);
162 DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
163 EndPaint(hWnd, &ps);
164 break;
165 case WM_DESTROY:
166 PostQuitMessage(0);
167 break;
168 default:
169 return DefWindowProc(hWnd, message, wParam, lParam);
170 }
171 return 0;
172}
173 
174// Mesage handler for about box.
175LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
176{
177 switch (message)
178 {
179 case WM_INITDIALOG:
180 return TRUE;
181 
182 case WM_COMMAND:
183 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
184 {
185 EndDialog(hDlg, LOWORD(wParam));
186 return TRUE;
187 }
188 break;
189 }
190 return FALSE;
191}

Quote:

Obviously you'll lose that cross-platform ability

Yes, I am working only on Windows at the moment.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Archon
Member #4,195
January 2004
avatar

I don't know WIN32 API. I tried learning it with DirectX 6 but it was a mistake at my level. I learnt most of the Windows programming stuff via Visual Basic 6.

Look at these functions (and others) described in the Allegro Manual:

win_set_window(HWND wnd);

blit_to_hdc(BITMAP *bitmap, HDC dc, int sx, sy, dx, dy, w, h);

Paul whoknows
Member #5,081
September 2004
avatar

It would be possible to write a wrapper for this purpose instead? so I can keep my code 100% allegro-friendly:D, those win32 code lines hurts my eyes badly every time I see them:(

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Archon
Member #4,195
January 2004
avatar

Quote:

It would be possible to write a wrapper for this purpose instead?

Just a question, are you going to be using the WIN32 widgets only for a map editor? If so, I personally would have just have used C# or VB.NET which is almost as easy as VB6 to do form based applications.

Paul whoknows
Member #5,081
September 2004
avatar

Quote:

Just a question, are you going to be using the WIN32 widgets only for a map editor?

A "map editor" is not what I have in mind, a complex level editor instead, you know (tiles, objects placement, enemies, AI, mission creation, routes, story, etc).
Now I am open to suggestions about which allegro GUI should I try for my level editor (it has to allow comercial usage).
I won't give up so easily;), but now I am working in a prototype and I think it would be stupid to waste my time in such silly details.

Quote:

I personally would have just have used C# or VB.NET which is almost as easy as VB6

I want to make my level editor interactive, so the game "engine" has to be running inside the level editor

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Specter Phoenix
Member #1,425
July 2001
avatar

Why not use QT4 Open Source for Mingw? GUI for all OSes and skinnable too?

Paul whoknows
Member #5,081
September 2004
avatar

Can you give me a link?
Also I am thinking to change from MSVC6 to MingW, but I don't know where to start:-/
Can you give me some advice to install Mingw with Dev-c?

[EDIT]

It seems that QT is something more than a GUI, and it is expensive!

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

It seems that QT is something more than a GUI

So is Win32.

Quote:

and it is expensive!

Expensive, IF you dont want to use the GPL version. Othwerwise its free for linux, osx, and windows.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Archon
Member #4,195
January 2004
avatar

Quote:

Also I am thinking to change from MSVC6 to MingW, but I don't know where to start:-/
Can you give me some advice to install Mingw with Dev-c?

Dev-C++ would come with MinGW unless you get the one that says "IDE only" or "compiler not included".

It's so simple that I did it ::)

Arthur Kalliokoski
Second in Command
February 2005
avatar

Look in /allegro/tests/win for some examples that use regular windows programming stuff along with allegro.

They all watch too much MSNBC... they get ideas.

Paul whoknows
Member #5,081
September 2004
avatar

That's exactly what I wanted!, a true win32-allegro hybrid program.
It seems dibsound.c is the first program featuring resizable windows and a system menu bar using allegro... and win32
Thanks guys!

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Go to: