May 01, 2024, 01:36:58 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Window Region

Started by ExMember001, November 10, 2006, 02:44:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

November 10, 2006, 02:44:36 AM Last Edit: November 10, 2006, 02:46:50 AM by KrYpT
I'm into trying to use an old IBasic pro program by ZeroDog "Custom Window Designer"
the program generate a .rgn file and an IBasic pro skeletton code.

I've manage to show the picture on the window but the region is not cut off

here is the Ibasic code given by the skeletton code (IBasic pro)
and Mine so far... (Aurora)

Anybody see what i'm doing wrong?
i pretty sure that allocateheap as something to do with that, but what should i do? Please.


IBasic PRO

//Custom Window

IMPORT INT SetWindowRgn(UNSIGNED INT hWnd, INT hRgn, INT bRedraw);
IMPORT INT ExtCreateRegion(INT pXform, INT nCount, POINTER lpRgnData);

INT run,BackgroundImage,WinRegion,RegionSize,Region;
STRING RegionName,ImageName;
INT RegionFile;
POINTER RegionData;

#define RegionWidth  500
#define RegionHeight 250

RegionName="AmpKC.rgn"
ImageName="Default.bmp"

OPENWINDOW win,0,0,@RegionWidth,@RegionHeight,@NOCAPTION,0,"",&WinProc
BackGroundImage = LOADIMAGE(getstartpath+ImageName,@IMGSCALABLE)

if (OPENFILE(RegionFile,getstartpath+RegionName,"R")=0)
RegionSize = LEN(RegionFile)
ALLOCMEM RegionData,1,RegionSize
READ RegionFile,RegionData
Region = ExtCreateRegion(0, LEN(RegionData), RegionData)
CLOSEFILE RegionFile
FREEMEM RegionData
SetWindowRgn(win.hwnd, Region, 1)
else
messagebox win,"Error loading "+RegionName,"Warning:"
run=0
endif

SHOWIMAGE win,BackGroundImage,@IMGSCALABLE,0,0,@RegionWidth,@RegionHeight

run=1
waituntil run=0
deleteimage BackgroundImage,@IMGSCALABLE
closewindow win
end

SUB WinProc
SELECT @CLASS
CASE @IDCLOSEWINDOW
run=0
CASE @IDLBUTTONDN
SENDMESSAGE win, (0xA1),2,0
ENDSELECT
RETURN : ENDSUB



Aurora :

import INT SendMessage alias SendMessageA(INT hWnd,UNSIGNED INT Msg,UNSIGNED INT wParam,INT lParam);
IMPORT INT SetWindowRgn(UNSIGNED INT hWnd, INT hRgn, INT bRedraw);
IMPORT INT ExtCreateRegion(INT pXform, INT nCount, POINTER lpRgnData);

//AmpKC definition
class AmpKC:CWINDOW
{
declare AmpKC();
declare _AmpKC();
declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare virtual OnLButtonDown(int  x, int  y, int  flags), int;

declare OpenMain();

RECT rc;
POINT pt;
}

enum CONTROLID
{
Close
}

AmpKC::OpenMain()
{

Create(0,0,500,250,AWS_VISIBLE|AWS_CENTERED|AWS_AUTODRAW,0,"",0);
ModifyStyle(0,AWS_CAPTION); //remove caption

Cimage img;
UNSIGNED INT himg;
INT rgnfile,RegionSize,region;
string RegionName="AmpKC.rgn";
himg = img.LoadFromFile(getstartpath()+"Default.bmp");
rgnfile = OpenFile(getstartpath() + RegionName ,MODE_READ);
if(rgnfile > 0)
{
POINTER RegionData;
RegionSize = GETFILELENGTH(rgnfile);
RegionData = AllocHeap(RegionSize);
READ(rgnfile, RegionData, RegionSize);
region = ExtCreateRegion(0, LEN(RegionData), RegionData);
CLOSEFILE(rgnfile);
FreeHeap(RegionData);
SetWindowRgn(m_hWnd, Region, 1);
img.Render(this,0,0,500,250);
}
else
{
messagebox(this,"Error loading: "+RegionName,"Warning:");
onclose();
}

AddControl(CTBUTTON,"x",450,9,20,20,AWS_VISIBLE|ABS_FLAT,0x0,close);
}

//AmpKC Implementation
AmpKC::AmpKC()
{
}

AmpKC::_AmpKC()
{
}

AmpKC::OnClose(),int
{
Destroy();

return 0;
}

AmpKC::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case close:
    onclose();
}

return 0;
}

AmpKC::OnLButtonDown(int  x, int  y, int  flags), int
{
//set entire window surface as titlebar (to drag window around)
    rc = GetClientRect();
    if (y > rc.top ) & (y < rc.bottom)
{
if (x > rc.left) &(x < rc.right)
{
            SENDMESSAGE(m_hWnd,0xA1,2,0); //TitleBar
}
}

return 0;
}

global sub main()
{
AmpKC amp;
amp.OpenMain();
do {wait(); }until !amp.IsValid();

return 0;
}

Ionic Wind Support Team

Cimage img; is located in a subroutine, so it will be destroyed when that subroutine exits.  Make it a class member variable.
Ionic Wind Support Team

sapero

region = ExtCreateRegion(0, LEN(RegionData), RegionData);
In IBpro RegionData was defined as MEMORY, where len() returned size of allocated memory.
You have defined it as POINTER, so LEN(RegionData) returns 4. You already have the data size in RegionSize variable.
Wow! sizeof(pointer) is now working?

ExMember001

Thanx a lot guys, its working great now  ;D