How to extract default file icon in WPF application


In Windows every file has default icon, and it is shown in Windows Explorer while browsing files on disk. If you want to grab this icon in WPF application there are several ways. One of the solution is by using ExtractAssociatedIcon from Icon class located in System.Drawing namespace.

The following code shows how to extract default icon from the file specified by file name:

var sysicon = System.Drawing.Icon.ExtractAssociatedIcon(filePath);
var bmpSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
            sysicon.Handle,
            System.Windows.Int32Rect.Empty,
            System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
sysicon.Dispose();

Explanation of the code above is straightforward.First we need file path, then we need to call Icon.ExtractAssociatedIcon(filePath) to get Icon object. From the icon object we can create BitmapSource which can be show everywhere in the WPF application.

 

Complete source code demo can be found .

Analitička geometrija i C# programiranje dio 3/n


Problem 3 i 4: Pripadnost tačke kružnici ili pravilnom poligonu

 

 

 

Implementacija problema pripadnosti tačke u kružnici je vrlo prosta i zahtjeva samo provjeru da li je dužina centra kružnice do posmatrane tačke manja ili jednaka radijusu kružnice. Implementacija se može napisati na sljedeci način:

/// <summary>
/// provjerava da i se tačka nalazi u kružnici
/// </summary>
/// <param name="a">koordinate tačke </param>
/// <param name="o1">koordinate centra kružnice</param>
/// <param name="radius">radijus kružnica</param>
/// <returns></returns>
bool isInCircle(Point a, Point o1, float radius)
{
    float length = (float)Math.Sqrt((a.x - o1.x) * (a.x - o1.x) + (a.y - o1.y) * (a.y - o1.y));

    if (radius >= length)
        return true;
    else
        return false;
}

Implementacija problema tačke u pravilnom poligonu je malo komplikovanija, a bazira se na činjenici da u koliko je tačka unutar poligona, tada tačka mora biti sa desne strane svih njegovih stranica, u koliko se stranica obilaze u smjeru kretanja kazaljke na satu. Implementacija izgleda kao na sljedećem listingu:

/// <summary>
/// vraća true ako se tačka A nalazi u poligonu
/// </summary>
/// <param name="a"></param>
/// <param name="o1">centar poligona</param>
/// <param name="polyedges">tačke tjemena poligona poredane u smjeru kretanja kazaljke na satu.</param>
/// <returns></returns>
bool isInPolygon(Point a, Point o1, Point[]polyedges)
{
    for (int i = 0; i < polyedges.Length; i++)
    {
        int j = i++;
        if (j == polyedges.Length)
            j = 0;
        if (isOnRightSide(a, polyedges[i], polyedges[j])==-1)
            return false;
    }
    return true;
}

Iz zadnjeg listinga vidimo da smo koristili metodu isOnRightSide iz prethodnog posta.

Configuring Visual Studio 2013 to use Git as Source Control


Visual Studio 2013 has ability to integrate Git source control. The blog post will shows in details how to configure Visual Studio to use Git, with remote repository at git.com. Configuration can be divided in several parts.

1. Installing required softwares

2. Creating SSH key and uploading to Git server

3. Configuring local Git repository and sync with remote server

4. Check in and check out source code.

Installing Git Extensions

Only software you have to install is Git Extensions for Windows which you can find on: 

1. After you download Git Extension installer, start the installation process. The following images show  step during the installation process.




At this step,in some case you can get the error in the installation with the following message:

‘Installation directory must be on local hard drive’

In that case, open Command Prompt with Administrator priviledge, go to folder GitInstaller is downloaded and type the following command:

msiexec /i GitExtensions.msi WIXUI_DONTVALIDATEPATH=”1″ 

where GitExtension.msi is the name of your installer.

Continue with installation:



Now proceed with installation of two installers: KDiff and GIT. Follow the default setup options:

Finish the installation process:

 

Creating SSH key and uploading to Git server

After you installed Git Extension open the Git Extention from Desktop :

Put UserName and Email to login information:

 

By clicking on OK button, Git Extension displays start screen. From Tools menu choose  Git Bash command line tool to create SSH key.

 

 

From the picture below follow the instruction how to create SSH Key.

type: ssh-keygen -t rsa -C [email protected], and press enter 4 times. By pressing Enter you accept default options.

 

After you create the key, you have to add it to local agent.

1. First start local agent: exec ssh-agent Bash   (eval `ssh-agent -s`)

2. Type ssh-add ~/.ssh/id_rsa

Add SSH key to GitHub

1. Open you Git Hub account

2. Go to Settings

3. Add SSH Tab

4. Press AddKey

5. Copy the Content of the id_rsa.pub (see picture below)

 

6. Paste to GitHub SSH key tab

You can test your account by typing ssh-T [email protected] to command line.

Now you are ready to use GitHub Source control.

Configuring local Git repository and sync with remote server

 

1. Define local repository path: C:/tfs/Git

2. Open GitExtensions: Open local repository:

 

2. Initialize local repository

 

 

Setup Remote Repository by specifing Name and SSH path of the project:

 

By pressing Save Changes from the last image, you setp the project and it is ready to be opened in Visula Studio.

Open Visual Studio 2013

Add local repository to Git

Double click on the project to get solution file to open:

Analitička geometrija i C# programiranje dio 2/n


U prethodnom dijelu smo dali osnovne teorijske osnove za implementaciju problema analitičke geometrije.

Problem 2: Pripadnost tačke kružnom segmentu?


Posmatrajmo gornju sliku na kojoj imamo kružni isječak, iz kojeg su povučene zrake z1 i z2. Pretpostavimo također da imamo tačku A koja se nalazi u kružnom isječku, dok tačka B se nalazi izvan isječka. Da bi odredili pripadnost tačke kružnom isječku potrebno je provjeriti sljedeće:

1. da se tačka nalazi s desne strane zrake z1

2. da se tačka nalazi sa lijeve strane zrake z2

3. da je dužina iz centra isječka do tačke A manja ili jednaka od radijusa kružnog isječka.

U koliko su sva tri uslova ispunjena, tada se tačka nalazi u kružnom isječku.

Kako smo već u prethodnom postu implementirali metodu za određivanje strane tačke, potrebno je još samo implementirati 3 slučaj.

/// <summary>
///
/// </summary>
/// <param name="a">posmatrana tačka</param>
/// <param name="o1">centar kruđnog isječka</param>
/// <param name="radius">radijus kružnog isječka</param>
/// <returns>tru ako je duzina manja od radijusa</returns>
bool isLessThanRadius(Point a, Point o1, float radius)
{
    float length= (float)Math.Sqrt((a.x-o1.x)*(a.x-o1.x) + (a.y-o1.y)*(a.y-o1.y));

    if (radius >= length)
        return true;
    else
        return false;
}

Na kraju je potrebno implementirati metodu koja će objediniti sva tri slučaja u vratiti true ako sva tri slučaja vrate true, u protivnom će vratiti false.

Ostavlja se čitaocu da sublimira prethodnu i ovu implementaciju shodno zaključcima.