IE: Prevent confirming dialog box when using window.close() to close a main window

[Origin]: https://blogs.msdn.microsoft.com/rextang/2008/10/17/ie-prevent-confirming-dialog-box-when-using-window-close-to-close-a-main-window/


Been busying on investigating Dynamics CRM 4 Web Application and Outlook VSTO Add-In development for the past weeks and not update blog much. It’s time to do a post now.

Little but useful trick when toying with IE windows.

When there is only a parent IE window and you load some pages with javascript “window.close();” that trying to close the window, in IE there will be a confirming dialog box asking if one really want to close the IE window. This often causes problems if you want to host your IE in a winform, and here are some simple and quick workaround to overcome this.

   1: <HTML>
   2: <HEAD>
   3: <TITLE>Close window without prompt</TITLE>
   4: <SCRIPT LANGUAGE="JavaScript">
   5: <!--
   6: function realClose()
   7: {
   8:     var win=window.open("","_top","","true");
   9:     win.opener=true;
  10:     win.close();
  11: }
  12: //-->
  13: </SCRIPT>
  14: </HEAD>
  15: <BODY>
  16: Close window without prompt
  17: <FORM><INPUT TYPE="button" VALUE="Close ME!" onClick="realClose()"></FORM>
  18: </BODY>
  19: </HTML>

The trick is to open an empty page in self window (the “_top”), and then close the opened window in javascript to fool IE that he is closing a child window. this worked without problems.

Further more, if you don’t have ways to modify the page you are opening, thus not able to embed the realClose() function to the page, maybe in a WinForm that hosting a IE window and actually you don’t know what page you are going to open, maybe this way would work.

   1: <HTML>
   2: <HEAD>
   3: <TITLE>Close window without prompt</TITLE>
   4: <SCRIPT LANGUAGE="JavaScript">
   5: <!--
   6: function realClose()
   7: {
   8:     var win=window.open("","_top","","true");
   9:     win.opener=true;
  10:     //win.close();
  11:     win.realclosefunc();
  12: }
  13: window.realclosefunc = window.close;
  14: window.close = realClose;
  15: //-->
  16: </SCRIPT>
  17: </HEAD>
  18: <BODY>
  19: Close window without prompt
  20: <FORM><INPUT TYPE="button" VALUE="Close ME!" onClick="javascript: window.close();"></FORM>
  21: </BODY>
  22: </HTML>
  23:  

in this way, when in WinForm, try to manipulate DOM of the hosting IE window, and try to insert the piece of code in the head part of page, then change the default window.close function to our self-made function to close the window. using this way won’t need to do a string replacement of the downloaded html contents to replace window.close() to our close function. little bit tidy, but still doable…

For WinForm hosting pattern, using .net 2.0 WinForm WebBrowser control won’t give you that magic WindowClosing event to prevent IE closing in your WinForm. There are articles introducing hooking DWebBrowserEvents2 interface to get this event working with WebBrowser control, but for no reason it just not working.

So I just tried to use COM Interop way to bridge the ActiveX IE control to .net by using aximp.exe command, and by doing this found that the WindowClosing event is working and able to detect the IE close before that confirming dialog box showed up, and then to cancel the IE close action inside the event and close my WinForm. this should be the easiest way to accomplish this task I think.

Advertisements

SSRS 2008 R2 – SSRS 2012 – ReportViewer: Reports are blank in Safari and Chrome

[Origin]: https://stackoverflow.com/questions/5968082/ssrs-2008-r2-ssrs-2012-reportviewer-reports-are-blank-in-safari-and-chrome/7043409#7043409

I migrated our reporting services from version 2008 to another server version 2008 R2. In version 2008 the reports work fine on Safari. The new version 2008 R2 the reports do not show up at all. All I see is the parameter section and then the report is blank. Same in Chrome. According to Microsoft Safari IS supported if in a limited fashion. The reports are not complex. In fact I created a report that only had a line on it to see if it would show up in Safari but no, that report is completely blank as well. Did anyone make SSRS reports viewable on Safari? Do I have to mess with some kind of a configuration setting?

Ultimate solution (works in SSRS 2012 too!)

Append the following script to the following file (on the SSRS Server)

C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportManager\js\ReportingServices.js
function pageLoad() {    
    var element = document.getElementById("ctl31_ctl10");
    if (element) 
    {
        element.style.overflow = "visible"; 
    }
}

