Can I find out current typing co-ordinates in a notepad relative to desktop window - delphi

Is it possible for me to find out the typing co-ordinates (relative to desktop co-ordinates) in a notepad window from a Delphi application? For example, if we look at the below picture, I am typing on a notepad window. Can I find out the screen co-ordinates, where I am typing on notepad.
Edit
It would be helpful if someone can suggest a generic solution. Answer no1 speaks about notepad. How about a console window? Is it possible to figure out the co-ordinates, if i am typing on a console window?

I guess, if UAC would not disable it, you can implement the following sequence:
you have to learn the windows structure of the notepad. Using tools like WinSpy++, WinSight or ProcFS for Total Commander or whatever. And then you have to get the handle (HWND) of the actual editbox window. The topic of enumerating or finding other applications windows was discussed many times already on StackOverflow and on Google.
Then you have to ask the main edit window for it coordinates. See Get{Client/Window}Rect functions, see http://msdn.microsoft.com/en-us/library/windows/desktop/ms633503.aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519.aspx Perhaps even better would be to SendMessage the EM_GETRECT custom message: http://msdn.microsoft.com/en-us/library/ms997530.aspx
Then you have to know the position of caret: like TMemo.SelEnd and TEdit.SelStart - again best way would be to just read how they are implemented in VCL. Probably that would be rooted in SendMessage(EM_GETSEL,...) - http://msdn.microsoft.com/en-us/library/ms997530.aspx - there is a ready example to do this
Then you would have to ask Widows for relative coordinates of that position - relative to the Client Rect you get in above steps. See EM_POSFROMCHAR message http://msdn.microsoft.com/en-us/library/windows/desktop/bb761631.aspx and Delphi sample at http://www.delphipages.com/forum/showthread.php?t=33707
However some claims that this does not always work reliably: http://vbcity.com/forums/t/14951.aspx so as last resort you can use hard-core string parsing, as described in version 1 of this answer.

Related

How to use MenuItemExecute() with AVDoc.OpenInWindowEx()

Is it possible to use Acrobat.MenuItemExecute('Copy'); command with
AVDoc.OpenInWindowEx(FFilename, Panel1.handle, 0, True, 0,0, 2, 0, 0, 0);
in Delphi 7 and Acrobat XI Pro?
If you help me with an example I'll be glad.
I think the answer to this is probably "no" because before calling Acrobat.MenuItemExecute('Copy'), it is necessary to call BringToFront on the window containing the text you want to copy, otherwise the call to MenuItemExecute('Copy') will fail, even when the document is hosted in one of Acrobat's own windows. I don't see how you could do that successfully when the document window is hosted in your app, rather than Acrobat.
However, there are a few things you could add to your q that might assist in getting a better answer. [...]
Update Please disregard my comments in an earlier version of this answer saying that I could not reproduce the behaviour that I could not select text in the window opened using OpenInWindowEx. In fact, I can now select text fine, what I had overlooked previously is that I had set the Enabled property of my TPanel to False.
Unfortunately, I have still not been able to successfully call Acrobat.MenuItemExecute('Copy') and I am beginning to think that there is no way to do this in a hosted window. I have not found a definitive list, but various comments by Adobe staffers that google found make it clear that many MenuItemExecute strings just to not work when using OpenInWindowEx.
However that may not be the only way to retrieve the selected text back into the Delphi app.
If you look at the hosted window using a tool like WinSpy or Window Detective you will see that contained within the panel window is a whole host of Acrobat windows, including an AVL_AVView one with the Window text "AVPageView" which I imagine is the actual window displaying the PDF text.
I think the key to a possible solution is your observation, which I've confirmed, that pressing Ctrl-C in the window copies the text to the clipboard. So far I have not been able to achieve the equivalent in code, using techniques like keybd_event calls, various Delphi "SendKeys" routines and sending a WM_COPY message to the AVPageView window. I'm sure it must be possible, but I haven't yet found a way.

How can I make the 'Showmessage' dialog wider so it fits the text?

I'm showing where a file has been saved by using 'Showmessage' (in Win 7).
When the file path is long it gets truncated and elipsis get inserted.
eg
the path
C:\Users\Admin\Documents\SubFolderOne\AnotherSubFolder\MyFile.csv
gets displayed as
C:\Users\Admin\Documents\SubFolderOne\Ano...\MyFile.csv
Is there a way to make the message box wider and show all of the filename and path?
I have read this
http://zarko-gajic.iz.hr/displaying-long-non-breakable-text-file-path-in-messagedlg-truncationellipsis-issues/
which explains some of the reasoning and gives a rather unsatisfactory method for a TTaskDialog and I also I realise I could make my own form to act in the same way as Showmessage but I am wondering if there is a simpler solution using just Showmessage.
Is a simpler solution using just ShowMessage?
No there is not.
I can think of three obvious approaches, although doubtless there are more.
Create your own dialog
There's nothing particularly magical about a dialog. You can perfectly well create them yourself, and so have complete control over their appearance. The downside of course is that it can be hard to match the native platform appearance. Especially when you consider all the different Windows versions that you are typically expected to support.
Use CreateMessageDialog and customise this Delphi form
You can call the RTL function CreateMessageDialog to obtain a Delphi form that can be used to display your message dialog. You then have the opportunity to customize this dialog in any way you please.
Use the task dialog API
The task dialog API, introduced in Vista, affords control of the dialog width. Call TaskDialogIndirect, and specify a non-zero value for cxWidth.
Before ShowMessage put:
UseLatestCommonDialogs:= false;
I use Delphi 10.2 and it works.

