The following I wrote when I thought it would be a good idea to custom windows routine. It works (well), but I didn't bother to finish it. As usual, IanM's DBPro Interface is needed.
Header:
#define ICON_PROGRAMICON 0 // Top left, must be 12x12
#define HIT_PROGRAMICON 1
#define ICON_TITLE 1 // Top, must be 1x12
#define HIT_TITLE 2
#define ICON_CLOSE 2 // Top right, must be 12x12
#define HIT_CLOSE 3
#define ICON_LEFT 3 // Middle bar, must be 12x1
#define HIT_LEFT 4
#define ICON_RIGHT 4 // Middle bar, must be 12x1
#define HIT_RIGHT 5
#define ICON_BOTTOMLEFT 5 // Bottom left icon. Must be 12x12
#define HIT_BOTTOMLEFT 6
#define ICON_BOTTOM 6 // Bottom. Must be 1x12
#define HIT_BOTTOM 7
#define ICON_SCALE 7 // Bottom right. Must be 12x12
#define HIT_SCAL 8
#define MAX_WINDOWS 255
// Window flags (deals with state of window)
#define TCAWINDOW_VISIBLE 1
#define TCAWINDOW_HIDDEN 2
typedef struct __ICONS {
DWORD idNum;
DWORD whichIcon;
char fileName[MAX_PATH+1];
DWORD sizeX;
DWORD sizeY;
} __ICONS;
typedef struct __WINDOWS {
DWORD windowNumber;
DWORD bitmapNumber;
DWORD imageNumber;
DWORD spriteNumber;
DWORD xPos;
DWORD yPos;
DWORD xSize;
DWORD ySize;
DWORD backgroundColour;
DWORD alpha;
DWORD stateFlags;
DWORD inFront;
RECT userArea;
} __WINDOWS;
void TCAWINDOWS_API Constructor(void);
void TCAWINDOWS_API Destructor(void);
void TCAWINDOWS_API ReceiveCoreDataPtr( LPVOID pCore );
DWORD TCAWINDOWS_API TCAWindow_Initialise(LPSTR path);
DWORD TCAWINDOWS_API TCAWindow_Create(DWORD xPos,DWORD yPos,DWORD xSize,DWORD ySize,
LPSTR title,DWORD extraAddr,DWORD flags);
DWORD TCAWINDOWS_API TCAWindow_Text(DWORD window,DWORD x,DWORD y,LPSTR string);
DWORD TCAWINDOWS_API TCAWindow_PositionWindow(DWORD window,DWORD xPos,DWORD yPos);
DWORD TCAWINDOWS_API TCAWindow_SetBackgroundColour(DWORD window,DWORD colour);
DWORD TCAWINDOWS_API TCAWindow_SetWindowAlpha(DWORD window,DWORD alpha);
DWORD TCAWINDOWS_API TCAWindow_ShowHideWindow(DWORD window,DWORD show);
DWORD TCAWINDOWS_API TCAWindow_BringToFront(DWORD window);
DWORD TCAWINDOWS_API TCAWindow_DetectHit(DWORD x,DWORD y);
Code:
#include "stdafx.h"
#include "TCAWindows.h"
#include "DBPro.hpp"
#include "io.h"
#include "stdlib.h"
#include "stdio.h"
#include "globstruct.h"
struct GlobStruct *g_pGlob;
using namespace DBPro;
#define ISVALID_WINDOW(x) ((x)>=1 && (x)<=MAX_WINDOWS ? true : false)
DWORD icons[16];
struct __WINDOWS windows[MAX_WINDOWS];
struct __ICONS iconGraphics[]={
{0,ICON_PROGRAMICON,"icon_application",12,12},
{0,ICON_TITLE,"icon_title",1,12},
{0,ICON_CLOSE,"icon_close",12,12},
{0,ICON_LEFT,"icon_left",12,1},
{0,ICON_RIGHT,"icon_right",12,1},
{0,ICON_BOTTOMLEFT,"icon_botleft",12,12},
{0,ICON_BOTTOM,"icon_bottom",1,12},
{0,ICON_SCALE,"icon_scale",12,12},
{0,0,NULL,0,0}
};
#define ISVALID_CREATED(x) (windows[(x)].windowNumber ? true : false)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
void Constructor(void)
{
ZeroMemory(&windows,sizeof(windows));
}
void Destructor(void)
{
//Font_Destructor();
}
void ReceiveCoreDataPtr( LPVOID pCore )
{
// Get Core Data Pointer here
g_pGlob = (GlobStruct*)pCore;
}
DWORD findFreeImage(void)
{
register DWORD index;
index=1;
while (ImageExist(index))
{
index++;
}
return (index);
}
DWORD findFreeBitmap(void)
{
register DWORD index;
index=1;
while (BitmapExist(index))
{
index++;
}
return (index);
}
DWORD findFreeWindow(void)
{
register DWORD index;
for (index=1; index<MAX_WINDOWS; index++)
{
if (windows[index].windowNumber==0)
{
return (index);
}
}
return (0);
}
DWORD findFreeSprite(void)
{
register DWORD index;
index=1;
while (SpriteExist(index))
{
index++;
}
return (index);
}
DWORD TCAWindow_Initialise(LPSTR path)
{
char fullPath[MAX_PATH+1];
register DWORD loop;
loop=0;
while ((iconGraphics[loop].fileName) &&
(strlen(iconGraphics[loop].fileName))>0)
{
ZeroMemory(&fullPath,sizeof(fullPath));
strcpy((char *) &fullPath,path);
if (fullPath[strlen(fullPath)-1]!=(char) '\\')
{
strcat(fullPath,"\\");
}
strcat(fullPath,iconGraphics[loop].fileName);
strcat(fullPath,".BMP");
if (_access(fullPath,00)==0)
{
if ((iconGraphics[loop].idNum=findFreeImage())>0)
{
DBPro::LoadImage((char *) &fullPath,iconGraphics[loop].idNum,1);
iconGraphics[loop].sizeX=ImageWidth(iconGraphics[loop].idNum);
iconGraphics[loop].sizeY=ImageHeight(iconGraphics[loop].idNum);
loop++;
}
else
{
return ((DWORD) false);
}
}
else
{
return ((DWORD) false);
}
}
/*
The application icon and close icons must have the same X & Y size
The title bar icon must have the same height as both, and a width of 1
Left & right icons must have a width between 1 and the application width, and a height of 1
Bottom left & bottom right icons must have the same X & Y size
Bottom icon must have a width of one, and a height of the bottom left icon
*/
if (iconGraphics[ICON_PROGRAMICON].sizeX==iconGraphics[ICON_CLOSE].sizeX &&
iconGraphics[ICON_PROGRAMICON].sizeY==iconGraphics[ICON_CLOSE].sizeY &&
iconGraphics[ICON_TITLE].sizeX==1 &&
iconGraphics[ICON_TITLE].sizeY==iconGraphics[ICON_PROGRAMICON].sizeY &&
(iconGraphics[ICON_LEFT].sizeX>=1 && iconGraphics[ICON_LEFT].sizeX<=iconGraphics[ICON_PROGRAMICON].sizeX) &&
(iconGraphics[ICON_RIGHT].sizeX>=1 && iconGraphics[ICON_RIGHT].sizeX<=iconGraphics[ICON_PROGRAMICON].sizeX) &&
iconGraphics[ICON_BOTTOMLEFT].sizeX==iconGraphics[ICON_SCALE].sizeX &&
iconGraphics[ICON_BOTTOMLEFT].sizeY==iconGraphics[ICON_SCALE].sizeY &&
iconGraphics[ICON_BOTTOM].sizeX==1 &&
iconGraphics[ICON_BOTTOM].sizeY==iconGraphics[ICON_BOTTOMLEFT].sizeY)
{
return ((DWORD) true);
}
return ((DWORD) false);
}
void getUpdatedBitmap(DWORD bitmap,DWORD image,
DWORD x,DWORD y,DWORD dx,DWORD dy)
{
SetCurrentBitmap(bitmap);
if (ImageExist(image)) DeleteImage(image);
GetImage(image,x,y,dx,dy,1);
SetCurrentBitmap(0);
}
void getUserArea(DWORD bitmap,DWORD window)
{
CreateBitmap(bitmap,
windows[window].userArea.right-windows[window].userArea.left,
windows[window].userArea.bottom-windows[window].userArea.top);
SetCurrentBitmap(bitmap);
}
void updateUserArea(DWORD image,DWORD window)
{
GetImage(image,
0,0,
windows[window].userArea.right-windows[window].userArea.left,
windows[window].userArea.bottom-windows[window].userArea.top,
1);
SetCurrentBitmap(windows[window].bitmapNumber);
PasteImage(image,
windows[window].userArea.left,
windows[window].userArea.top,
1);
}
void showHideWindow(DWORD window,DWORD state)
{
if (state==TCAWINDOW_VISIBLE)
{
ShowSprite(windows[window].spriteNumber);
}
else
{
HideSprite(windows[window].spriteNumber);
}
}
DWORD TCAWindow_Create(DWORD xPos,DWORD yPos,DWORD xSize,DWORD ySize,
LPSTR title,DWORD extraAddr,DWORD flags)
{
DWORD windowIndex;
register DWORD loop;
if ((windowIndex=findFreeWindow())>0)
{
// Make sure the x & y size is at least greater than 26x26
if (xSize<26 || ySize<26) return ((DWORD) false);
// Now to create the bitmap
if ((windows[windowIndex].bitmapNumber=findFreeBitmap())>0 &&
(windows[windowIndex].imageNumber=findFreeImage())>0 &&
(windows[windowIndex].spriteNumber=findFreeSprite())>0)
{
// Calculate the user area
windows[windowIndex].windowNumber=windowIndex;
windows[windowIndex].userArea.left=ImageWidth(iconGraphics[ICON_LEFT].idNum);
windows[windowIndex].userArea.top=ImageHeight(iconGraphics[ICON_PROGRAMICON].idNum);
windows[windowIndex].userArea.right=xSize-ImageWidth(iconGraphics[ICON_RIGHT].idNum);
windows[windowIndex].userArea.bottom=ySize-ImageHeight(iconGraphics[ICON_SCALE].idNum);
windows[windowIndex].xSize=xSize;
windows[windowIndex].ySize=ySize;
windows[windowIndex].xPos=xPos;
windows[windowIndex].yPos=yPos;
windows[windowIndex].stateFlags=TCAWINDOW_VISIBLE;
CreateBitmap(windows[windowIndex].bitmapNumber,xSize,ySize);
SetCurrentBitmap(windows[windowIndex].bitmapNumber);
// First, put in all the 12x12 icons
PasteImage(iconGraphics[ICON_PROGRAMICON].idNum,0,0,0);
PasteImage(iconGraphics[ICON_CLOSE].idNum,xSize-ImageWidth(iconGraphics[ICON_CLOSE].idNum),0,0);
PasteImage(iconGraphics[ICON_BOTTOMLEFT].idNum,0,ySize-ImageHeight(iconGraphics[ICON_BOTTOMLEFT].idNum),0);
PasteImage(iconGraphics[ICON_SCALE].idNum,xSize-ImageWidth(iconGraphics[ICON_SCALE].idNum),ySize-ImageHeight(iconGraphics[ICON_SCALE].idNum),0);
// And paste the top and bottom parts
for (loop=ImageWidth(iconGraphics[ICON_PROGRAMICON].idNum); loop<xSize-ImageWidth(iconGraphics[ICON_CLOSE].idNum); loop++)
{
PasteImage(iconGraphics[ICON_TITLE].idNum,loop,0,0);
}
for (loop=ImageWidth(iconGraphics[ICON_BOTTOMLEFT].idNum); loop<xSize-ImageWidth(iconGraphics[ICON_SCALE].idNum); loop++)
{
PasteImage(iconGraphics[ICON_BOTTOM].idNum,loop,ySize-ImageHeight(iconGraphics[ICON_BOTTOM].idNum),0);
}
// Left and right sections now
for (loop=ImageHeight(iconGraphics[ICON_PROGRAMICON].idNum); loop<ySize-ImageHeight(iconGraphics[ICON_BOTTOM].idNum); loop++)
{
PasteImage(iconGraphics[ICON_LEFT].idNum,0,loop,0);
}
for (loop=ImageHeight(iconGraphics[ICON_CLOSE].idNum); loop<ySize-ImageHeight(iconGraphics[ICON_SCALE].idNum); loop++)
{
PasteImage(iconGraphics[ICON_RIGHT].idNum,xSize-ImageWidth(iconGraphics[ICON_RIGHT].idNum),loop,0);
}
// Now to get the image
getUpdatedBitmap(windows[windowIndex].bitmapNumber,windows[windowIndex].imageNumber,
0,0,xSize,ySize);
//Sprite(windows[windowIndex].spriteNumber,xPos,yPos,windows[windowIndex].imageNumber);
//showHideWindow(windowIndex,windows[windowIndex].stateFlags);
// Set this window tp be in front
TCAWindow_BringToFront(windowIndex);
return (windowIndex);
}
}
return ((DWORD) 0);
}
DWORD TCAWindow_Text(DWORD window,DWORD x,DWORD y,LPSTR string)
{
DWORD tempBitmap,tempImage;
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
if ((tempBitmap=findFreeBitmap())>0 &&
(tempImage=findFreeImage())>0)
{
getUserArea(tempBitmap,window);
Text(x,y,string);
updateUserArea(tempImage,window);
DeleteImage(tempImage);
DeleteBitmap(tempBitmap);
getUpdatedBitmap(windows[window].bitmapNumber,
windows[window].imageNumber,
0,0,
windows[window].xSize,
windows[window].ySize);
return (true);
}
}
return (false);
}
DWORD TCAWindow_PositionWindow(DWORD window,DWORD xPos,DWORD yPos)
{
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
windows[window].xPos=xPos;
windows[window].yPos=yPos;
if (windows[window].stateFlags==TCAWINDOW_VISIBLE)
{
Sprite(windows[window].spriteNumber,
windows[window].xPos,
windows[window].yPos,
windows[window].imageNumber);
}
return ((DWORD) true);
}
return ((DWORD) false);
}
DWORD TCAWindow_SetBackgroundColour(DWORD window,DWORD colour)
{
DWORD tempBitmap,tempImage;
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
if ((tempBitmap=findFreeBitmap())>0 &&
(tempImage=findFreeImage())>0)
{
getUserArea(tempBitmap,window);
Cls(colour);
// Rebuild everything else currently displayed
updateUserArea(tempImage,window);
DeleteImage(tempImage);
DeleteBitmap(tempBitmap);
getUpdatedBitmap(windows[window].bitmapNumber,
windows[window].imageNumber,
0,0,
windows[window].xSize,
windows[window].ySize);
return ((DWORD) true);
}
}
return ((DWORD) false);
}
DWORD TCAWindow_SetWindowAlpha(DWORD window,DWORD alpha)
{
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
windows[window].alpha=alpha;
if (windows[window].stateFlags==TCAWINDOW_VISIBLE)
{
SetSpriteAlpha(windows[window].spriteNumber,windows[window].alpha);
}
return ((DWORD) true);
}
return ((DWORD) false);
}
DWORD TCAWindow_ShowHideWindow(DWORD window,DWORD show)
{
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
if (show && windows[window].stateFlags==TCAWINDOW_HIDDEN)
{
windows[window].stateFlags=TCAWINDOW_VISIBLE;
showHideWindow(window,windows[window].stateFlags);
}
else
if (!show && windows[window].stateFlags==TCAWINDOW_VISIBLE)
{
windows[window].stateFlags=TCAWINDOW_HIDDEN;
showHideWindow(window,windows[window].stateFlags);
}
return ((DWORD) true);
}
return ((DWORD) false);
}
DWORD TCAWindow_BringToFront(DWORD window)
{
register DWORD loop;
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
// You cant bring to front a hidden window
if (windows[window].stateFlags==TCAWINDOW_HIDDEN)
{
return ((DWORD) false);
}
// Delete all sprites and redo all except this window
for (loop=1; loop<MAX_WINDOWS; loop++)
{
if (ISVALID_WINDOW(loop) &&
ISVALID_CREATED(loop) &&
windows[loop].spriteNumber &&
SpriteExist(windows[loop].spriteNumber))
{
DeleteSprite(windows[loop].spriteNumber);
windows[loop].inFront=false;
if (loop!=window)
{
if ((windows[loop].spriteNumber=findFreeSprite())>0)
{
Sprite(windows[loop].spriteNumber,
windows[loop].xPos,
windows[loop].yPos,
windows[loop].imageNumber);
if (windows[loop].stateFlags==TCAWINDOW_HIDDEN)
{
HideSprite(windows[loop].spriteNumber);
}
}
}
}
}
// Now for the selected window
if ((windows[window].spriteNumber=findFreeSprite())>0)
{
windows[window].inFront=true;
Sprite(windows[window].spriteNumber,
windows[window].xPos,
windows[window].yPos,
windows[window].imageNumber);
if (windows[loop].stateFlags==TCAWINDOW_HIDDEN)
{
HideSprite(windows[loop].spriteNumber);
}
return ((DWORD) true);
}
}
return ((DWORD) false);
}
DWORD TCAWindow_DetectHit(DWORD x,DWORD y)
{
register DWORD loop,result;
result=0;
for (loop=1; loop<MAX_WINDOWS; loop++)
{
if (ISVALID_CREATED(loop) && windows[loop].stateFlags==TCAWINDOW_VISIBLE)
{
if ((x>=windows[loop].xPos && x<=windows[loop].xPos+windows[loop].xSize) &&
(y>=windows[loop].yPos && y<=windows[loop].yPos+windows[loop].ySize))
{
// Now to find out which section we possibly have clicked in
if ((x>=windows[loop].xPos && x<=windows[loop].xPos+iconGraphics[ICON_PROGRAMICON].sizeX) &&
(y>=windows[loop].yPos && y<=windows[loop].yPos+iconGraphics[ICON_PROGRAMICON].sizeY))
{
return ((HIT_PROGRAMICON<<16) | loop);
}
}
}
}
return (result);
}
// To be amended later
DWORD TCAWindow_SendToBack(DWORD window)
{
register DWORD loop;
if (ISVALID_WINDOW(window) && ISVALID_CREATED(window))
{
// You cant bring to front a hidden window
if (windows[window].stateFlags==TCAWINDOW_HIDDEN)
{
return ((DWORD) false);
}
// Delete all sprites and redo all except this window
for (loop=1; loop<MAX_WINDOWS; loop++)
{
if (ISVALID_WINDOW(loop) &&
ISVALID_CREATED(loop) &&
windows[loop].spriteNumber &&
SpriteExist(windows[loop].spriteNumber))
{
DeleteSprite(windows[loop].spriteNumber);
}
}
// Do the sprite for this window
if ((windows[window].spriteNumber=findFreeSprite())>0)
{
Sprite(windows[window].spriteNumber,
windows[window].xPos,
windows[window].yPos,
windows[window].imageNumber);
if (windows[loop].stateFlags==TCAWINDOW_HIDDEN)
{
HideSprite(windows[loop].spriteNumber);
}
}
// Do all the others
for (loop=1; loop<MAX_WINDOWS; loop++)
{
if (loop!=window)
{
if ((windows[loop].spriteNumber=findFreeSprite())>0)
{
Sprite(windows[loop].spriteNumber,
windows[loop].xPos,
windows[loop].yPos,
windows[loop].imageNumber);
if (windows[loop].stateFlags==TCAWINDOW_HIDDEN)
{
HideSprite(windows[loop].spriteNumber);
}
}
}
}
// Now for the selected window
if ((windows[window].spriteNumber=findFreeSprite())>0)
{
Sprite(windows[window].spriteNumber,
windows[window].xPos,
windows[window].yPos,
windows[window].imageNumber);
if (windows[loop].stateFlags==TCAWINDOW_HIDDEN)
{
HideSprite(windows[loop].spriteNumber);
}
return ((DWORD) true);
}
}
return ((DWORD) false);
The place for all
great plug-ins.
Keep your friends close, and your cats even closer.