Link to home
Start Free TrialLog in
Avatar of jabubo
jabubo

asked on

Creating an AppBar for a ticker

Hello,

i try to create a simple newsticker and for this it would be glad, when the windows is on top of my desktop or bottom, wherever i want.

i've found in the MSDN the Appbar Messages and Functions, but there is much trouble with it for me :/

BarData     : TAppBarData;

with BarData do begin
         cbSize := SizeOf(BarData);
         hwnd := Ticker.Handle;
         uCallBackMessage := WM_USER;
         uEdge := ABE_TOP;
         rc := Rect( 0 , 0 , screen.width , 30 );
         lParam := 0;
end;

This is how my AppBar Structure looks like.
The Problem with this code is, when i run the Form, the window is just half the screen wide and behind some other appbars.

SHAppBarMessage(ABM_QUERYPOS, BarData); <-- this returns evertime true, MSDN says, so i dont know how to check if there is any appbar in this location of my desktop.

Can someone help find the right positon and size for my ticker ?
Is there something to remember when i reposition the ticker from top to bottom ?

Thanks for help anyway
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

hello jabubo, you need to use the ShAppBarMessage(ABM_QUERYPOS, BarData1); to get the information about the other "APPBAR" that may already be on that Side of the screen, here is some code that may help you, I did this to display a Menu Bar, to do many things, by the user just clicking a ton og menu Items. I did not include all of the variables.

procedure TForm1.FormCreate(Sender: TObject);
var
MenuRect: Trect;

begin
GetMenuItemRect(Handle,MainMenu1.Handle,0, MenuRect);
Height := MenuRect.Bottom - MenuRect.Top;

BarData1.cbSize := SizeOf (TAppBarData);
BarData1.uEdge := ABE_TOP;
BarData1.lParam := 0;
BarData1.uCallbackMessage := WM_MyUser;
BarData1.rc.Left := 0;
BarData1.rc.Top := 0;
BarData1.rc.Right := GetSystemMetrics(SM_CXSCREEN);
BarData1.rc.Bottom := Height;
BarData1.hWnd := Handle;

ShAppBarMessage(ABM_NEW, BarData1);
ShAppBarMessage(ABM_QUERYPOS, BarData1);
BarData1.rc.Bottom := BarData1.rc.Top+Height;

ShAppBarMessage(ABM_SETPOS, BarData1);
SetBounds(BarData1.rc.Left, 0, BarData1.rc.Right-BarData1.rc.Left, BarData1.rc.Bottom - BarData1.rc.Top);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ShAppBarMessage(ABM_REMOVE, BarData1);
end;

- - - - - - - - - - - - - - - - - - - - - -  --

ask questions if you need more info
Avatar of jabubo
jabubo

ASKER

Hello Slick812,

The window appears now in the reserved area and the appbar is registered. But i have not found any way to set the top and left position to the right value, so that other appbars ( MS-Office Bar, Newsticker, Taskbar .... ) are not at the same coordiantes. Now my Appbar is over an other appbar.

When you could help me with this, points are yours ;)

thanks for help so far.
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would like to suggest that you set the form align to
top or bottom

i hope this will solve your problem...

:D
Avatar of jabubo

ASKER

Hi,

Sorry for the delay!

this helps a little bit, but when i write:
BarData1.rc.Left := 0;
BarData1.rc.Top := 0;
the bar only will be on top of desktop, but there could be another bar. So i need a top and left value, that sets the size of the rest of the desktop. With maximizing the window, geht top and left value, and resize to normal and so on, id wouldn't work :/

hope that you know what i mean and that you can help me.
Sorry for my excellent english ;)

Thanks for help
??????
what are you talking about?
the code

BarData1.rc.Left := 0;
BarData1.rc.Top := 0;

does Nothing, later you call

ShAppBarMessage(ABM_QUERYPOS, BarData1);

which accually sets the BarData1.rc to the "NEW" position under any other AppBar on the top
or it changes the rc.Left, if there is an AppBar on the left, then

{I set the rc. bottom here, but if it is the ABE_BOTTOM then
you would set the rc.Top, and rc.Left for ABE_RIGHT
and rc.Right for ABE_Left}
BarData1.rc.Bottom := BarData1.rc.Top+Height;

you need to set the height of the rc rect

and then

ShAppBarMessage(ABM_SETPOS, BarData1);

will further adjust the rc Rect, and set your AppBar position, I tried this with other AppBars and it repositioned
to Under others on top or Over others on the bottom, it works for me in Win98 and WinXP
Avatar of jabubo

ASKER

hmm, there must be some errors in my code, with your code from above it works.
Thanks for your help!!!