Button Notifications In Delphi 7 - delphi

I have searched many forums and many web sites but i didn't find the required solution.I had a requirement to show the number of notifications to buttons .When the form Loads.If the notifications are hundred there should be 100 beside the button.if nothing then no notification should be visible.
Please suggest me the required solution..
Thanks In advance.
They are asking the similar functionality as in Icons of IOS4.

If you don't mind using a component for this instead of making your own, there is one that does what you need. It will display a status and looks just like what you have shown in your image link.
You can see this page here
It is not free though.

In iOS 4 there are icons with notifications (for programm-startup) and no buttons (I think), so this is not really the same,... but maybe you can create a custom button (inherit from TButton) and use something like an onPaint Event (sorry this is too much dotnet-style,... don't know how it is called in delphi) to draw this "notification" to the button like you do it in TCanvas.

I think you can use TBalloonHint component. For example, To show the notification,
procedure TForm1.FormCreate(Sender: TObject);
var
point : TPoint;
begin
point.X := sb1.Left;
point.Y := sb1.Top;
BalloonHint1.Delay := 100;
//BalloonHint1.Description := 'This is your Notification!';
BalloonHint1.HideAfter := -1;
BalloonHint1.Style := bhsBalloon;
BalloonHint1.Title := '2';
sb1.ParentShowHint := False;
BalloonHint1.ShowHint(point);
end;
To Hide the notification
procedure TForm1.sb1Click(Sender: TObject);
begin
BalloonHint1.HideHint;
end;
It would be see like the above image
If you want to show images, you can use the BalloonHint1.Images property.

You could use a TPaintBox and draw directly to its Canvas property. TCanvas has a number of methods that would make this a fairly simple task, in my opinion. Just store the background image separately (maybe in a TImage), copy it to the canvas (using the Draw method in the OnPaint event), and then paint the circle (Ellipse method) and the number last (TextOut or TextRect). You can also use the OnClick event of the TPaintBox to manage the "button clicking" operations.

Related

How can I bring a window to top and simulate a click on it?

I am running a Delphi application multiple times and I need to bring each one to top and simulate a mouse click somewhere on its form.
In my app I have a TWebBrowser component and I want to click somewhere in that browser. The thing is that I need to click on flash object inside that browser. I tried to get the ClassName and Handle to click on flash, but is not working with all websites. So the only thing that works is to simulate a mouse click.
For example I load this link into the browser http://bit.ly/XWaelU and I am trying to simulate click on the big "play" button from the flash player inside.
Can someone help me with an example code on how this can be done?
I think the application must be launched with fixed position so the coordinates of the click remain the same, right?
Thanks.
Assuming you want to click a control on the window, with known position relative to the window, from which you have (can get) the handle, you could use this. Demo only on the current form.
Maybe adapted to your conditions.
Procedure SetWindowTopAndClickOnRelPos(wnd:HWND;Pos:TPoint);
var
ChildControlHandle:HWND;
begin
SetForegroundWindow(wnd);
ChildControlHandle:= ChildWindowFromPoint(WND,pos);
SendMessage(ChildControlHandle,WM_LButtonDown,0,5*$FFFF + 5);
SendMessage(ChildControlHandle,WM_LButtonUp,0,5*$FFFF + 5);
Form4.Memo1.Lines.Add(Format('ChildControlHandle: %d',[ChildControlHandle]));
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(Format('Window: %d',[Handle]));
Memo1.Lines.Add(Format('Button: %d',[button2.Handle]));
SetWindowTopAndClickOnRelPos(handle,Point(Button2.Left + 2,Button2.Top + 2));
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
Showmessage('Hallo');
end;

PageControl disabled text on tabs - gray text

I am looking (I think) for the Windows API that I can use in my OnDrawTab event in the TPageControl component to display gray text on tabs that I choose. I have done it in the past and from memory this is where I did (in the OnDrawTab event). Unfortunately I don't have access to the code to look back how I did it before.
I'm sure that I used something like DrawText or TextOut or something but I was able to add a flag or format style to it which gave it the appearance of grayed out. For the life of me I cannot find the command I used. ODS_DISABLED flag seems to be something like what I'm after but it is a windows message handler so I'm sure I didn't use that before. I'm not writing a component here, just handling the OnDrawTab event.
Anyone point me in the right direction?
I'm using Delphi 6.
Thanks
Jason
You can use the DrawState and GrayString functions.
procedure TForm1.FormClick(Sender: TObject);
var
s: string;
begin
s := 'testar';
DrawState(Canvas.Handle,
0,
nil,
integer(#s[1]),
length(s),
10,
10,
0,
0,
DST_TEXT or DSS_DISABLED)
end;

Windows 7 style Notifications Flyouts in Delphi

Regarding Notification Area recommendations by Microsoft, I'm looking for ideas or a Delphi component to implement Notification Area Flyouts.
The first "natural" idea is to use a standard Delphi form, but I'm facing two issues with it:
I can't get the form border behavior using the standard "BorderStyle" property. Tried to "mimic" the border using the GlassFrame property along with BorderStyle set to bsNone, but there's no GlassFrame when there's no border (at least, in Delphi 2007).
I can't figure out how to make the form close when the user clicks everywhere out of the form itself. Yesterday I was trying with different messages, but no one works as expected.
I will thank any clue or component to make it happen :)
Best regards.
jachguate.
ps. There's a related question in converting notification area icon to Program icon in Win7 (Delphi).
update[0]
I'm still looking for advise. #skamradt answer looks very good, but unfortunately doesn't work well in practice.
update[1]
Finally, The auto-close behavior is working with the WM_ACTIVATE message after a calling SetForegroundWindog to force flyout "activation"
begin
FlyoutForm.Show;
SetForegroundWindow(FlyoutForm.Handle);
end;
Now, I'm looking for advise to reach the border behavior and visual style, because the closest behavior is achieved with style as WS_POPUP or WS_DLGFRAME, while the closest visual goal is achieved setting style as WS_POPUP or WS_THICKFRAME.
I believe what your after is the following:
TForm1 = class(TForm)
:
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure WMActivate(Var msg:tMessage); message WM_ACTIVATE;
end;
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := WS_POPUP or WS_THICKFRAME;
end;
procedure TForm4.WMActivate(var msg: tMessage);
begin
if Msg.WParam = WA_INACTIVE then
Hide; // or close
end;
This will give you a sizeable popup window with a glass frame. You can't move the window without additional programming, since the standard windows caption is missing. When another window gets focus, the FormDeactivate event gets fired...but only if you switch to another form in the same application. To handle it regardless of the application switched, use the message capture method.

How to programmatically disable window animation under Vista Aero?

My application does automated screenshots of several dynamically created forms. This works perfectly under Windows XP, but doesn't work well under Vista Aero. Most of the forms appear semitransparent in the screenshots. The problem lies in the window animation of Aero.
How can I check/disable/enable this animation from inside a Delphi (2007+) program?
Or as an alternative: How can I make sure the form is displayed properly before making the screenshot?
The link in the comment from Shoban led me in the right direction. A quick check showed a wrapper for the DwmApi in the VCL and from that it went straight forward. Here is the code I successfully use now:
uses DwmApi;
...
SaveDwmCompositionEnabled := DwmCompositionEnabled;
if SaveDwmCompositionEnabled then
DwmEnableComposition(DWM_EC_DISABLECOMPOSITION);
...
if SaveDwmCompositionEnabled then
DwmEnableComposition(DWM_EC_ENABLECOMPOSITION);
Disabling Aero would be a pity - in general it's not a good idea to change the user's choice of UI style.
You may be able to draw the form another way. One thing that comes to mind is using the PaintTo method to paint it to a canvas. (In fact, if you're taking screenshots of the forms as a way of getting what it looks like you probably don't need to show the forms at all - created them with Visible set to false and paint them to a bitmap. Only show them if the user needs to interact with them.)
I was trying to solve the same problem and found this question, but came up with a completely different solution. It doesn't disable the animation, but it allows you to make the window disappear without animation effect.
var oldWidth := Self.Width;
var oldHeight := Self.Height;
try
if Visible and (Self.WindowState <> wsMinimized) then
begin
Self.BorderStyle := bsNone; // do this first
Self.Width := 0;
Self.Height := 0;
end;
//.. Do your screen capture here
finally
if Visible and (Self.WindowState <> wsMinimized) then
begin
Self.BorderStyle := bsSizeable; // or whatever it was
Width := oldWidth;
Height := oldHeight;
end;
end;
You could also move the window to -maxint for X & Y, but I like this better.
You can add a manifest resource to the exe file, to notify Vista you want that the application runs without Aero
http://www.google.be/search?q=vista+manifest+resource+delphi

Delphi Pop Up menu visibility

Is there a way in Delphi 7 to find out if a pop-up menu is visible (shown on the screen) or not, since it lacks a Visible property.
You could make your own flag by setting it in the OnPopup event. The problem is knowing when the popupmenu is closed. Peter Below has a solution for that.
But my I ask why you would want this? Maybe there is a better way to solve the underlying problem.
This seems to be a bit simpler (I used Delphi 2007):
In your WM_CONTEXTMENU message handler, before calling the inherited handler, the popup menu is about to be shown, you can set your flag. After calling inherited, the popup menu has been closed, reset your flag.
procedure TForm1.WMContextMenu(var Message: TWMContextMenu);
begin
FPopupActive := True;
try
OutputDebugString(PChar(Format('popup opening', [])));
inherited;
finally
FPopupActive := False;
OutputDebugString(PChar(Format('popup closed', [])));
end;
end;

Resources