Note: As azzlak noted, the div’s name isn’t always ctl31_ctl10. For SQL 2012 tryctl32_ctl09 and for 2008 R2 try ctl31_ctl09. If this solution doesn’t work, look at the HTML from your browser to see if the script has worked properly changing the overflow:auto property to overflow:visible.


Solution for ReportViewer control

Insert into .aspx page (or into a linked .css file, if available) this style line

#reportViewer_ctl09 {
  overflow:visible !important;
 }

Reason

Chrome and Safari render overflow:auto in different way respect to IE.

SSRS HTML is QuirksMode HTML and depends on IE 5.5 bugs. Non-IE browsers don’t have the IE quirksmode and therefore render the HTML correctly

The HTML page produced by SSRS 2008 R2 reports contain a div which has overflow:autostyle, and it turns report into an invisible report.

<div id="ctl31_ctl10" style="height:100%;width:100%;overflow:auto;position:relative;>

I can see reports on Chrome by manually changing overflow:auto to overflow:visible in the produced webpage using Chrome’s Dev Tools (F12).


I love Tim’s solution, it’s easy and working.

But there is still a problem: any time the user change parameters (my reports use parameters!) AJAX refreshes the div, the overflow:auto tag is rewritten, and no script changes it.

This technote detail explains what is the problem:

This happens because in a page built with AJAX panels, only the AJAX panels change their state, without refreshing the whole page. Consequently, the OnLoad events you applied on the <body> tag are only fired once: the first time your page loads. After that, changing any of the AJAX panels will not trigger these events anymore.

User einarq suggested this solution:

Another option is to rename your function to pageLoad. Any functions with this name will be called automatically by asp.net ajax if it exists on the page, also after each partial update. If you do this you can also remove the onload attribute from the body tag

So wrote the improved script that is shown in the solution.

Is it possible to have an “Always on top” feature in (L)ubuntu?

[Origin]: https://askubuntu.com/questions/645693/is-it-possible-to-have-an-always-on-top-feature-in-lubuntu

I’m using Lubuntu 14.04 64 Bit and I need to have the “Always on top” feature so I can have any window always visible if I need to.

I’ve searched a lot up and down, but to my surprise I could not find anything.

Is it possible at all to have this feature ?

Problem solved!

Right-click the Window Decoration (Upper Window Border) => Layer => Always on top

Credit goes to “drooly” at the LXDE forums

  • Another way to do this is using the keyboard shortcut alt+space to bring up the same menu then select always on top. – ianorlinJul 15 ’15 at 17:19
  • Is there a way to do this from the command line when opening a GUI program in Lubuntu 14.04? – Andy JSep 8 ’15 at 15:27
  • the alt+space @ianorlin mentioned is important to override Chrome’s right click menu – AsafMay 19 ’16 at 9:16

How to get a date in YYYY-MM-DD format from a TSQL datetime field?

[Origin]: https://stackoverflow.com/questions/889629/how-to-get-a-date-in-yyyy-mm-dd-format-from-a-tsql-datetime-field

How do I retrieve a date from SQL Server in YYYY-MM-DD format? I need this to work with SQL Server 2000 and up. Is there a simple way to perform this in SQL Server or would it be easier to convert it programatically after I retrieve the result set?

I’ve read the CAST and CONVERT on Microsoft Technet, but the format I want isn’t listed and changing the date format isn’t an option.

SELECT CONVERT(char(10), GetDate(),126)

Limiting the size of the varchar chops of the hour portion that you don’t want.

Starting with SQL Server 2012 (original question is for 2000):

SELECT FORMAT(GetDate(), 'yyyy-MM-dd')
SELECT convert(varchar, getdate(), 100) -- mon dd yyyy hh:mmAM

SELECT convert(varchar, getdate(), 101) -- mm/dd/yyyy – 10/02/2008                  

SELECT convert(varchar, getdate(), 102) -- yyyy.mm.dd – 2008.10.02           

SELECT convert(varchar, getdate(), 103) -- dd/mm/yyyy

SELECT convert(varchar, getdate(), 104) -- dd.mm.yyyy

SELECT convert(varchar, getdate(), 105) -- dd-mm-yyyy

SELECT convert(varchar, getdate(), 106) -- dd mon yyyy

SELECT convert(varchar, getdate(), 107) -- mon dd, yyyy

SELECT convert(varchar, getdate(), 108) -- hh:mm:ss

SELECT convert(varchar, getdate(), 109) -- mon dd yyyy hh:mm:ss:mmmAM (or PM)

SELECT convert(varchar, getdate(), 110) -- mm-dd-yyyy