Change help link in the Visual Editor of MediaWiki

Is there a way to change the help link in the toolbar dropdown in the new visual editor of MediaWiki?
I tried setting
"visualeditor-help-link":"mw:Help:VisualEditor/User guide/de"
in
"extentsions/VisualEditor/modules/ve-wmf/i18n/de.json"
as proposed here, but then my MediaWiki could not parse the JSON file. My goal is to link to the MediaWiki help page, that can be found here. The normal version:
"visualeditor-help-link":"[https://www.mediawiki.org/wiki/Help:VisualEditor/User_guide/de]"
did not work, neither did this:
"[[{{MediaWiki:visualeditor-helppagelink}}|Hilfe]]"
You should never ever change the source code of MediaWiki core or any extension. It makes an upgrade process much more hard and complicated. There are other ways to achieve a high customization of the user interface language :)
For your problem, it should be enough to create the following page in your wiki (like any other page, but you need the editinterface user right, which is assigned to sysops by default):
MediaWiki:visualeditor-help-link
Put the link you want to use into the textarea (without any wikitext, e.g. "Help:VisualEditor" (without any ")) and save the page.
After reloading the VisualEditor (maybe you need to clear your browser's cache using Ctrl + F5) the link should point to the new target you specified in the message above. If you use a message cache, it is maybe needed to rebuilt it.

Link to other page than specified

I use a program that has a button which opens a webbrowser on a pre-defined page, let's say https://www.somepage.com. As it is not possible to rewrite this program, I would like to know whether it is possible to change the target into another page, let's say https://www.mypage.com (i.e. without rewriting the program).
Even better would be to open a window in which you can choose between going on to somepage.com and mypage.com.
Yes that is possible. It depends on your System how that is done.
On a Unix system find your hosts file (/etc/hosts is likely), then add a line like this:
www.somepage.com www.mypage.com
That should do it. I guess on a Windows it is similar (at least it used to be on 2000 :)

How do I make a TLinkLabel work in Delphi?

I put a TLinkLabel on my form, filled it in with a caption including a valid HTML link, and got some nice blue underlined text. When I ran the program, I expected it to invoke Firefox (my default browser) and open the link automatically. Apparently that's not the case.
The helpfile says I have to code this in an OnLinkClick event handler. It doesn't say anything about how to do that, though. It'll pass in a string value called "Link". How do I say "invoke the default browser and have it open Link"?
You can call ShellExecute.
I wrote this method for generic calls, and should works in your case.
procedure ShellOpen(const Url: string; const Params: string = '');
begin
ShellAPI.ShellExecute(0, 'Open', PChar(Url), PChar(Params), nil, SW_SHOWNORMAL);
end;
In your code you should call this
procedure TForm1.LinkLabelClick(Sender: TObject);
begin
ShellOpen(LinkLabel.Caption);
end;
I have all sorts of problems with TLinkLabel that ships with delphi 2010.
a) The control does not render as a hyperlink but as a simple label text on the form. b) the cursor does not change to point out this is a link even though I set the Cursor property. c) the OnLinkClick event does not fire at all.
I am working on windows 7.
So, as far as I am concerned, TLinkLabel does nothing as it should and is useless. ShellExecute is the only solution and must be placed in the OnClick event.
TLinkLabel provides a label that looks like a link. It's your job as the programmer to make it act like a link because only you can know what links are supposed to act like in your program. You wanted the label to automatically open the user's default Web browser using the URL in the label, but that's not the only thing links do. For example:
Internet Explorer is not my default browser, but when I click a link in Internet Explorer, I do not expect the linked page to open in Firefox.
When I click a link in the help program, I expect the linked topic to appear in the help program, not in any Web browser at all.
The preference pages in Eclipse are very complicated. Settings on one page are sometimes related to settings on another page. There are links on those pages that take the user directly to the related page. There is no URL and no HTML involved in this case, and yet they're still labels with underlined text.
Some programs try to offer a choice between opening links in new windows versus re-using old windows. You can't implement that feature without knowing which browser is in use. Your program might offer the user a choice to ignore the default browser setting and always use a specific one. To do that, your UI control can't make too many assumptions about what the program is supposed to do.
I'm guessing you're referring to a TLinkLabel control that comes with Delphi. (My versions don't have such a component.) I imagine that the Delphi control is meant to mimic the one in the .Net class library. It can hold multiple links, and each link can do something different.
If you want a control that always does the shell's default action for URLs, then consider using a different TLinkLabel; the one by Alexander Bach does exactly what you expected. It's from Delphi 3, but it should work unmodified in all later versions as well, including Delphi 2009. If you look at the code, you'll see how it works. It simply calls ShellExecute, as Cesar's answer demonstrates.
LOL, it's funny. So instead of setting crHandPoint as cursor, colored and underlined font and filling the OnClick event to standard TLabel we have component that knows link tag and which at all I need to supply with same On(Link)Click event :))
Only thing it is good for is that it makes easier to embed link into some text and that it is using system style of link...
p.s.: really you have to put Some text with link into the Caption and setup OnLinkClick to that ShellExecute...
I use a control called TInternetLabel instead. It does exactly what you want: on click it opens the browser so you don't have to put code in the OnClick event.
I tried this solution but it still gave problems in Delphi XE4, probably becasue ShellOpen does not understand the HTML-code in the Caption.
What worked for me was a combination of Cesar Romero (the basic code), Adam Feistner (The HTML-code in the Caption) and an older solution:
Put the URL in the HINT field.
Change the line: ShellOpen(LinkLabel.Caption);
to
ShellOpen(LinkLabel.Hint);
This worked for me.

Resources