May 01, 2024, 11:05:49 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Borderless and clickable Image control?

Started by Shannara, December 17, 2006, 02:36:50 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Shannara

December 17, 2006, 02:36:50 AM Last Edit: December 17, 2006, 02:38:31 AM by Sync
Ok, maybe I am spoiled ... ok, I am spoiled  ;D

In other languages, you can create a clickable image control. It can have border or be borderless. I am trying to create a borderless image control (or at least a borderless image button) in Aurora. I have figured out how to make an image button and how to make it flat. But how do I make it completely borderless? Am I going about this the wrong way?


Sorry about posting about another language indirectly, it was in violation of the forum policy/guidelines, I'll try not to do it again :(
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

Use a static control.  You can use it as a clickable image control by creating with the styles

ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100

0x100 = SS_NOTIFY which sends the parent window notification messages when the user clicks or double-clicks the control
Ionic Wind Support Team

Shannara

Now thats' awesome. I gotta dig into the help file much more then I have been :) Thanks again Paul!

In case your wondering, I am porting over a game engine of mine (Mirage Source) into many different languages. This is lots of fun a joy .. ergh!
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

And here is a short example using a dialog.  Steps were simple.

#1 create a dialog using the dialog editor.
#2 Add a static text control to the dialog.
#3 double click on the static control and check the "bitmap" box.
#4 Generate source and check the "Generate skeleton handler" and "Open in new window".
#5 edit the OnInitDialog method to set the image for the control and change the style of the control from 0x5000030E to 0x5000010E which is the same as the styles I gave you in hex.


#define STATIC_1 100
class dlg:CDialog
{
declare OnInitDialog(),int;
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
}

global sub main()
{
dlg d1;
d1.Create(0,0,300,202,0x80C80080,0,"Caption",0);
d1.AddControl(CTSTATIC,"Static",78,24,105,103,0x5000010E,0x0,STATIC_1);

d1.DoModal();
return 0;
}

dlg::OnClose(),int
{
CloseDialog(1);
return true;
}

dlg::OnInitDialog(),int
{
/* Initialize any controls here */
CenterWindow();
CBitmap bmp;
if(bmp.LoadFromFile(GetStartPath()+"picture.bmp"))
{
*(CStatic)GetControl(STATIC_1).SetImage(bmp.Detach());
}
return true;
}

dlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
case STATIC_1:
if(nNotifyCode = 0)
{
MessageBox(this,"Clicked!","Info");
}
}
return true;
}


You would need a bitmap named "picture.bmp" in the same directory as the created executable to try this example. 

Paul.
Ionic Wind Support Team

Shannara

Sorry about that, my statement was for other languages like Delphi :( Aurora reminds me much like C# (day job), so picking it up wasnt hard, just wading my way though here :) The following is what I ended up with :)


/***********************************/
/* Aurora 1.0 Beta 1 Rev 3 Port.   */
/* Released under the MSE License. */
/* Created by Shannara             */
/***********************************/

class frmMainMenu : CWindow
{
declare virtual OnClose(),int;
    declare virtual OnCreate(),int;
declare virtual OnPaint(), int;
declare virtual OnControl(int  nID, int  nNotifyCode, unsigned int  hControl), int;

CImage Logo;
CImage iNewAccount;
CStatic NewAccount;
CImage iDeleteAccount;
CStatic DeleteAccount;
CImage iLogin;
CStatic Login;
CImage iCredits;
CStatic Credits;
CImage iQuit;
CStatic Quit;
}


frmMainMenu :: OnCreate()
{
string Dir = "C:\\Projects\\MSE (Aurora)\\";

// Create our wonderful controls ....
Logo.LoadFromFile(Dir + "girl.bmp");

iNewAccount.LoadFromFile(Dir + "newaccount.bmp");
NewAccount.Create(216, 8, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 1, "", this);
NewAccount.SetImage(iNewAccount.Detach());

iDeleteAccount.LoadFromFile(Dir + "deleteaccount.bmp");
DeleteAccount.Create(216, 64, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 2, "", this);
DeleteAccount.SetImage(iDeleteAccount.Detach());

iLogin.LoadFromFile(Dir + "login.bmp");
Login.Create(216, 120, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 3, "", this);
Login.SetImage(iLogin.Detach());

iCredits.LoadFromFile(Dir + "credits.bmp");
Credits.Create(216, 176, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 4, "", this);
Credits.SetImage(iCredits.Detach());

iQuit.LoadFromFile(Dir + "quit1.bmp");
Quit.Create(216, 232, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 5, "", this);
Quit.SetImage(iQuit.Detach());


// Set window attributes
SetWindowColor(RGB(0, 0, 0));
CenterWindow();
return 0;
}

frmMainMenu :: OnClose()
{
Destroy();
return 0;
}

frmMainMenu :: OnPaint()
{
Logo.Render(this, 0, 0, 201, 309);
}

frmMainMenu :: OnControl(int nID, int nNotifyCode, unsigned int hControl)
{
if (nID == 5 && nNotifyCode == 0)
{
Destroy();
}
return true;
}

global sub main()
{
frmMainMenu win;
win.Create(0, 0, 546, 326, AWS_VISIBLE | AWS_SYSMENU, 0, "Mirage Source Engine", NULL);

do{ wait();} until win.m_hWnd = 0;
}



Seems to work out nicely :)
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

