Chitika

Thursday, February 23, 2012

javascript send message to child window from parent window

Parent Window

function ProcessMsgParent(msg) {
.
.
.
}


// open child window
var win = window.open(...);

// send message to child window
win.ProcessMsgChild(msg_to_child);

Child Window

function ProcessMsgChild(msg) {
.
.
.

}

// send message to parent window
window.opener.ProcessMsgParent(msg);

Monday, February 6, 2012

C# Printing



private PrintDocument doc = null;

.
.
.
 doc = new PrintDocument();
 PrintController printController = new StandardPrintController();
 doc.PrintController = printController;
 doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
.
.
.
doc.Print();
.
.
.
private void doc_PrintPage(object sender, PrintPageEventArgs e)
{
            try
            {
                  Graphics gfxObj = e.Graphics;
                   // for upside down printing
                  graphics.RotateTransform(180.0F);
                   // graphics operations
                  .

                  .
                  .
            }
            catch
            {
            }
            finally
            {
            }
}

Thursday, February 2, 2012

VC++ DLL

DLL:

Create new Win32DLL project, say dllProj.

In header file define:

#ifdef PROJ_EXPORTS
#define PROJ_API __declspec(dllexport)
#else
#define PROJ_API __declspec(dllimport)
#endif

Add functions in header files with PROJ_API prefix and definitions in source file with PROJ_API prefix.

PROJ_API  int foo();

Usage:

Create new Win32Console project.

define:

Top define:
extern int foo();

In function, call:
a=foo();

right click project, click Reference..., Common Properties, Frameworks and References, Add New Reference, Select dllProj project.

compile and run :)

Dotnet Usage:

Using command like linux "strings", read the function signature in the dll, which would be like ?foo@@YAHPAD@Z.

In c#, declare as:

[DllImport("dllProj.dll", CharSet = CharSet.Ansi, EntryPoint = "?foo@@YAHPAD@Z")]
private static extern int foo(string port);

Now, use it in the class as normal static function.