Archive for July, 2008

h1

Jak zabranit zbytecnemu mergovani v TFS?

July 28, 2008

Řekněme,že máme situaci, kdy pět lidí naráz pracuje s projektem Services. Všichni si stáhli latest version brzo ráno, když přišli do práce. Každý z nich upravuje orchestrace a přidává vlastní orchestrace do složky App_Code. K čemu dojde? První uživatel checkne svůj projekt bez problémů. Druhý už ale musí mergovat, protože zatímco pracoval, nevěděl nic o změnách , které provedl první uživatel. Třetí checkující v pořadí dělá to samé, ale se změnami prvních dvou.

Mergování je nepříjemná věc. Jak tomu zabránit? Stačilo by, kdyby se do souboru Services.csproj zapsalo namísto kompilování jednotlivých servis tohle:

 <Compile Include=”App_Code\**\*.cs”/>

To znamená, že uživatelé budou checkovat jen přidané orchestrace, ale nemusejí už checkovat a mergovat soubor .csproj. Tím se zjednodušší práce a zjednodušší čitelnost souboru .csproj. Tag nám totiž říká kompiluj všechny .cs soubory. Pokud tedy nemáme důvod nekompilovat vše, můžeme použít postup s kompilováním všech *.cs souborů a namísto mergování Services.csproj dáme jen undo changes.

h1

Informace o oběktech na obrazovce: Object Spy

July 27, 2008

Z SourceForge lze stáhnout prima utilitku – ObjectSpy. Utilitka vrací kolekci properties (včetně handlu) objektů na obrazovce.

  • Důvod proč ObjectSpy používám: Při opravě bugů na UI. Když opravuji bugy po jiných programátorech občas netuším, v jaké třídě se UserControl / Panel / Form nachází. Jediné co vím, je obrazovka, s chybou, kterou mi ukáže tester. V projektu jsou různých formulářů stovky. Ano na vnadě je správná architektura atd… Ale v konkrétní situaci projekt vypadá zmateně a chyby se musejí řešit.  ObjectSpy je záchrana. Pouhým kliknutím a přetažením kurzoru na control ( ikona, formulář, panel tlačítko…. ) získám jeho informace, včetně jména, které si potom můžu v Sulutioně vyhledat.
    v ObjectSpy lze také nastavovat property. To znamená, ušetřený čas při testování (např přizměnách pozadí formulářů atd…)

Reference

h1

Capturing active window

July 27, 2008

Sometimes you need to capture active window, there is a solution. Following code shows you, how to capture it.  I will make two classes, which imports external code from user32.dll and gdi32.dll.  (Windows API , etc..)

Attention: It captures active window. So if you want to capture any other window, it will not work. For example: if you call this code from click to Notify icon, it captures Notify bar (exactly it captures blank screen.).

User32Helper

public class User32Helper
{
[StructLayout(LayoutKind.Sequential)]
public struct
RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern int GetActiveWindow();
[DllImport("user32.dll")]
public static extern int GetTopWindow(int hWnd);
[DllImport("user32.dll")]
public static extern int GetNextWindow(IntPtr hWnd, int wCmd);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("User32.dll")]
public static extern int GetDesktopWindow();
[DllImport("User32.dll")]
public static extern int GetWindowDC(int hWnd);
[DllImport("User32.dll")]
public static extern int ReleaseDC(int hWnd, int hDC);

 

 

 //keyboard
[DllImport("user32")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, intdwExtraInfo);
public const byte VK_MENU = 0×12;
public const byte VK_TAB = 0×09;
public const int KEYEVENTF_EXTENDEDKEY = 0×01;
public const int KEYEVENTF_KEYUP = 0×02;
public const int GW_HWNDPREV = 0×03;
}

GDI32Helper

class GDI32Helper
{
[DllImport("GDI32.dll")]
public static extern bool BitBlt(int hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, int hdcSrc, int nXSrc, int nYSrc, int dwRop);
[DllImport("GDI32.dll")]
public static extern int CreateCompatibleBitmap(int hdc, int nWidth, int nHeight);
[DllImport("GDI32.dll")]
public static extern int CreateCompatibleDC(int hdc);
[DllImport("GDI32.dll")]
public static extern bool DeleteDC(int hdc);
[DllImport("GDI32.dll")]
public static extern bool DeleteObject(int hObject);
[DllImport("GDI32.dll")]
public static extern int GetDeviceCaps(int hdc, int nIndex);
[DllImport("GDI32.dll")]
public static extern int SelectObject(int hdc, int hgdiobj);
}

 

 

