How to write a "child" application in Delphi like Office does? - delphi

Office 2016 behaves like an MDI application, although it isn't: if you open many files in Taskmgr.exe there is one EXCEL.EXE process running (tab "Details"):
But there are multiple entries in the tab "Processes" (which actually lists windows):
When I open the first file Excel starts slow. But when I open the second and third file Excel is faster than first.
How to do this in a Delphi program?

Windows' Task Manager unneedingly uses misleading terms to what actually happens:
The tab "Processes" actually lists windows for its category "Apps" and either succeeds in listing multiple windows for one process or doesn't. In older versions of Windows the Task Manager listed the windows this way, already having the suspicious tab title "Applications", but without grouping and associating multiple windows to one process:
The tab "Details" lists the actual processes that run, unbound to how many windows they have or display. In previous versions this tab was titled "Processes":
Which situation do we have? One process displaying multiple windows. This can be accomplished easily just like ages ago: you just ensure only running one instance which handles multiple documents. Does not even need to be a true MDI for that.
What you want on top is, that the Task Manager also groups multiple windows. How does Excel achieve this? Look at your taskbar: for each document a separate button exists, not only one in general for Excel itself. In your Delphi program you must ensure that each window must also appear on the taskbar: How to correctly have modeless form appear in taskbar along with its answer has evaluated many ways of doing so.

In Delphi you program one single application. It will have several secondary windows. The main window and the secondary windows shall have an MDI style.
When the application is started, it first looks if a copy of itself is already running. If not, it simply continues; if a previous copy is running, it sends to it the document (filename) that should be opened and then quits. The previously running application will open the passed document in a new secondary window.
This is the overall way of doing it. If there is something you don't know how to do then please open separate questions for each topic.
Please read the help pages, take the SO tour, read How to Ask, as well as this question checklist.

Related

Updates for controls in Win3.1 palette

