Tuesday, November 8, 2011

ssEditBox

Since textbox can only hold a limited maximum number of characters and will hide some entries from our eyes if it goes beyond the textbox's current width, then for longer entries we normally use an editbox. However, one thing that I don't like about editboxes is those "eat" space and sometimes it is harder to design the appearance of our forms because we have to give allowance to those.  See image below:


Solution?  Create a dropdown editbox.


This class I called ssEditBox is designed to cater for longer entries that normally requires an editbox. This class appears like an ordinary textbox and consumes space on the form much like an ordinary textbox as well.  The difference is that this can handle longer entries as once the textbox reached the nMaxChar property value (default is 15 characters) then the dropdown editbox will appear and focus will be transferred there so you can continue typing as if you really are typing there in the first place.

You may want to change the value of nMaxChar property other than 15 characters if you have resized the class (made it wider or narrower) so you can estimate the number of characters user will type before it reaches the end of the current textbox width and make it appear that suddenly the dropdown edit box will popup.

Aside from letting the class reach the nMaxChar property for dropdown editbox to appear, you can likewise force the dropdown portion to appear "any time" via pressing down arrow when the class has the focus.  Hiding it back is done either via pressing Esc key, up arrow key or when you click outside of the dropdown editbox.

By default, the dropdown editbox is wider than the textbox.  But when you drag the right edge of the class making it wider than the dropdown editbox portion, the class will auto-compensate adjusting the dropdown portion to be of equal width with the textbox portion.

So there you are, again a very simple yet unique and appealing new class added to the list of growing ssclasses family.

Enjoy!

ssGridLock

I never liked horizontal scrolling capabilities of grids because I wanted everything to be seen outright without the need to scroll.  So I never used grid column locking before and most of my classes that deals with grids is designed without horizontal scrollbar in mind like ssAnchorSizer.

But, taste and need changes and in one of my modules I am forced to put a grid where some columns are hidden and the need to scroll horizontally cannot be avoided.  And since I don't want to guess "where" I am when I scroll to the right, I need to lock columns on the left.  And with that need arises ssGridLock class.





Using it is very easy like my ssGridSorter class.  Just bind the grid you wanted to attach to that column locking capability like this (on class Init event):

This._GridName = "Grid1"

By default, it will lock the 1st column of the grid but you can adjust it to initially show more than one column locked also via init event like this:

This.Value = 2  && locks 2 columns initially

Or via its value property on the PEM window.

This class will create a lock image on the column of your grid so you will know which column is currently locked.

And since it is included with a spinner, you can change locking dynamically on run by changing the spinner value up or down or by manually keying in the  number of columns to be locked.

Like my other grid classes, the class and the grid should be on the same container.  So a grid in the form must have that class on the form as well.  If the grid is inside a container object, then the class should also be inside that container.  If the grid is inside a page, the class should also be in that same page.

Monday, October 24, 2011

Convert external document files to PDF via ShellExecute()

Originally posted in www.junblogs.com

The easiest way to convert a report into a pdf file is via using a pdfprinter.  There are lots of pdf printers outside there which you can use.  You can check these sites:

to name a few.  Converting the report is as easy as these:

SET PRINTER TO NAME('PrimoPDF') && or something like that or a variable that contains the name of the PDF printer

REPORT FORM YourReport TO PRINTER NOCONSOLE


SET PRINTER TO DEFAULT && This is essential to instruct VFP to return back to its default printer

Friday, October 21, 2011

IEXPLORE.EXE virus Manual Removal


This is actually an old infection and this can be easily killed so I ignored sharing this one before.  However, some units here in our office has been again infected by this virus that is why I have to manually kill those again as our antivirus seems to not recognize this one.

What is IEXPLORE.EXE?

This is actually the executable filename of Microsoft Internet Explorer.  But since some virus propagator decides to be a little naughty, they named the process the same name.  If I am creating a virus, I might name a virus with a certain Microsoft processes as well so it can fool a lot of people thinking it is legal.

Since this virus has the same processes’ name with that of Internet Explorer, how will we know if what you are seeing in the Task Manager is the virus or the real Internet Explorer?  Simple, if there is no open Internet Explorer, then it is a virus.  If there is an open Internet Explorer, close it. After closing Internet Explorer and there still is an instance of IEXPLORE.EXE, then that is a virus.

What does this virus do?

Wednesday, October 19, 2011

Auto Run your exe on OS logon

While we are at it (Your exe and nothing else), I want to show now here the ways to make your exe sort of auto run during logon, the places where we can do that and the advantages and disadvantages if any.

There are 3 common places I would choose to ensure that my exe will auto-load so users will no longer need to double-click it when they open their computer unit.  I will start the sequence from the first to the last:

a.  Startup folder - this is the very first instance that the OS will load or try to run anything.  You can put the shortcut of your exe here.  Click Start button, All Programs (or simply Programs), then Startup folder.  Right-click it and choose Explore.  Paste your exe shortcut here. 

As I said, the OS will try to run "first" what is here before the other ways I will show below and this is a sort of advantage.  Its disadvantage is a user can delete that shortcut later removing that auto-run(load) effect you want your exe to have.

b.  You can create an entry inside registry in this:

Your exe and nothing else

Most POS developers says to themselves "Oooo!  I want to hide task bar and start button so users can not switch to other exe while using my POS system.  I also want to hide this, disable this and kill this, etc."  Although in reality most developers do not really say "Oooo!" and instead use stronger words but that is the way I want to paint that expression here for fun, LOL!

So they find ways to do that and of course those are always possible via playing with registry settings or in some cases via WinAPIs.

However, why go into the trouble of doing all those things when there is simpler and easier way to achieve that?  Is it possible to make your exe the only thing running and nothing else?  Sure.

