Disable Print button in HtmlHelp - windows

I'm performing maintenance on a legacy MFC application. We have a need to disable the Print button in the Help dialog. There is no printer connected to the system and the application crashes if the user presses the Print button in the help window.
The code just uses the standard HtmlHelpA method to bring up the Windows Help dialog:
void CNiftyView::OnHelp()
{
CString csHelpFile;
csHelpFile.Format( "%s/NiftyHelp.chm", NiftyDoc::GetHelpPath() );
::HtmlHelpA( m_hWnd, csHelpFile, HH_HELP_CONTEXT, IDH_NIFTY_SECTION );
}
I've found information that we can suppress the Print button with some code in the Help HTML stylesheet (http://www.sagehill.net/docbookxsl/HtmlHelp.html). But that would require recompiling the help file, and I'd prefer to not do that. I also found some information that says you can customize the HTML Help Viewer by manipulating each pane's HH_WINTYPE structure, but no information on how you actually do that (http://msdn.microsoft.com/en-us/library/ms524435%28v=vs.85%29.aspx).
Is there some way to disable that Print button in the HTML Help viewer programatically?

You can display your CHM help file without the Print button as follows:
Call HtmlHelp with the HH_GET_WIN_TYPE command to get a pointer to a HH_WINTYPE structure containing the HTML Help Viewer parameters defined in your CHM file.
Copy the returned structure. (Modifying the returned structure directly won't work.)
Modify the fsToolBarFlags member of the structure to exclude the HHWIN_BUTTON_PRINT value.
Pass the modified HH_WINTYPE structure back to the HtmlHelp function using the HH_SET_WIN_TYPE command.
Example C++ code*:
HH_WINTYPE *pwt = NULL;
LPCWSTR pszFile = L"MyFile.chm";
LPCWSTR pszWin = L"MyFile.chm>Main"; // "Main" is the window type defined in the CHM file
// Get the window type definition
HWND hWndHelp = HtmlHelp(NULL, pszWin, HH_GET_WIN_TYPE, (DWORD) &pwt);
if (pwt) {
// Copy the contents of the returned structure
HH_WINTYPE wt = *pwt;
// Remove the "Print" toolbar button from the window definition
wt.fsToolBarFlags &= ~HHWIN_BUTTON_PRINT;
wt.cbStruct = sizeof(wt); // force the correct size
// Set the new window type
hWndHelp = HtmlHelp(NULL, pszFile, HH_SET_WIN_TYPE, (DWORD) &wt);
// Display help
hWndHelp = HtmlHelp(NULL, pszFile, HH_DISPLAY_TOPIC, NULL);
}
I almost don't know C++, so it's very amateur code. Please fell free to edit and improve it.
More examples of using HH_WINTYPE, HH_GET_WIN_TYPE and HH_SET_WIN_TYPE:
How To Programmatically Create a Tri-pane HTML Help Window
How to use the unmanaged HTML Help API from a managed Visual C# application

Related

Automate a reoccuring manual task (generate order number based on name) in Visual Studio

I'm currently working on a EpiServer project where we use the ContentType attribute to set the DisplayName and Order of the blocks. The Order is based on the name of the block. Here's an example:
[ContentType(
DisplayName = "My First Block",
Order = 133536,
GUID = "0f02e38a-a6e2-4333-9bd1-c61cf573d8d3",
Description = "Just an example block.",
GroupName = "Blocks.Content"
)]
public class MyFirstBlock : BaseBlock
{
}
Apparently EpiServer can't sort the blocks alphabetically so we generate the order based on the DisplayName as a work around. A formula was invented to determine the order. One colleague has written a JavaScript function that can be used to generate the order number:
function getEPiOrderNumber(value) {
var alphabeticalIndex = function (character) {
return character.toLowerCase().charCodeAt() - 96;
};
var firstSection = alphabeticalIndex(value[0]);
var secondSection = alphabeticalIndex(value[1]) + 10;
var thirdSection = alphabeticalIndex(value[2]) + 100;
return `${firstSection}${secondSection}${thirdSection}`;
}
This function can be executed in the console of a browser. Better than having to calculate the order by hand, but this requires that I switch to a browser, open the console, paste this code and execute it and finally copy the result and paste it in the model I'm working on.
I figured it would be much more convenient to be able to do generate the order number from within VS. I have been looking into using Visual Studio Extensions but can't really find anything that is to my liking.
The most optimal solution would be to be able to select the (part of the) DisplayName, right click and select a new command from the context menu that will generate the order and paste it at the correct location. Or place it on the clip board so I can easily paste it in the right location myself. A pop-up displaying the order would be fine as well.
Is this even possible?
Another option could be a new command in one of the toolbar menu's, say Tools, that would display a small window where I can enter/ paste the text and to have it generate the order that I can then paste in the code.
I have figured out how to add an Custom Command to the Tools menu and how I could generate the code and display it, but how can I enter the text? Or is it maybe possible to retrieve selected text from the editor window? That would solve my problem as well.
If anyone could point me in the right direction, that would be great!
PS. I'm not too happy with the title of this question so I'm open to suggestions if anyone can think of a title that better describes my question.
You could retrieve selected text from Visual Studio editor window with following code.
DTE dte = (DTE)this.ServiceProvider.GetService(typeof(DTE));
string text = "";
if (dte.ActiveDocument != null)
{
var selection = (TextSelection)dte.ActiveDocument.Selection;
text = selection.Text;
}

Open a dialog using openDialog and pass an object parameter

I'm developing a Firefox extension which has this code to open some dialog:
Cu.import("resource://gre/modules/Services.jsm");
function showPanel()
{
let mainWindow = Services.wm.getMostRecentWindow("navigator:browser");
mainWindow.openDialog(data.url("ui/options.html"),
"Dictionary settings",
"chrome,centerscreen,dialog,modal,resizable,scrollbars,height=400,width=400",
{ a: 123 });
}
On the dialog side, when I access window.arguments[0] I get an empty object with no fields.
If I pass primitives like strings and numbers, they are passed correctly to the dialog.
What's the problem with this code?
Regards,
Update:
As I won't be able to commit my code, I've created a whole branch of the project.
Please check this repository https://github.com/ashrafsabrym/firefox-dict-switcher
Using an object or array as parameter sends an empty object to the dialog, while primitives work well.

How to access the content of a webpage displayed in a tab from a Firefox addon

In a Firefox extension, I am attempting to add a form into the web page by inserting DOM elements, and then process any data that the user enters in the form.
I have tried several methods, but have been unable to get my form inserted into the webpage's document. I tried using the different types of add-ons, Overlay (XUL) and the Add-on SDK, but I have not been able to get it to work.
Overlay/XUL: I investigated and found nothing that specifically showed me how to change the contents of a web page.
Using the Addons SDK: The only working code which I found was the demo code in "Modifying Web Pages Based on URL" which appeared to give:
var html = sth;
$("body").html(html);
I tried:
$('.id_of_ele').html('I want to show');
It doesn't work.
So far the only thing which has gotten me close is to use unsafeWindow.document, but I believe that is a really a bad idea, and the code looks really bad.
How do I access the the document of a webpage from a Firefox extension?
If you are looking for examples of known working code, you can always download one or more extensions from Mozilla Add-ons which do something close to what you want to accomplish and look at how they do it. Obviously, you should look at the license (linked on each extensions page) to see what the legal status of the code it. There are literally thousands of working examples there. The vast majority of which have code which is licensed in a way which permits you to re-use it.
The jQuery accesses which you are trying to use rely on the document variable pointing to the document which you are wanting to modify. In the context in which you are running, a Firefox add-on, the document variable may, by default, point to a document which is an ancestor of the webpage you are interested in or not be defined at all. What document actually is will depend on the context from which your add-on code was invoked. In a Firefox add-on, the document variable will almost never, by default, point to the content of a web page. You have to remember that you are writing code that is intended to run in a context that is much larger (entire browser/user agent) than that which is used for content scripts on a webpage (context within the browser is restricted to only the content of the webpage from which the script was run, or data which is obtained from references originating from within the page).
Gaining access to the document for the currently selected tab:
Changing the content document is very easy. You can change it just like you would from any JavaScript. The issue that you may find frustrating is obtaining a reference to the document.
Firefox overlay and restartless/bootstrapped have a great amount of power over the entire browser. However, the context, and what window points to, or even if it is defined, depends greatly on how the JavaScript was invoked. This can be both confusing and frustrating. On MDN, there is a document "Working with windows in chrome code" which describes many of the issues.
From extensions you have access to all windows and tabs. However, what you probably want is just some code that works to get you access to the current selected document.
This should work from all contexts to get you a reference to the document for the currently selected tab:
var selectedTabWindow = Components.classes["#mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
var selectedTabDocument = selectedTabWindow.content.document;
If you have code which you are converting from a content script which just expects to find window and document objects, you could write something like:
if (typeof window === "undefined") {
var window;
} else {
//Keep a reference to whatever was defined as window.
var originalWindow = window;
}
//Get the window from the most recently selected tab.
window = Components.classes["#mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
//Now that we have a window for the most recently selected tab,
// get the document for it.
if (typeof document === "undefined") {
var document;
} else {
//Keep a reference to whatever was defined as document.
var originalDocument = document;
}
document = window.content.document;
//Now that we have a window for the most recently selected tab,
// get the gBrowser for it.
if (typeof gBrowser === "undefined") {
var gBrowser;
} else {
//Keep a reference to whatever was defined as gBrowser.
var originalGBrowser = gBrowser;
}
gBrowser = window.gBrowser;
The above will, obviously, overwrite any currently variables currently defined as window, document and gBrowser. Depending on the context in which you are running, and the scope in which you define these this could be either a good thing, or it might be a bad idea to change that reference. For example, if the code is running in a popup window then window is a reference to window of the popup. In that case, you can get a reference to the window from which the popup was opened with:
var windowWhichOpendedThisOne = window.opener;
var documentForWindowWhichOpendedThisOne = window.opener.content.document;
If you are in an event handler, then you can get the window for the target of the event from:
var windowInWhichEventTargetExists = event.view;
Choosing what to do based on the URL:
Once you have the correct document it should be quite easy to choose what to do based on the document's URL:
var currentUrl = document.location.href;

Make a click event based on a control's name value property

I'm using TestComplete for the automation of QA process.
TestComplete detects click events based on the postion of the mouse on the screen. But when I run the same test on a different machine (a larger/smaller screen) the mouse button won't click on the correct position.
Therefore I want to know is there a method which I can search a control based on its name (i.e. name of a button) and then run a script to click on that particular word (or position).
Any help is appreciated :)
Additional Details
This is a sample script generated by TestComplete for clicking the search button on a web page.
Sub Test6()
'Opens the specified URL in a running instance of the specified browser.
Call Browsers.Item(btIExplorer).Navigate("http://www.simplyrecipes.com/search/?cx=003084314295129404805%3Ai2-mkfc4cai&cof=FORID%3A11&q=&sa.x=48&sa.y=16")
'Clicks at point (173, 10) of the 'textboxQ' object.
Call Aliases.browser.pageHttpWwwSimplyrecipesComSearc.panelPage.headerMasthead.group.panelSiteSearch.formSearchbox0030843142951294048.textboxQ.Click(173, 10)
'Sets the text 'asd' in the 'textboxQ' text editor.
Call Aliases.browser.pageHttpWwwSimplyrecipesComSearc.panelPage.headerMasthead.group.panelSiteSearch.formSearchbox0030843142951294048.textboxQ.SetText("asd")
'Clicks at point (57, 12) of the 'imagebuttonSa' object.
Call Aliases.browser.pageHttpWwwSimplyrecipesComSearc.panelPage.headerMasthead.group.panelSiteSearch.formSearchbox0030843142951294048.imagebuttonSa.Click(57, 12)
End Sub
Here is the button click event captured in the RecordTest window
What I want to know is, is there a way I can specify the control name (i.e 'Search' or 'imagebuttonSa'), so the TestComplete will search for the name in the given GUI and then once it's found, make a click event on the word.
I'm using Windows 7 64bit OS, TestComplete 9 trial version and VBScript as the scripting language.
As far as I can see, TestComplete already works in your case with specific controls/objects: textboxQ and imagebuttonSa. These two names are given to objects by the Name Mapping functionality and you are free to change them as you like.
As for the coordinates, these coordinates are related to the top left corner of the corresponding control (textboxQ or imagebuttonSa). If you want, you can remove the coordinates from the action parameters (e.g. ...imagebuttonSa.Click()) and TestComplete will click the central point of the control.
In case you have any problems with playing back your tests and you cannot find out what the cause of these problems is, the best option for you will be contacting the SmartBear support team with detailed explanation of what happens. Send them your project with failed results logs.
Whenever I have a problem with not finding an object with TC I use one of this functions or a combination of them.
In case you have the table object (parent of the cell you want to click):
function clickCellByText(text,tablePath)
{
var table = tablePath;
if (!table.Exists)
{
Log.Error("A table with the following text cannot be found: " + table);
}
clickCell1(table, "*Cell*", "*Cell*");
function clickCell1(table, idText, linkText)
{
var propArray = new Array("innerText", "ObjectType");
var valArray = new Array(text,"Cell*");
var idCell = table.FindChild(propArray, valArray, 20000);
if (idCell.Exists)
{
// Row found, find the link in the same row
idCell.Click();
}
else
{
Log.Error("A cell with the following text cannot be found: " + text);
}
}
}
If you want to find the object or the parent of the object by any property:
function clickComponent(property,text)
{
// Using the Find method
var myObj = Sys.Browser("iexplore").Page("*").NativeWebObject.Find(property,text);
// Checks if the button exists
if (myObj.Exists)
{
myObj.Click();
}
else
Log.Error("Can't find the object","");
}
If you don't specify co-ordinate, it will click at the center of the object.
You can try doing FindChild or Find with the Object Name Mapping where the button resides, with Properties like (Eg:ObjectType as Button and Button Caption with your required button caption), once the FindChild finds the button with above specified properties you can use that object to click on it:
var button = ParentObj.FindChild(["ObjectType","Caption"],["Button","OK"],10);
if(button.Exists)
button.Click()

IShellView: ColumnHeaders not hidden if AutoView does not choose Details

I`m using an IShellView instance with the FVM_AUTO (-1) flag as view mode. That means the explorer should choose a viewstyle that fits the content of the displayed folder.
This works fine except the fact, that columnheaders are visible for viewstyle other than Details, e.g. Thumbnails.
The IShellView object and view window is created like this:
ShellFolder1.CreateViewObject(this.Handle,
ref IID_IShellView,
out shellViewObject));
IShellView shellView = shellViewObject as IShellView;
FolderSetting folderSettings = new FolderSetting();
folderSettings.ViewMode = (int)View; // view is FVM_AUTO = -1
folderSetting.FolderFlags = FolderFlags.NoClientEdge
| FolderFlags.ExtendedTiles
| FolderFlags.AutoArrange
// only columnheaders for view mode details
| FolderFlags.NoHeaderInAllViews;
shellView.CreateViewWindow(oldView, ref folderSettings, isb,
ref rect, ref m_ShellViewHandle);
A list of available folder flags can be found here: http://msdn.microsoft.com/en-us/library/bb762508(VS.85).aspx
Any suggestions how to tell the view that column headers should be displayed only for "details" in auto view mode? setting FolderFlags.NoColumnHeader does not change anything.
Thanks
this behavior seems to be a bug and is reported on MS connect
Additional information from MS support:
The folder controls the view. The values you pass to CreateViewWindow are merely suggestions. For the most part, these suggestions are respected, but a folder is technically allowed to ignore them.
In particular, this case overrides the suggestion for compatibility with Windows XP. If you use IShellView3::CreateViewWindow3, then this compatibility behavior does not apply, and the flags should be respected better. You can use the SV3CVW3_FORCEFOLDERFLAGS flag to make your suggestion more emphatic.
--> use IShellView3.CreateViewObject3 with the ForceFolderFlags flag

Resources