May 22, 2024, 08:17:28 AM

News:

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


Desktop Clock

Started by GWS, December 20, 2005, 01:39:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

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
Tomorrow may be too late ..

Ionic Wind Support Team

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.
Ionic Wind Support Team

GWS

Wow! .. that's great Paul.ÂÃ,  I'll study how you did it ..ÂÃ,  :)

Graham
Tomorrow may be too late ..

Bruce Peaslee

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Parker

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.

Zen

Very good graham. I think that is actually the first real GUI app weve got, apart from the examples of course.

Lewis

Parker

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 ;)

GWS

Whee .. I wasn't far away .. thanks to Peaslee's pathfinding .. :)

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

Graham
Tomorrow may be too late ..

GWS

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
Tomorrow may be too late ..

Zen

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

Ionic Wind Support Team

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.
Ionic Wind Support Team

GWS

Thanks folks ..  :)

Graham
Tomorrow may be too late ..