A normal windows OS uses Explorer.exe as its shell.  There are other more 3rd party shells out there in the net and I tried some before but because of familiarity with Explorer, I always go back to the default.  What is a shell?

Shell, briefly explained:

A shell is a piece of software that provides an interface for users of an operating system which provides access to the services of a kernel.   Its primary purpose is to invoke or "launch" another program; however, shells frequently have additional capabilities such as viewing the contents of directories. - wiki

So what has an OS shell go to do with what I am trying to say here?  When you use Explorer.exe as shell, then it will load the taskbar, it will load the desktop, it will load a lot of everything.... which in the end you wanted to kill or disable later anyway.  So why go into the trouble of disabling, hiding, or killing those things later..... when we can simply prevent those to be loaded in the first place?

What I am trying to say is use your exe as the OS shell so that is the only thing that will be loaded.... and nothing else.  Below is a simple snippet to do that.  I used scripting here but if you are not comfortable with it, you can use registry.prg that is shipped with VFP (HOME()+"samples\classes\registry.prg"):




**********************
* ShellSwitcher.prg
* Author: Jun Tangunan, October 19, 2011
**********************
Local oForm As Form
oForm = Createobject('ShellForm')
oForm.Show(1)
Return

Define Class ShellForm As Form
      AutoCenter = .T.
      Height = 100
      Width = 300
      Caption = "Sandstorm's Shell Switcher"
      MinButton = .F.
      MaxButton = .F.
      BorderStyle = 1

      Add Object label1 As Label With;
            top=35, Left= 10, Caption = "Please Select what Shell to use later",;
            AutoSize = .T., FontBold = .T.

      Add Object opgshell As OptionGroup With ;
            top = 50, Left = 10, ButtonCount = 2, Value = 1, ;
            AutoSize = .T., BorderStyle = 0

      Add Object cmdgo As CommandButton With;
            top=60, Left= 165, Caption = "Apply", Width = 100, Height = 30


      Procedure Init
            With Thisform.opgshell
                  .option1.Caption = "Explorer (Default)"
                  .option1.AutoSize = .T.
                  .option2.Caption = "This System"
                  .option2.AutoSize = .T.
            Endwith

      Function cmdgo.Click
            If Messagebox("Proceed?",4+32,"Switch Shell") = 6
                  Local loWSH As wscript.Shell
                  loWSH = Createobject("wscript.shell")
                  loWSH.RegWrite(;
                        "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell",;
                        Iif(Thisform.opgshell.Value=1,"Explorer.exe",;
                        "< your exe with full path >"))
                  Messagebox("A log off is necessary, click ok to log off now!",;
                        0+64,"System Restart Needed!")
                  loWSH.Run("CMD /C LOGOFF",2,.T.)
                  Thisform.Release
                  Return
            Else
                  Messagebox("Shell switching is aborted!",0+64,"Oppppssss!")
            Endif
      Endfunc

Enddefine


Here are some more things you need to know to be able to use this:
  1. You should be a member of an Administrator Account because it deals with tampering values of Local Machine in Registry 
  2. I have not killed Task Manager here so once you have tested your exe to be the Shell and would want to go back to the OS default (Explorer.exe), then you can press Ctrl+Alt+Del keys to active Task Manager, run Explorer.Exe, go to where this code snippet is, run it again and switch back to Explorer as the Shell.
 Tested under WindowsXP SP2.

You can incorporate the above codes as part of your project so that you can switch shells from within your exe without invoking the task manager. And once you are comfortable with it, then you can either proceed with disabling the task manager as well so it will really be your exe and nothing else.....


Enjoy!

Wednesday, October 12, 2011

Selectively Close Open files in Server

A question is raised recently in Foxite Forum on how to avoid an error during backup creation if a table is left open by users.  My suggestion is to use Computer Management Console in the server itself either by logging directly onto the server unit or remote controlling it via remote desktop:


However, that is the manual way of doing it.  A fellow foxiter named Yahia Aboudalal said he is using this command to close those files, i.e., OpenFiles.  That is great because I am not even aware that such command exists, LOL!

Anyway, this will need to know the ID of the open files so we can selectively close those.  Like in our office here, some engineers stays well beyond 5PM so I would not want to execute something that will suddenly close their files as well, won't we?  So here is a simple snippet I prepared today to test on our server.  The purpose is to selectively close only the files my app is using:


Create Cursor junkopen (xID I, xuser c(10), xsystem c(10), xfiles c(100))


Local oShell As wscript.Shell, lcTempFile
lcTempFile = Addbs(Getenv("TMP"))+Sys(3)+".txt"
oShell = Createobject("WScript.Shell")

* create a CSV list of open files in server
oShell.Run("cmd /c openfiles /query /S < your server name >"+;
      "/U administrator /FO CSV /NH > "+m.lcTempFile,2,.T.)

* Clean it up, remove those warnings above the list
Strtofile(Strextract(Filetostr(m.lcTempFile),;
      "again.."),(m.lcTempFile))

* add records to our cursor
Append From (m.lcTempFile) Type Csv

* Clean it up
Select xfiles, xID From junkopen Where ;
      INLIST(Upper(Justext(xfiles)),"DBF","CDX","APP","FPT") ;
      AND !Empty(Justext(xfiles)) Into Cursor junkopen

* Start closing remaining files on the list
Scan
      Wait Window "Attempting to close "+;
            ALLTRIM(junkopen.xfiles) Nowait
      oShell.Run("CMD /C OPENFILES /DISCONNECT /S "+;
            "< your server name > /ID "+Transform(junkopen.xID),2,.T.)
Endscan

Messagebox("Target Open Files has been closed!")

* Perform your backup routine




And as usual if I believe this will benefit others, then I post it here in my blog than inside the forum so it won't be lost easily.