CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    Windows 7 Gadget Programming with Javascript or JScript?

    Hello guys,
    With this windows 7 gadget, I need access to a local file (binary)
    in order to calculate something and output some outcomes.
    I wonder how I can access file using javascript, I've gone over
    a lot of articles that javascript is restricted by a sandbox.
    Are there any good ways that I can read the data out of a local file?
    BTW, is it also possible to access an embedded database with a gadget?
    Thanks a lot, have a nice day!
    Jack
    Last edited by lucky6969b; March 23rd, 2014 at 12:25 AM.

  2. #2
    Join Date
    Dec 2010
    Posts
    907

    Re: Windows 7 Gadget Programming with Javascript or JScript?

    When I pack it up into a .gadget file and loaded into the sidebar (3rd party tool) of windows 7.
    I can see "Hello World" to appear. But no alert boxes came up. Why?
    The html page is displayed correctly in IE10.
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
    	    <title>Hello World</title>
    	    <style type="text/css">
    		    body
    		    {
    		        margin: 0;
    		        width: 130px;
    		        height: 75px;
                    font-family: verdana;
                    font-weight: bold;
                    font-size: small;
    		    }
    		    #gadgetContent
    		    {
    		        margin-top: 20px;
    		        width: 130px;
    		        vertical-align: middle;
    		        text-align: center;
                    overflow: hidden;
    		    }
    	    </style>
    	    <script type="text/jscript" language="jscript">
    
    			var fileName = "D:/money.dat";
    		
    			// --------------------------------------------------------------------
    			// Initialize the gadget.
    			// --------------------------------------------------------------------
    			function init()
    			{			    
    				 getDat();
    				 display();
    			}
    			
    			function getDat() 
    			{
    				var fso, f1;
    				fso = new ActiveXObject("Scripting.FileSystemObject");
    				try
    				{
    				   
    					ts = fso.OpenTextFile(fileName, 1, false, 0);
    					var name = "Jacky";
    					s = ts.Read(10);
    					alert(name);
    					alert(s);
    					
    				}
    				catch(e)
    				{
    					System.Debug.outputString(e);
    				}
    			}
    
                            functon display() {
                            }
    	    </script>
        </head>
    	
    <body onload="init()">
        <g:background id="imgBackground">
    	<span id="gadgetContent">Hello World!</span>
    	</g:background>
    </body>
    </html>
    Last edited by lucky6969b; March 23rd, 2014 at 01:02 AM.

  3. #3
    Join Date
    Jun 2009
    Posts
    113

    Re: Windows 7 Gadget Programming with Javascript or JScript?

    Alerts are disabled in Gadgets: http://msdn.microsoft.com/en-us/maga...63370.aspx#S10
    Mind you, Gadgets have been discontinued ( http://windows.microsoft.com/en-gb/windows/gadgets ) so you won't be able to use them beyond Windows 7.

  4. #4
    Join Date
    Jun 2009
    Posts
    113

    Re: Windows 7 Gadget Programming with Javascript or JScript?

    Having a quick play with this, assuming you're reading the first line from your .DAT file, this script section should work:
    Code:
    <script type="text/jscript" language="jscript">
    var filename = "D:\\Money.dat";
    function init(){
    	var updater = setInterval(readfile, 5000);
    }
    function readfile(){
    	var fso, f;
    	var ForReading = 1, ForWriting = 2;
       	fso = new ActiveXObject("Scripting.FileSystemObject");
       	f = fso.OpenTextFile(filename, ForReading);
      	document.getElementById("gadgetContent").innerHTML=f.ReadLine();
    	f.Close();
    }
    </script>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured