Tuesday, December 18, 2012

Get Textbox or RichtextBox value using pInvoke (Windows API)

Assuming you already get the pointer handle of the textbox/richtextbox control from source calling function, the snippet to get the content of the edit control is as follows.
Code:
public const int GWL_ID = -12;  
 public const int WM_GETTEXT = 0x000D;  
 [DllImport("User32.dll")]  
 public static extern int GetWindowLong(IntPtr hWnd, int index);  
 [DllImport("User32.dll")]  
 public static extern IntPtr SendDlgItemMessage(IntPtr hWnd, int IDDlgItem, int uMsg, int nMaxCount, StringBuilder lpString);  
 [DllImport("User32.dll")]  
 public static extern IntPtr GetParent(IntPtr hWnd);  
 private StringBuilder GetRichEditText(IntPtr hWndRichEdit)  
 {  
   Int32 dwID = GetWindowLong(hWndRichEdit, GWL_ID);  
   IntPtr hWndParent = GetParent(hWndRichEdit);  
   StringBuilder title = new StringBuilder(128);  
   SendDlgItemMessage(hWndParent, dwID,  
     WM_GETTEXT,  
     128, title);  
   return title;  
 } 
For labels and buttons, you use the GetWindowText() function... :)

Greg

Sunday, December 16, 2012

WPF Webbrowser loop through html elements and submit

A question was raised on vbforums on how to invoke click a button using WPF webbrowser control. This sample loads google.com page and writes a sample text on the textbox and then invoking the click button.
Code:
 HTMLDocument document = (HTMLDocument)wbGetHost.Document;  
       foreach (IHTMLElement myelem in document.getElementsByTagName("input"))  
       {  
         if (myelem.id != null)  
         {  
           if (myelem.id.Equals("lst-ib") && myelem.className.Equals("lst lst-tbb") && !document.documentElement.innerHTML.ToLower().Contains("wikipedia"))  
           {  
             HTMLInputElement el = myelem as HTMLInputElement;  
             el.value = "Bill Gates";  
             HTMLInputElement searchButton = (HTMLInputElement)document.all.item("btnK", 0);  
             searchButton.click();  
             break;  
           }  
         }  
       } 
Greg

Thursday, December 6, 2012

The controller for path /favicon.ico does not implement IController

In an application using Controller factory, i encountered an error as stated in the title. My MVC does not have a favicon.ico. The solution is to add a parameter constraint that does not allow .ico filenames in your routes. I got the solution from forums.asp.net
Code:
 routes.MapRoute(  
           "Default",                       // Route name  
           "{controller}/{action}/{id}",              // URL with parameters  
           new { controller = "ProductView", action = "Index", id = "" }, // Parameter defaults  
           new { controller = @"[^\.]*" }    // Parameter constraints (regex/string expression)  
         ); 

Wednesday, December 5, 2012

Count duplicate or repeating records from union all query

Here's a query to count number of repeating records based from union all query. Union all query does not remove duplicate records. Here's a sample script:
1:  select resultsduplicate.url as job_item,  
2:  count(resultsduplicate.url) as repeat_occurence  
3:  from  
4:  (  
5:    SELECT url FROM mainTable  
6:     where id = 47 and url like '%testsite.com%' and _active = 1  
7:    UNION ALL  
8:    SELECT url FROM detailTable  
9:     where id = 47 and url like '%testsite.com%' and _active = 1  
10:  )resultsduplicate   
11:  group by resultsduplicate.url  
12:  having (count(resultsduplicate.url) >1);  
Original Source (Stackoverflow.com) Cheers!

Tuesday, December 4, 2012

Content Types/MIME Types List in ASP.NET(MVC)

I have searched for content types which is suitable for asp.net or asp.net mvc applications using the HttpResponse class ContentType property.

Here's the website with the MIME list: Mime Type List

Here's a sample asp.net/mvc snippet.
Code:
HttpResponseBase response = context.HttpContext.Response;  
response.ContentType = "application/pdf";  

Greg

Sunday, December 2, 2012

Codeformatter

Code formatter with line numbers...

http://codeformatter.blogspot.com/