Capturing active window

/// <summary>
///
Captures the active window.
///
</summary>
/// <returns></returns>

public static Bitmap CaptureActiveWindow()
{
User32Proxy.RECT rect;
int desktop = (int)User32Helper.GetForegroundWindow();
int hdcSrc = User32Helper.GetWindowDC(desktop);
int hdcDest = GDI32Helper.CreateCompatibleDC(hdcSrc);
User32Proxy.GetWindowRect(new IntPtr(desktop), out rect);
int hBitmap = GDI32Helper.CreateCompatibleBitmap(hdcSrc, rect.Right – rect.Left, rect.Bottom – rect.Top);
GDI32Helper.BitBlt(hdcDest, 0, 0, rect.Right – rect.Left, rect.Bottom – rect.Top, hdcSrc, 0, 0, 0×00CC0020);
return Image.FromHbitmap(new IntPtr(hBitmap));
}

 

 

References

 

 

 

References

 

 

h1

Capturing Image

July 27, 2008

In this article I will show how to capture Area from screen to Image.

/// <summary>
/// Captures the screen.
/// </summary>
/// <returns></returns>
public static Bitmap CaptureIamge(Point location , Size size)
{
    Bitmap bitmap = new Bitmap(size.Width, size.Height);
    Graphics g = Graphics.FromImage(bitmap);
    //druhy parametr rika, na jakou pozici se to ma do ciloveho obrazku nahrat
     g.CopyFromScreen(location,new Point(0,0), size,   CopyPixelOperation.SourceCopy);
    return bitmap;
}

 

References

h1

Capturing screen

July 27, 2008

Sometimes we must capture window to Bitmap. This easy method will provide this funcionality.

 

/// <summary>
///
Captures the screen.
///
</summary>
///
<returns></returns>
public static Bitmap CaptureScreen()
{
Bitmap bmpScreenshot;
Graphics gfxScreenshot;
// Set the bitmap object to the size of the screen
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); 
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
return bmpScreenshot;
}

h1

Sending Email via Outlook with picture attachment

July 20, 2008

You have many ways how to send email from client in .NET

  • You can use standard .NET API and send email via your mail server.
    Disadvantages are, that each client must have  configured  SMTP, and you could not use your mail client interface.
  • You can use HTML mailto command in any component. When you activate it, it opens  your mail client and you can send an email.
    Disadvantages are, that clients are very various. You should never know which client does user use. Than it is very hard to pregenerate content of mail item. Especially add attachment is difficult.
  • You can use standard Email client interop. (In our case Outlook 2003 interop)
    Disadvantages are, that user must have installed outlook 2003. It is very good solution for internal software inside  of companies, that use outlook client globally. It is easy to work with attachments there.

I have been inspirate from this great article of Keith Elder. I am using same class Email from this article to show you , how to send email with picture attachment.

private void SendEmail(string attachmentFileName, string message)
{
  try
  {
          string dir = System.IO.Directory.GetCurrentDirectory();
          string path = string.Format(@"{0}\{1}", dir, attachmentFileName);
          EmailProxy outlookEmail = new EmailProxy();
          outlookEmail.Message.BodyFormat = OlBodyFormat.olFormatHTML;
          outlookEmail.Message.Importance = OlImportance.olImportanceNormal;
          outlookEmail.Message.Subject = string.Format("PT: {0}", DateTime.Now.ToString("yyyyMMddHHmmss"));
          outlookEmail.Message.Attachments.Add(path, OlAttachmentType.olByValue, 1, attachmentFileName);
         
          outlookEmail.Message.HTMLBody = string.Format(
            @"<html><table border='0'><tr><td height='30'>{0}</td></tr><tr><td></td></tr><tr><td>"
           +"<img align='middle' src='{1}'/></td></tr>",message.Replace("\n","</p>"), attachmentFileName);
           outlookEmail.Message.HTMLBody +=  @"</table></html>"
           outlookEmail.Show();
     }catch (Exception ex){ Trace.WriteLine(ex.Message); }
}

 

References

 

 

h1

Cell-phones and Microwaves

July 20, 2008

Cell-phone  in Microwave

10 / 10 za aliena v mikrovlnce

Microwave from cell-phones

h1

Developers, developers, developers, developers

July 20, 2008