IonicWind Software

Aurora Compiler => GUI => Topic started by: GWS on December 20, 2005, 01:39:53 PM

Title: Desktop Clock
Post by: GWS on December 20, 2005, 01:39:53 PM
Hi guys,

I've actually got a little application to work - sort of .. :)

I won't class it as a true Aurora application, 'cos it relies too heavily on API calls.

Here's my little desktop clock, which I find very useful ..


// Desktop Clock - December 2005

#AutoDefine "Off"

class awindow : window
{
//override functions ..
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare OnCreate(),int;
declare OnTimer(int nIDEvent),int;

// Variables
def run as int;
def Button1 as int;

}

awindow::OnClose(),int
{
StopTimer();
run = 0;
Destroy();
return TRUE;
}

awindow::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select(nID) //same as @CONTROLID
{
case 1:
if nNotifyCode = 0 // exit button clicked
run = 0;
default:
}
return true;
}

awindow::OnCreate(),int
{
run = 1;
return TRUE;
}

awindow::OnTimer(int nIDEvent),int
{
writetext (10,2,left$(time$(),5));
return TRUE;
}

awindow::OnLButtonDown(int x,int y, int flags),int
{
// SendmessageA(hInst,WM_NCLBUTTONDOWN,HTCAPTION,0);
}

// Window style constants
const WS_CHILDÂÃ,  ÂÃ, = 0x40000000;
const WS_VISIBLE = 0x10000000;
const WM_NCLBUTTONDOWN = 0xA1;
const HTCAPTION = 2;

declare import, GetModuleHandleA(int num),unsigned int;
declare import, GetSystemMetrics(int nIndex),unsigned int;
declare import, SendMessageA(int hwnd,int msg,int wparam,int lparam ),unsigned int;

declare import, CreateWindowExA(
dwExStyle as unsigned int,
lpClassNameÂÃ,  as string,
lpWindowName as string,
int dwStyle,
int x,
int y,
int nWidth,
int nHeight,
int hWndParent,
hMenu as unsigned int,
hInstance as unsigned int,
lpParam as pointer
),int;

global sub main()
{

def w as awindow;
def hinst as unsigned int;

int style,screenwidth;

screenwidth = GetSystemMetrics(0);

style = AWS_VISIBLE|AWS_AUTODRAW|AWS_POPUP;
w.Create((screenwidth - 60)/2,0,60,18,style,AWS_EX_TOPMOST,"",NULL);

w.SetWindowColor(0x555555);

hInst = GetModuleHandleA(null);

w.Button1 = CreateWindowExA
(0,"Button", "",
WS_VISIBLE | WS_CHILD,
50,0,
10,18,
w.m_hwnd,
1, // control number
hInst,
NULL);

w.StartTimer(10);
w.SetFont("Times New Roman",8,400);
w.BackPen(0x555555);
w.FrontPen(0xffff00);

do
{
wait();
}until w.run = 0;

return;

}



It runs OK, but I need to make the clock draggable when clicked on.
I got it working in IBasic by sending a message to the window. (I don't know why it works, but it does .. :))


ÂÃ,  ÂÃ,  ÂÃ,  Case @IDLButtonDN
' Move the Window by dragging itÂÃ,  ..
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, SendMessage w.hwnd, WM_NCLBUTTONDOWN,HTCAPTION,0


If anyone can fix that it would be great.ÂÃ,  I've tried, but couldn't find the right instruction to do the job.

best wishes, :)

Graham
Title: Re: Desktop Clock
Post by: Ionic Wind Support Team on December 20, 2005, 01:49:17 PM
Here is your fix ;)


// Desktop Clock - December 2005

#AutoDefine "Off"
// Window style constants
const WS_CHILD   = 0x40000000;
const WS_VISIBLE = 0x10000000;
const WM_NCLBUTTONDOWN = 0xA1;
const HTCAPTION = 2;

declare import, GetModuleHandleA(int num),unsigned int;
declare import, GetSystemMetrics(int nIndex),unsigned int;
declare import, SendMessageA(int hwnd,int msg,int wparam,int lparam ),unsigned int;

declare import, CreateWindowExA(
dwExStyle as unsigned int,
lpClassName  as string,
lpWindowName as string,
int dwStyle,
int x,
int y,
int nWidth,
int nHeight,
int hWndParent,
hMenu as unsigned int,
hInstance as unsigned int,
lpParam as pointer
),int;