You can simplify it a bit.   Unless you need those CImage classes for something else just reuse a single one created on the stack.  The only one I could see you reusing was the logo


frmMainMenu :: OnCreate()
{
string Dir = "C:\\Projects\\MSE (Aurora)\\";

// Create our wonderful controls ....
CBitmap bmp;
Logo.LoadFromFile(Dir + "girl.bmp");

bmp.LoadFromFile(Dir + "newaccount.bmp");
NewAccount.Create(216, 8, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 1, "", this);
NewAccount.SetImage(bmp.Detach());

bmp.LoadFromFile(Dir + "deleteaccount.bmp");
DeleteAccount.Create(216, 64, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 2, "", this);
DeleteAccount.SetImage(bmp.Detach());

bmp.LoadFromFile(Dir + "login.bmp");
Login.Create(216, 120, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 3, "", this);
Login.SetImage(bmp.Detach());

bmp.LoadFromFile(Dir + "credits.bmp");
Credits.Create(216, 176, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 4, "", this);
Credits.SetImage(bmp.Detach());

bmp.LoadFromFile(Dir + "quit1.bmp");
Quit.Create(216, 232, 320, 55, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, 5, "", this);
Quit.SetImage(bmp.Detach());


// Set window attributes
SetWindowColor(RGB(0, 0, 0));
CenterWindow();
return 0;
}
Ionic Wind Support Team

Shannara

Oooo, I didnt think of that. It's about 1:22AM here and my mind isnt working as good as it could. I'm typing out a To Do list for the project to work on sometime this week. One one of the things was to create a control that inherits from CStatic ... something like the following:



class CImageEx : CStatic
{
delcare virtual OnCreate(int  l, int  t, int  w, int  h, int  nID, string  FileName, CWindow  *parent), int
CBitMap bmp;
}

CImageEx :: OnCreate(int  l, int  t, int  w, int  h, int  nID, string FileName, CWindow  *parent)
{
bmp.LoadFromFile(FileName);
this.Create(l, t, w, h, ASS_BITMAP | AWS_CHILD | AWS_VISIBLE | 0x100, nID, "", *parent);
this.SetImage(bmp.Detach());
}


I then got to looking a the docs some more ... Is it possible to inherit from an CImage and override (or whatever) the OnCreate() event somehow?
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

You have the right idea, just the wrong name.  OnCreate is already a method that is inherited from CWindow so you can't call it that.  Just name it unique like CreateEx.
Ionic Wind Support Team

Shannara

Ah, ok I think I have it. Just need to get home to jot down some code :) Basically I need to create a blank class, with a constructor that takes the needed co-ords. Then create a static control and a bitmap, in that class, with the appropriate values. Then, i need some sort of automated OnPaint() ... come to think of it, maybe I need to inherit from CControl so that paint event is ran automatically, eh?
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

No.  Just inherit from CStatic and add a method.
Ionic Wind Support Team

Shannara

Quote from: Paul Turley on December 18, 2006, 11:54:24 AM
No.  Just inherit from CStatic and add a method.

:) That is what I am trying not to do :) I am looking for away for it to act like any other static control, but when it is created, it has an extra parameter of FileName (for image to load). That way, once that is passed, I can create the bitmap, and the static control (with the bitmap flag), and pass the bitmap to it. :)
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team



class cbitmapstatic : CStatic
{
     declare CreateEx(int l, int t, int w, int h, int id, CWindow *parent,  string filename),int
}

cbitmapstatic::CreateEx(int l, int t, int w, int h, int id, CWindow *parent, string filename),int
{
      int iRet;
      CBitmap bmp;
      iRet = Create(l,t,w,h, 0x5000010E, id, "", parent);
      if(iRet)
      {
           if(bmp.LoadFromFile(filename))
           {
                SetImage(bmp.Detach());
           }
      }
      return iRet;
}


Ionic Wind Support Team

Shannara

December 18, 2006, 12:25:18 PM #12 Last Edit: December 18, 2006, 12:28:31 PM by Sync
Ergh, I wasnt thinking. I am so used to the C# implimentation on when you create a control, ie


CStatic cs = new CStatic(args)


So, fromt what I understand. I cannot override the Create() method?
Love is staying up all night with a sick child, or a healthy adult.

Ionic Wind Support Team

What I gave you above you just replace a CStatic variable with a cbitmapstatic one and call CreateEx.  You can use NEW if you want.

You can override the Create method, but you can't overload it.  Two different terms.

Paul.
Ionic Wind Support Team

Shannara

Ah yes, overloading was what I was thinking :) My bad, that was what I was looking for. heh. Thanks for the clearup, Paul. I'll be quiet for today now :)
Love is staying up all night with a sick child, or a healthy adult.

J B Wood (Zumwalt)

Keep up this conversation, I am learning tons.