Some people are saying that I must update the controls in Win3.1 palette (especially TFilterComboBox) with modern ones. But does Delphi provide such new controls?
I need to create a GUI (somehow similar to Windows Explorer, consisting in a DirectoryListBox, FileListBox and a FilterComboBox) where I allow the user to easily explore for files of a specific type. Since the interface is centered around this Explorer, a TOpenDialog will be like hitting the customer with a hammer in the middle of his head. I need an 'easy to use' solution.
Unfortunately Shell Controls are not stable enough to be used as replacement.
The Shell Controls that come as a demo with Delphi only have to be installed, and you'll have some nice shell controls. There is, IMO, no big need to get 3rd party components for that.
Look for ShellCtls (or similar, can't check right now) in your demos folder. That Demos folder can be accessed from the Windows Start menu for your version of Delphi.
Update
They are not in a Demos folder, it is called Samples now. They can be found in Samples\Delphi\VCL\ShellControls. Install vclshlctrls.dproj first and then dclshlctrls.dproj.
In our application we use tpShellShock which works rather well. You may need to tweak it a little for Unicode Delphi, but if I recall correctly that was pretty simple to do.
Here's what it looks like:

A kinder way than TerminateProcess?

I have a backup app that will close user-defined running programs before the backup so that open data files can be closed and flushed before the backup. After the backup is complete it restarts the programs in the list.
I have no problem getting the window Handle using the Caption and PostMessage(AppHandle,WM_CLOSE,0,0); That works fine for most apps, but not for ones running in the Notification Area (System Tray)
Currently I am using TerminateProcess( and it works for those Notification Area apps, but it leaves files open as Windows bypasses any Close instructions and just slams those apps down.
I have searched long and hard and I cannot find a nicer way to shut down Notification Area apps. Can anyone please help?
Thanks
In order to close a program gracefully, you need to know something about how that program expects to be closed. If closing the main window accomplishes it, then you need to know how to recognize the "main" window.
Programs don't run "in" the notification area. They display icons there. Any program with a notification icon must also have a window (because the shell tells the program that the icon has been clicked by sending messages to the window). Even if the window isn't visible, it still must exist. If you can determine some set of properties that identify the window associated with a particular notification icon, then you could close it. There is no standard set of attributes to look for, though; each program can do it differently.
And even if you find the window you're looking for, closing it might not be the way the program expects to be terminated, either. It might expect a certain command from the notification icon's menu instead, or some message sent by a dialog box that the program displays.
If your application is running on Windows Vista or Windows 7, don't shut down programs - instead use the Volume Shadow Copy service to access a snapshot of the files while they are still in use. This is what the Windows 7 built-in backup program does.
If you're on an earlier version of Windows, there's no foolproof solution. If the program has a systray icon, it will have a hidden window as well, and you can try sending WM_QUERYENDSESSION and WM_ENDSESSION to it. However, there is no guarentee that the program will shut down, and if it does shut down, since you may be bypassing parts of its normal shutdown process, it may not complete its normal cleanup. There may also be programs running with no associated windows at all. The best approach would probably be to simply log off the user, and perform the backup from a service process. Of course, you'll still have sharing issues with files opened by other services...

How do I add recent items to my program's jump list on the Windows 7 taskbar?

I'm using Delphi XE and would like to add "recent items" in the Windows 7 taskbar jump list for my application, like when right-clicking on Microsoft Word brings up recently opened documents.
I've found information on how to set the progress but nothing on jump-list items. Any help would be greatly appreciated.
This will happen automatically if, for instance, you only use the standard Windows file dialogs. At least my text editor, Rejbrand Text Editor, has got such a MRU list by Windows. It lists all files I have recently edited using Rejbrand Text Editor, even though I have not written any code at all for it.
I think that Windows observes the files you
open and save in your application by means of standard Windows file dialogs
open in your application by starting yourapp.exe <file name>, for instance by double-clicking a file that opens in your application
and automatically display these in the list.
If you want to control the task bar button and menu programmatically, you can use the Windows API. Delphi-specific examples are found in this blog post.
In my opinion the best way to do this is to make the following simple API call:
SHAddToRecentDocs(SHARD_PATH, PChar(FileName));
This not only deals with Windows 7 jump lists but also adds your file into the system's list of recently used documents which has an effect on early versions of Windows too.
Call the function whenever you open or save a file.
For your convenience, a link to the documentation of SHAddToRecentDocs().
Here are some resources that I have found useful when making my programs vista ready
http://code.google.com/p/theunknownones/wiki/TaskbarListComponents
http://www.installationexcellence.com/articles/VistaWithDelphi/Index.html
http://www.theabsolute.net/sware/delphivista.html

Modifying old Win32 application without source code (possibly written using Borland tools)

I have a quite old Windows application (1998) which is no longer maintained by the author and I don't have its source code. This application in one of its windows has a dropdown list widget where the user can choose one of the 4 predefined values (numbers). I need to add new predefined values there or change the widget to something that lets me introduce any value (some edit field or editable combobox).
Some other data about the application:
Probably written using some Borland tools, I guess it uses BDE and Paradox as its database.
There is a file with .mme extension in the directory. I unpacked it and it contains 5 files: .data, .rdata, .rsrc, .sdata, .text. I viewed them in a hex editor and they contain some text data but I don't know how to look for those predefined values. Since they are numbers it's probable that I will find just some other numbers.
I tried using RedEdit and XN Resource Editor but they show only the icon and version info.
I know my question is kind of vague, but if I don't find any solution to this I will have to rewrite the whole program, so I'm asking just in case there is a solution.
It might be possible to write another app that looks for this program, gets a handle to the window owning the drop-down box (if t's a native windows component), and then gets a handle to the drop-down box and use the Windows SendMessage API to manipulate the contents of the drop-down box.
http://msdn.microsoft.com/en-us/library/ms632595(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx
It might require so much effort that it may be better to just rewrite the app!
If it is written with Borland tools, you can probably find out which one by searching the EXE for the string "Borland" - there should be a copyright string somewhere.
Once you know, find someone with Borland tools experience and have her find out if those numbers in the drop-down list happen to come out of a database table. If they do, try modifying that table, if not, rewrite the app :)

how to load delphi tframe from dll to delphi application

i have created a dll with tframe .
how can i load it inside my application, i dont like to use bpls , i only want to destribute exe and dlls with my app
Since a BPL is a DLL, go the BPL way: much easier.
It can be done but it's a hell of a job to get it working without errors or memory problems. To make matters worse, you will be using two VCL's in your application, one in your executable and another in the DLL. Your frame would try to refer to the DLL VCL, which would provide very different information than the EXE VCL. Especially when checking the global Screen and Application variables.
Still, a frame is nothing more than a special window control, just like forms. You could export a function from your DLL which would return a value of type TFrame. Your application would be able to call this function and thus create the frame, use it in any way it uses all other frames. It won't have any specific information about additional functionality within your frame, though.The next thing you'd have to work on is to synchronize the data between the EXE and the DLL that is VCL related. That's not very pretty. Plus, you will probably have some issues when using the tab key to tab through the controls on your screen, since the tab key won't be able to tab outside the frame. And you will notice a few more oddities like this.
I have worked on a simple application that used frames this way. Me, and two others spent two months getting some working solution, which did work reasonable well without memory leaks and other troubles. Before we started that project, it just seemed like a good idea. Afterwards, we decided that it didn't turn out to be the solution we'd wanted so we merged the code of the DLL's with the code of the executable to just create one executable. It was better that way.
We did use another alternative, though. We started using a webbrowser component in the mainform. The DLL would contain a HTML page, nicely formatted, and a bunch of methods that would be called when certain specific functions were used. We had this working in a simple test application with good results but then the company went chapter 11... My employer went dead broke since a deal with some customer misfired badly, leaving the company with some huge debts. And thus an interesting project ended...

Resources