class awindow : window
{
//override functions ..
declare OnClose(),int;
declare OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare OnCreate(),int;
declare OnTimer(int nIDEvent),int;
declare OnLButtonDown(int x,int y, int flags),int;

// Variables
def run as int;
def Button1 as int;

}

awindow::OnClose(),int
{
StopTimer();
run = 0;
Destroy();
return TRUE;
}

awindow::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select(nID) //same as @CONTROLID
{
case 1:
if nNotifyCode = 0 // exit button clicked
run = 0;
default:
}
return true;
}

awindow::OnCreate(),int
{
run = 1;
return TRUE;
}

awindow::OnTimer(int nIDEvent),int
{
writetext (10,2,left$(time$(),5));
return TRUE;
}

awindow::OnLButtonDown(int x,int y, int flags),int
{
SendmessageA(m_hWnd,WM_NCLBUTTONDOWN,HTCAPTION,0);
return true;
}


global sub main()
{

def w as awindow;
def hinst as unsigned int;

int style,screenwidth;

screenwidth = GetSystemMetrics(0);

style = AWS_VISIBLE|AWS_AUTODRAW|AWS_POPUP;
w.Create((screenwidth - 60)/2,0,60,18,style,AWS_EX_TOPMOST,"",NULL);

w.SetWindowColor(0x555555);

hInst = GetModuleHandleA(null);

w.Button1 = CreateWindowExA
(0,"Button", "",
WS_VISIBLE | WS_CHILD,
50,0,
10,18,
w.m_hwnd,
1, // control number
hInst,
NULL);

w.StartTimer(10);
w.SetFont("Times New Roman",8,400);
w.BackPen(0x555555);
w.FrontPen(0xffff00);

do
{
wait();
}until w.run = 0;

return;

}


When your code is located within a method of the window class the handle (HWND) of that window is m_hwnd

Paul.
Title: Re: Desktop Clock
Post by: GWS on December 20, 2005, 02:12:19 PM
Wow! .. that's great Paul.ÂÃ,  I'll study how you did it ..ÂÃ,  :)

Graham
Title: Re: Desktop Clock
Post by: Bruce Peaslee on December 20, 2005, 02:19:05 PM
Not bad, not bad at all.
Title: Re: Desktop Clock
Post by: Parker on December 20, 2005, 02:46:33 PM
The reason sending that message works is because that's the message that the default procedure in windows handles when the title bar is clicked on. So you're tricking it into thinking that the title bar was clicked, and it drags.
Title: Re: Desktop Clock
Post by: Zen on December 20, 2005, 02:51:13 PM
Very good graham. I think that is actually the first real GUI app weve got, apart from the examples of course.

Lewis
Title: Re: Desktop Clock
Post by: Parker on December 20, 2005, 05:23:05 PM
You can't say it's not a true Aurora program just because it uses API. If that was true, then there would be almost no C programs, only MFC programs or wxWidgets programs. Yours is just as much an Aurora program as the hello world that just uses writeln().

Edit: Besides, I'm writing a program with straight API to learn it, and I still want to be able to say it's written in the language I'm using ;)
Title: Re: Desktop Clock
Post by: GWS on December 21, 2005, 01:59:23 AM
Whee .. I wasn't far away .. thanks to Peaslee's pathfinding .. :)

Have you noticed how small the .exe's are .. 8)

Graham
Title: Re: Desktop Clock
Post by: GWS on January 04, 2006, 02:08:05 AM
Just noticed that when the .exe is run, a blank box appears in the task bar.

This doesn't happen with the IBPro version ..

all the best, :)

Graham
Title: Re: Desktop Clock
Post by: Zen on January 04, 2006, 09:14:30 AM
I think that might be because in the ibasic version it has a toolbar caption and they dont display in the task bar. Try changing it to the equivelant of @TOOLWINDOW.

Just a suggestion, dont take my word for it.

Lewis
Title: Re: Desktop Clock
Post by: Ionic Wind Support Team on January 04, 2006, 09:22:36 AM
WS_EX_TOOLWINDOW = 0x80


style = AWS_VISIBLE|AWS_AUTODRAW|AWS_POPUP;
w.Create((screenwidth - 60)/2,0,60,18,style,AWS_EX_TOPMOST | 0x80,"",NULL);


I will have the constant AWS_EX_TOOLWINDOW in the next update.  But you can just OR in 0x80 as above.

Paul.
Title: Re: Desktop Clock
Post by: GWS on January 04, 2006, 10:27:43 AM
Thanks folks ..  :)

Graham