Hey there!
I thought that you guys might want to take control of
win32 functions, such as creating buttons, edit boxes and so on.
- Combine AppGameKit with Win32 -
So, I've made that nifty library just for you
What does it look like?
What can you currently do with it?
-
Create & manipulate buttons
-
Create groups
-
Create & manipulate check boxes
-
Create & manipulate edit boxes
-
Simplified displaying message boxes
-
Open save & open dialog and get path from the output
-
Manipulate window - Strip it completely from title bar and all / Set it to fullscreen / Change dimensions
What's yet to come?
-
Radio buttons
-
Dialog boxes
-
Menu
-
?
Please note, that library is Tier 2 only
... because Tier 1 doesn't allow any plugins. For now hopefully.
Not wasting more of your time, here is how to set up the library
1. Put
window_manipulation.cpp &
window_manipulation.h next to template.cpp.
2. Open Core.cpp and inside it
#include "window_manipulation.h"
3. Go to line
151 and under it paste following code:
case WM_ERASEBKGND:
{
HBRUSH g_hbrBackground = CreateSolidBrush(RGB(GETCOLOR(0), GETCOLOR(1), GETCOLOR(2)));
HDC hdcStatic = (HDC)wParam;
SetBkMode(hdcStatic,OPAQUE);
RECT window;
GetWindowRect(GetDesktopWindow(), &window);
FillRect(hdcStatic,&window,g_hbrBackground);
return (LONG)g_hbrBackground;
break;
}
case WM_CTLCOLORDLG:
{
HBRUSH g_hbrBackground = CreateSolidBrush(RGB(GETCOLOR(0), GETCOLOR(1), GETCOLOR(2)));
return (LONG)g_hbrBackground;
}
break;
case WM_CTLCOLORSTATIC:
{
HBRUSH g_hbrBackground = CreateSolidBrush(RGB(GETCOLOR(0), GETCOLOR(1), GETCOLOR(2)));
HDC hdcStatic = (HDC)wParam;
//RECT window;
//GetWindowRect(GetDesktopWindow(), &window);
//FillRect(hdcStatic,&window,g_hbrBackground);
SetTextColor(hdcStatic, RGB(0, 0, 0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LONG)g_hbrBackground;
}
break;
4. Inside template.cpp
#include "window_manipulation.h"
5. Inside window_manipulation.cpp change:
int r = 210;
int g = 210;
int b = 200;
To RGB which you use for all the button's background. For example,
when your buttons are on blue background, set this to:
int r = 0;
int g = 0;
int b = 200;
You're done!
Here are revelant up to date files:
window_manipulation.cpp <330 lines>
#include "window_manipulation.h"
#ifdef AGKWINDOWS
#include <Windows.h>
#include <vector>
#endif
#define IDC_MAIN_BUTTON 101
#define IDC_MAIN_EDIT 10000
int current_button = IDC_MAIN_BUTTON;
int current_edit = IDC_MAIN_EDIT;
int R = 210;
int G = 210;
int B = 200;
std::vector<int> button_pressed;
std::vector<int> button_type;
std::vector<int> handle;
int GCB(void)
{
return current_button;
}
int GCE(void)
{
return current_edit;
}
int GBT(int n)
{
return button_type[n-101];
}
int GETCOLOR(int c)
{
if(c == 0)
return R;
if(c == 1)
return G;
if(c == 2)
return B;
return 0;
}
void SetBTNP(int id, int flag)
{
button_pressed[id] = flag;
}
int GetBTNP(int id)
{
return button_pressed[id];
}
void SetParams(int fullscreen, char* window_title, int width, int height)
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
if(fullscreen == 1)
{
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
SetWindowLongPtr(hWnd, GWL_STYLE,WS_POPUP | WS_VISIBLE);
MoveWindow(hWnd, 0, 0, rc.right, rc.bottom, TRUE);
} else {
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW & (~WS_SIZEBOX) | WS_VISIBLE);
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW & (~WS_SIZEBOX), FALSE);
MoveWindow(hWnd, rc.right/2-width/2, rc.bottom/2-height/2, rect.right-rect.left, rect.bottom-rect.top, TRUE);
}
#endif
}
void StripSizebar(char* window_title, bool strip)
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
if(strip)
SetWindowLongPtr(hWnd,GWL_STYLE,WS_POPUP & (~WS_SIZEBOX) | WS_VISIBLE);
else
SetWindowLongPtr(hWnd,GWL_STYLE,WS_OVERLAPPEDWINDOW & (~WS_SIZEBOX) | WS_VISIBLE);
#endif
}
void Msg(char* text, char* title)
{
#ifdef AGKWINDOWS
MessageBoxA(NULL,text,title,MB_OK);
#endif
}
int Dialog(char* text, char* title)
{
#ifdef AGKWINDOWS
//MessageBox(NULL,text,title,MB_OK | MB_CANCEL);
//TODO
#endif
return 0;
}
int AddEditBox(char* window_title, char* text, int x, int y, int width, int height, bool multiline)
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
HWND hEdit;
if(multiline)
{
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
agk::Str(current_edit),
WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
x,y,width,height,
hWnd,(HMENU)current_edit,
GetModuleHandle(NULL),NULL);
} else {
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
agk::Str(current_edit),
WS_CHILD|WS_VISIBLE,
x,y,width,height,
hWnd,(HMENU)current_edit,
GetModuleHandle(NULL),NULL);
}
SendMessageA(hEdit,WM_SETTEXT,NULL,(LPARAM)text);
current_edit++;
return current_edit-1;
#endif
}
int AddButton(char* window_title, char* text, int x, int y, int width, int height)
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
HWND hButton = CreateWindowEx(NULL,
"BUTTON",
text,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
x, y, width, height,
hWnd,(HMENU)current_button,
GetModuleHandle(NULL),NULL);
SendMessageA(hButton,WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(FALSE,0));
button_pressed.push_back(0);
button_pressed[current_button-101] = 0;
button_type.push_back(0);
button_type[current_button-101] = 1;
handle.push_back(0);
handle[current_button-101] = (int)hButton;
current_button++;
return current_button-1;
#endif
}
void AddGroupBox(char* window_title, char* text, int x, int y, int width, int height)
{
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
HWND hButton = CreateWindowEx(NULL,
"BUTTON",
text,
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
x, y, width, height,
hWnd,(HMENU)100,
GetModuleHandle(NULL),NULL);
}
char* OpenDialog(char* files)
{
#ifdef AGKWINDOWS
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
ofn.hwndOwner = NULL;
if(!files)
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
else
ofn.lpstrFilter = files;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if(GetOpenFileName(&ofn))
{
return szFileName;
}
#endif
}
char* SaveDialog(char* files)
{
#ifdef AGKWINDOWS
OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
ofn.hwndOwner = NULL;
if(!files)
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
else
ofn.lpstrFilter = files;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if(GetSaveFileName(&ofn))
{
return szFileName;
}
#endif
}
void SetEditBoxText(char* window_title, int nmb, char* text)
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW","template");
HWND hWndM = FindWindowEx(hWnd,NULL,"EDIT",agk::Str(nmb));
SendMessageA(hWndM,WM_SETTEXT,NULL,(LPARAM)text);
#endif
}
char* GetEditBoxText( char* window_title, int nmb )
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
HWND hEdit = FindWindowEx(hWnd,NULL,"EDIT",agk::Str(nmb));
int ln = GetWindowTextLength(hEdit);
if(ln > 0)
{
char buffer[256];
SendMessageA(hEdit,
WM_GETTEXT,
sizeof(buffer)/sizeof(buffer[0]),
reinterpret_cast<LPARAM>(buffer));
return buffer;
} else {
return "EMPTY";
}
#endif
}
int GetEditBoxLenght( char* window_title, int nmb )
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
HWND hEdit = FindWindowEx(hWnd,NULL,"EDIT",agk::Str(nmb));
return GetWindowTextLength(hEdit);
#endif
}
int AddCheckBox(char* window_title, char* text, int x, int y, int width, int height)
{
#ifdef AGKWINDOWS
HWND hWnd = FindWindow("OPENGLWINDOW",window_title);
HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
HWND hButton = CreateWindowEx(NULL,
"BUTTON",
text,
WS_VISIBLE | WS_CHILD | BS_LEFTTEXT | BS_AUTOCHECKBOX,
x, y, width, height,
hWnd,(HMENU)current_button,
GetModuleHandle(NULL),NULL);
SendMessageA(hButton,WM_SETFONT,(WPARAM)hfDefault,MAKELPARAM(FALSE,0));
button_pressed.push_back(0);
button_pressed[current_button-101] = 0;
button_type.push_back(2);
button_type[current_button-101] = 2;
handle.push_back(0);
handle[current_button-101] = (int)hButton;
current_button++;
return current_button-1;
#endif
}
void SetItemActive(int nmb, bool active)
{
#ifdef AGKWINDOWS
EnableWindow((HWND)handle[nmb-101],active);
#endif
}
void SetGUIClearColor(int r, int g, int b)
{
R = r;
G = g;
B = b;
}
void ProcessWIN32( void )
{
#ifdef AGKWINDOWS
for(int n=101; n<current_button; n++)
{
if(GBT(n) == 1)
button_pressed[n-101] = 0;
}
#endif
}
int GetButtonPressed(int button_nmb)
{
#ifdef AGKWINDOWS
return button_pressed[button_nmb-101];
#endif
}
window_manipulation.h <34 lines>
#ifndef WINDOW_MANIPULATION_H
#define WINDOW_MANIPULATION_H
#include "agk.h"
using namespace AGK;
void SetParams(int fullscreen, char* window_title, int width, int height);
void StripSizebar(char* window_title, bool strip);
int AddEditBox(char* window_title, char* text, int x, int y, int width, int height, bool multiline);
int AddButton(char* window_title, char* text, int x, int y, int width, int height);
int AddCheckBox(char* window_title, char* text, int x, int y, int width, int height);
void AddGroupBox(char* window_title, char* text, int x, int y, int width, int height);
int GetButtonPressed(int button_nmb);
int GCB(void);
int GCE(void);
int GBT(int n);
int GETCOLOR(int c);
void SetBTNP(int id, int flag);
char* GetEditBoxText( char* window_title, int nmb );
int GetEditBoxLenght( char* window_title, int nmb );
char* OpenDialog(char* files);
char* SaveDialog(char* files);
void SetEditBoxText(char* window_title, int nmb, char* text);
void ProcessWIN32( void );
int GetBTNP(int id);
void SetGUIClearColor(int r, int g, int b);
void Msg(char* text, char* title);
int Dialog(char* text, char* title);
void SetItemActive(int nmb, bool active);
#endif
Up to date tutorials are in the post below! Or either look at the documentation:
DOCUMENTATION
void SetParams(int fullscreen, char* window_title, int width, int height);
FULLSCREEN - pass 0 for windowed or 1 for fullscreen. When passing 1 width and height doesn't matter.
----------------------------------------------------
int AddEditBox(char* window_title, char* text, int x, int y, int width, int height, bool multiline);
Everything's self explanatory, but the last argument:
MULTILINE - pass false to have one line, non-scrolling text. Otherwise you get richbox.
----------------------------------------------------
int AddButton(char* window_title, char* text, int x, int y, int width, int height);
----------------------------------------------------
int AddCheckBox(char* window_title, char* text, int x, int y, int width, int height);
----------------------------------------------------
void AddGroupBox(char* window_title, char* text, int x, int y, int width, int height);
Adds a decorative group box. Text is group's name which is displayed within it.
----------------------------------------------------
int GetButtonPressed(int button_nmb);
Check if button has been pressed / checkbox is selected
----------------------------------------------------
char* GetEditBoxText( char* window_title, int nmb );
Get edit box text.
----------------------------------------------------
int GetEditBoxLenght( char* window_title, int nmb );
Get edit box's text lenght.
----------------------------------------------------
char* OpenDialog(char* files);
char* SaveDialog(char* files);
See tutorials for deeper explanation.
----------------------------------------------------
void SetEditBoxText(char* window_title, int nmb, char* text);
Set's edit's box text.
----------------------------------------------------
void ProcessWIN32( void );
Process everything. Put this at the end of the loop.
----------------------------------------------------
void SetGUIClearColor(int r, int g, int b);
// TODO
----------------------------------------------------
void Msg(char* text, char* title);
Display message box. With OK option only.
----------------------------------------------------
void SetItemActive(int nmb, bool active);
Disable/Enable a button or checkbox or radio button.
Have fun