Anyway to lock orientation to per se Portrait for only a specific form and not the whole application?
Using Delphi xe6, for iOS. Can't seem to find anything by googling. Thank you!
Update:
My underlying issue is that I'm using a zbar unit for scanning and when the screen rotates, the display from the camera view does not. So the app goes to landscape, but the view from the scanner is still portrait, thus making the view look sideways. From what I've googled and tooled around on my own, it appears that locking the orientation maybe easier so here is where I am.
I've found this article: http://www.delphifeeds.com/go/s/84941, but to no avail, the one form I don't want to rotate, still rotates.
I've implemented this code for the time being, although I'm not very found of it. Was just a quick, fix work-around.. I put everything ontop of a layout and on the form's resize event:
with LayoutOrientation do
begin
if Clientwidth > ClientHeight then
begin
Align := TAlignLayout.None;
width := ClientHeight;
height := Clientwidth;
RotationAngle := 90;
RotationCenter.X := 0.948;
end else begin
RotationAngle := 0;
RotationCenter.X := 0.5;
Align := TAlignLayout.Client;
end;
end;
Meh, I don't like this because the app still repaints when it doesn't need to and also the status bar showing at the top still, gives it a funky look. This for the time being works - but really looks like I hacked it, which in this case I did..
Update Application.FormFactor.Orientations before and after showing your form.
Application.FormFactor.Orientations := [TFormOrientation.Portrait];
ScannerForm.ShowModal;
Application.FormFactor.Orientations := [TFormOrientation.Portrait, TFormOrientation.Landscape, TFormOrientation.InvertedLandscape];
It actually depends how do you generally controll your application orientation.
If you use Layouts to control orientation you could force the use of same layour for every oriantation.
If you are creating different forms for different orientation you can force your application to use same for for every orientation.
Related
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.
I'm using Peter Below's PBThreadedSplashForm to display during application startup. It gets updated as various databases are opened during the creation of the data module (just before the main form is created).
The problem is that we have a check for the existence of certain things that is done during the creation of the data module. If any of those items are missing, a modal dialog is shown so that either the item can be created or the application closed. (The missing items are typically indexes, and the dialog is primarily used when we reindex databases, so it's aimed at the developers and not normal users.) However, the modal dialog is displayed behind the splash screen; it appears to be the focused window, as the caption changes, but it displays behind the splash screen.
The splash screen is created using the Windows API CreateWindowEx() from a different thread than the main process, using the following code:
procedure TPBSplashThread.CreateSplashWindow;
const
TopmostStyle: Array [Boolean] of DWORD = (0, WS_EX_TOPMOST );
NoActivateStyle : Array [Boolean] of DWORD = (0, WS_EX_NOACTIVATE );
var
wsize: TSize;
begin
wsize.cx := FSurface.Width + GetSystemMetrics( SM_CXEDGE ) * 2;
wsize.cy := FSurface.Height + GetSystemMetrics( SM_CYEDGE ) * 2;
FWnd := CreateWindowEx(
TopmostStyle[ FTopmost ] or WS_EX_TOOLWINDOW
or WS_EX_STATICEDGE or WS_EX_CLIENTEDGE
or NoActivateStyle[ Win32MajorVersion >= 5 ],
MakeIntResource( FWndClass ),
nil,
WS_POPUP or WS_BORDER,
Forigin.x, Forigin.y,
wsize.cx, wsize.cy,
0, 0, hInstance, self );
If FWnd = 0 Then
raise exception.create('TPBSplashThread.CreateSplashWindow: CreateWindowEx failed');
end;
FTopmost is a property (with the obvious meaning) that is never set, so it's False due to the default initialization during class construction. (I've also tried explicitly setting it to False, just in case, with no effect.) I've also tried using SetForegroundWindow() and SetWindowPos() during the OnShow event of the modal dialog with no effect.
Does anyone have any idea what might be causing this?
Ok. Finally got the problem solved. It appears to be caused by the WS_EX_NOACTIVATE flag in the call to CreateWindowEx(). Changing it to remove that seems to solve the problem; the modal dialog displays above the splash screen, and because it's modal the splash screen can't be brought above it.
The working code is:
FWnd := CreateWindowEx(
TopmostStyle[ FTopmost ] or WS_EX_TOOLWINDOW
or WS_EX_STATICEDGE or WS_EX_CLIENTEDGE,
MakeIntResource( FWndClass ),
nil,
WS_POPUP or WS_BORDER,
Forigin.x, Forigin.y,
wsize.cx, wsize.cy,
0, 0, hInstance, self );
Thanks, Rob and Craig, for the efforts.
If you're looking for an explanation, I can't help you.
If you're looking for a solution, you're not the first. Eddie Shipman encountered this same problem in May. His proposed solution was to make the other dialog (the one hidden by the splash screen) be a topmost window, but he ultimately avoided the issue by hiding the splash screen before the application needed to display any other windows.
Another suggestion was to post commands to the splash screen and have it display the message box. The dialog could be parented to the splash screen. It's tricky, though, because you're not afforded any of the luxuries of the VCL anymore since it doesn't work outside the main thread.
You should be able to fix this by parenting the dialog to the splash screen. Assign the splash screen's HWND to a global variable, and override the dialog's CreateParams method. If the global HWND has a value assign it to the Params.WndParent variable that CreateParams passes in. The fact that they're from different threads shouldn't matter, since it's just dealing with the HWND, not a VCL object, and Windows will handle the synchronization.
var ScreenSaver:String;
var handle:HWND;
begin
Handle := FindWindow('Progman', 'Program Manager');
Handle := FindWindowEx(Handle, 0, 'SHELLDLL_DefView', 0);
Handle := FindWindowEx(Handle, 0,'SysListView32', 'FolderView');
ScreenSaver := 'C:\windows\system32\Mystify.scr /P' + InttoStr( Handle );
WinExec(pAnsichar(screensaver), SW_SHOWNormal);
This code will erase the desktop icons.
How to get the window handle behind the desktop icons?
This isn't really a Delphi question, but anyway... Starting a screen saver with the /P command line switch creates the screen saver window as a child of the given window, with the same size and position - it is meant only to provide a screen saver preview in the Display Properties dialog box. It will not position the screen saver window somewhere in the Z-order beneath some other window. Consequently it will draw over everything, erasing the desktop icons as well.
Unless you create your own screen saver that draws directly on the desktop window I don't think what you want can be done.
As mghie indicates, if you're wanting to start a screensaver, that's not the correct way to do it. Easiest way is:
SendMessage(Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
In my experience, I again agree with mghie; I don't think you can do what you're wanting to do. Windows seems to operate in a different environment when a screensaver is active, e.g. Windows messages don't seem to propagate as expected, etc.
Although, to get at the desktop, I've previously used a handle to the Device Context of the desktop.
var
ScreenDC: HDC;
begin
ScreenDC := GetWindowDC(0);
...
// You can then use the Device Context with Windows API methods such as BitBlt
// and StretchBlt to go graphical work on the desktop.}
...
ReleaseDC(0, ScreenDC);
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
I've got an app that runs a long set of operations, and I'm trying to use a TProgressBar to keep track of what's going on. I set a number of steps, and call .StepIt to increment the progress bar.
Problem is, it doesn't keep up very well. Instead of jumping directly to the correct position, it seems to like to slide gradually up to it. That's all well and good if it's eye candy you're after, but when I'm trying to get an accurate representation of my routine's progress, this makes it appear to be constantly lagging behind the true status. How can I turn that "feature" off?
I only notice this happening under Windows Vista. Not sure if it's also going on on XP or not, because when I test it on XP, the process goes a lot faster and it's over too quickly. :P But this may or may not be Vista-specific. Either way, it's driving me nuts. Does anyone know how to fix it?
I have a quick but partial and inelegant solution, if you don't mind having the progressbar yellow instead of green:
ProgressBar1.SmoothReverse := True;
ProgressBar1.State := pbsPaused; // for yellow or pbsError for red
Or if you don't mind loosing the vista/theme look and go back to a flat blue one:
UxTheme.SetWindowTheme(ProgressBar1.Handle, ' ', ' ');
The real "problem" according to Microsoft is that you try to "pervert" a ProgressBar into a Meter which they claim it is not.
You could also try to draw it yourself ;-)
Same problem on Windows7 !!
But the answer was already in one of the older posts:
If tou make the progressbar step backwards there will NO delay !!!
So I implemented this..... (and get instant updates)
if(progress < ProgressBar.Max)
then
begin
ProgressBar.Position := progress+1;
ProgressBar.Position := progress; //This will set Progress backwards and give an instant update....
end
else
begin //cannot set position beyond max...
ProgressBar.Max := progress + 1;
ProgressBar.Position := progress + 1;
ProgressBar.Max := progress; //This will also set Progress backwards also so instant update........
end;
I ran into exactly the same problem a while ago. After searching Google for a long time, I found that it is a Vista-specific problem. It seems to boil down to this: Microsoft added fancy animations to the progress bar control in Vista (i.e., the moving 'highlight'). To make updates more smooth, they implemented some sort of 'lagging' in the repaint of the control --- and this basically screws the whole progress bar control. Rather annoying, I'd say, especially since there doesn't seem to be a decent solution.
See for more details the replies by Arvid Winkelsdorf to this Embarcadero Discussion Forum post:
It's the same for VB, C++ and C#
somehow as the problem lies in the
Vista drawing of the new animated
ProgressBars. To provide a smoother
visual feedback drawing is delayed
when moving forward. Your application
cannot be sure that 100% will be
reached at any given time.
By setting the position back to a
smaller value, the ProgressBar drawing
is forced to jump back. No delay in
getting to a position smaller than the
current. So you'll have nearly 100%
immediately. Afterwards set to the
maximum and you'll have exactly 100%.
[...]
There is a similar glitch when using
the new Vista ProgressBar Styles like
PB Paused or PB Error. If the bar is
still moving (MS part) and your app
sets the color to paused by
SendMessage (like in D2009) the
message will be ignored by the
ProgressBar.
Maybe you can try to set the position of the ProgressBar directly instead of using the StepIt procedure. I'm on XP with Delphi 7 here, so I can't test it, but looking at the code of TProgressBar it uses a different message (PBM_SETPOS instead of PBM_STEPIT). So maybe it sets the position of the progressbar without an animation.
Additionally there are several 3rd party components which provide better Progress bar implementations that still render nice on Vista. Personally, I prefer the one from Raize components which works quite well. It doesn't "lag" like the windows control does and works independent of any theming.
If you don't really want anything fancy, then you can always build one yourself using a panel and a tshape aligned left inside the panel. Resize the tshape to be a % of the panel it sets on.
I had the same problem, my solution was to switch to another control available in the VCL :
I choose to use the Range of TTrackBar to display the progression.
(with slider off and control resized to hide the range marks).
Not the same visual (particulary if themed), but it fit well my need (no lag).
Here is a simple solution:
ProgressBar.max := ProgressBar.max +1;
ProgressBar.StepBy(2);
ProgressBar.StepBy(-1);
ProgressBar.max := ProgressBar.max -1;