SELECT convert(varchar, getdate(), 111) -- yyyy/mm/dd

SELECT convert(varchar, getdate(), 112) -- yyyymmdd

SELECT convert(varchar, getdate(), 113) -- dd mon yyyy hh:mm:ss:mmm

SELECT convert(varchar, getdate(), 114) -- hh:mm:ss:mmm(24h)

SELECT convert(varchar, getdate(), 120) -- yyyy-mm-dd hh:mm:ss(24h)

SELECT convert(varchar, getdate(), 121) -- yyyy-mm-dd hh:mm:ss.mmm

SELECT convert(varchar, getdate(), 126) -- yyyy-mm-ddThh:mm:ss.mmm
answered Aug 30 ’16 at 6:53

Is there a way to crack the password on an Excel VBA Project?

[Origin]: https://stackoverflow.com/questions/1026483/is-there-a-way-to-crack-the-password-on-an-excel-vba-project

I’ve been asked to update some Excel 2003 macros, but the VBA projects are password protected, and it seems there’s a lack of documentation… no-one knows the passwords.

Is there a way of removing or cracking the password on a VBA project?

You can try this direct VBA approach which doesn’t require HEX editing. It will work for any files (*.xls, *.xlsm, *.xlam …).

Tested and works on

Excel 2007
Excel 2010
Excel 2013 – 32 bit version.
Excel 2016 – 32 bit version.

Looking for 64 bit version? See https://stackoverflow.com/a/31005696/4342479

how it works

I will try my best to explain how it works – please excuse my english.

  1. The VBE will call a system function to create the password dialog box.
  2. If user enters the right password and click OK, this function returns 1. If user enters the wrong password or click Cancel, this function returns 0.
  3. After the dialog box is closed, the VBE checks the returned value of the system function
  4. if this value is 1, the VBE will “think” that the password is right, hence the locked VBA project will be opened.
  5. The code below swaps the memory of the original function used to display the password dialog with a user defined function that will always return 1 when being called.

using the code

  1. Open the file(s) that contain your locked VBA Projects
  2. Create a new xlsm file and store this code in Module1

    code credited to Siwtom (nick name), a Vietnamese developer
    
    Option Explicit
    
    Private Const PAGE_EXECUTE_READWRITE = &amp;H40
    
    Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
            (Destination As Long, Source As Long, ByVal Length As Long)
    
    Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Long, _
            ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long
    
    Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As Long
    
    Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
            ByVal lpProcName As String) As Long
    
    Private Declare Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" (ByVal hInstance As Long, _
            ByVal pTemplateName As Long, ByVal hWndParent As Long, _
            ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer
    
    Dim HookBytes(0 To 5) As Byte
    Dim OriginBytes(0 To 5) As Byte
    Dim pFunc As Long
    Dim Flag As Boolean
    
    Private Function GetPtr(ByVal Value As Long) As Long
        GetPtr = Value
    End Function
    
    Public Sub RecoverBytes()
        If Flag Then MoveMemory ByVal pFunc, ByVal VarPtr(OriginBytes(0)), 6
    End Sub
    
    Public Function Hook() As Boolean
        Dim TmpBytes(0 To 5) As Byte
        Dim p As Long
        Dim OriginProtect As Long
    
        Hook = False
    
        pFunc = GetProcAddress(GetModuleHandleA("user32.dll"), "DialogBoxParamA")
    
        If VirtualProtect(ByVal pFunc, 6, PAGE_EXECUTE_READWRITE, OriginProtect) &lt;&gt; 0 Then
    
            MoveMemory ByVal VarPtr(TmpBytes(0)), ByVal pFunc, 6
            If TmpBytes(0) &lt;&gt; &amp;H68 Then
    
                MoveMemory ByVal VarPtr(OriginBytes(0)), ByVal pFunc, 6
    
                p = GetPtr(AddressOf MyDialogBoxParam)
    
                HookBytes(0) = &amp;H68
                MoveMemory ByVal VarPtr(HookBytes(1)), ByVal VarPtr(p), 4
                HookBytes(5) = &amp;HC3
    
                MoveMemory ByVal pFunc, ByVal VarPtr(HookBytes(0)), 6
                Flag = True
                Hook = True
            End If
        End If
    End Function
    
    Private Function MyDialogBoxParam(ByVal hInstance As Long, _
            ByVal pTemplateName As Long, ByVal hWndParent As Long, _
            ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer
        If pTemplateName = 4070 Then
            MyDialogBoxParam = 1
        Else
            RecoverBytes
            MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _
                               hWndParent, lpDialogFunc, dwInitParam)
            Hook
        End If
    End Function
    

  3. Paste this code in Module2 and run it
    Sub unprotected()
        If Hook Then
            MsgBox "VBA Project is unprotected!", vbInformation, "*****"
        End If
    End Sub
    
  4. Come back to your VBA Projects and enjoy.

Sparse Matrix

[Origin]: http://btechsmartclass.com/DS/U1_T14.html

What is Sparse Matrix?

In computer programming, a matrix can be defined with a 2-dimensional array. Any array with ‘m’ columns and ‘n’ rows represents a mXn matrix. There may be a situation in which a matrix contains more number of ZERO values than NON-ZERO values. Such matrix is known as sparse matrix.

Sparse matrix is a matrix which contains very few non-zero elements.

When a sparse matrix is represented with 2-dimensional array, we waste lot of space to represent that matrix. For example, consider a matrix of size 100 X 100 containing only 10 non-zero elements. In this matrix, only 10 spaces are filled with non-zero values and remaining spaces of matrix are filled with zero. That means, totally we allocate 100 X 100 X 2 = 20000 bytes of space to store this integer matrix. And to access these 10 non-zero elements we have to make scanning for 10000 times.

Sparse Matrix Representations

A sparse matrix can be represented by using TWO representations, those are as follows…

  1. Triplet Representation
  2. Linked Representation

Triplet Representation

In this representation, we consider only non-zero values along with their row and column index values. In this representation, the 0th row stores total rows, total columns and total non-zero values in the matrix.

For example, consider a matrix of size 5 X 6 containing 6 number of non-zero values. This matrix can be represented as shown in the image…

In above example matrix, there are only 6 non-zero elements ( those are 9, 8, 4, 2, 5 & 2) and matrix size is 5 X 6. We represent this matrix as shown in the above image. Here the first row in the right side table is filled with values 5, 6 & 6 which indicates that it is a sparse matrix with 5 rows, 6 columns & 6 non-zero values. Second row is filled with 0, 4, & 9 which indicates the value in the matrix at 0th row, 4th column is 9. In the same way the remaining non-zero values also follows the similar pattern.

Linked Representation

In linked representation, we use linked list data structure to represent a sparse matrix. In this linked list, we use two different nodes namely header nodeand element node. Header node consists of three fields and element node consists of five fields as shown in the image…

Consider the above same sparse matrix used in the Triplet representation. This sparse matrix can be represented using linked representation as shown in the below image…

In above representation, H0, H1,…,H5 indicates the header nodes which are used to represent indexes. Remaining nodes are used to represent non-zero elements in the matrix, except the very first node which is used to represent abstract information of the sparse matrix (i.e., It is a matrix of 5 X 6 with 6 non-zero elements).

In this representation, in each row and column, the last node right field points to it’s respective header node.

Arrays

[Origin]: http://btechsmartclass.com/DS/U1_T13.html

What is an Array?

Whenever we want to work with large number of data values, we need to use that much number of different variables. As the number of variables are increasing, complexity of the program also increases and programmers get confused with the variable names. There may be situations in which we need to work with large number of similar data values. To make this work more easy, C programming language provides a concept called “Array”.

An array is a variable which can store multiple values of same data type at a time.

An array can also be defined as follows…

“Collection of similar data items stored in continuous memory locations with single name”.

To understand the concept of arrays, consider the following example declaration.

int a, b, c;

Here, the compiler allocates 2 bytes of memory with name ‘a’, another 2 bytes of memory with name ‘b’ and more 2 bytes with name ‘c’. These three memory locations are may be in sequence or may not be in sequence. Here these individual variables can store only one value at a time.

Now consider the following declaration…

int a[3];

Here, the compiler allocates total 6 bytes of continuous memory locations with single name ‘a’. But allows to store three different integer values (each in 2 bytes of memory) at a time. And memory is organized as follows…

That means all these three memory locations are named as ‘a’. But “how can we refer individual elements?” is the big question. Answer for this question is, compiler not only allocates memory, but also assigns a numerical value to each individual element of an array. This numerical value is called as “Index”. Index values for the above example are as follows…

The individual elements of an array are identified using the combination of ‘name’ and ‘index’ as follows…

arrayName[indexValue]

For the above example the individual elements can be referred to as follows…

If I want to assign a value to any of these memory locations (array elements), we can assign as follows…

a[1] = 100;

The result will be as follows…


There are different types of arrays in c programming language. Click on the below link to read TYPES OF ARRAYS