Skip to content

Instantly share code, notes, and snippets.

@cbkid
cbkid / WindowRect.cs
Created September 10, 2012 06:16
获取当前窗口显示位置所在屏幕的工作区
HwndSource hd = PresentationSource.FromVisual(this) as HwndSource;
Rect r = CRootGUI.Common.Helpers.ViewHelper.GetWorkingArea(hd);
[System.Diagnostics.DebuggerStepThrough]
public static Rect GetWorkingArea(HwndSource vis)
{
System.Windows.Forms.Screen scrn = System.Windows.Forms.Screen.PrimaryScreen;
if (vis != null && System.Windows.Forms.Screen.AllScreens.Length > 1)
@cbkid
cbkid / singleprocess.cs
Created April 28, 2012 08:16
单一进程
//文件存在情况;
//尝试去创建一个一下名称的Mutex
string mutexName = "MyCompany.MyApplication";
bool createdNew;
mutex = new Mutex(true, mutexName, out createdNew);
//如果创建失败,说明已经创建,因此关闭当前实例
if (!createdNew)
{
try
@cbkid
cbkid / systeminfo.cs
Created March 15, 2012 09:11
获取系统信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Win32;
using System.Management;
using System.IO;
using System.Reflection;
using System.Threading;
@cbkid
cbkid / taskbar.cs
Created March 15, 2012 01:43
将应用程序钉在任务栏
public static bool LockApp(bool isLock, string appPath)
{
Shell shell = new Shell();
Folder folder = shell.NameSpace(Path.GetDirectoryName(appPath));
FolderItem app = folder.ParseName(Path.GetFileName(appPath));
string sVerb = isLock ? "锁定到任务栏(&K)" : "从任务栏脱离(&K)";
foreach (FolderItemVerb item in app.Verbs())
{
if (item.Name == sVerb)
@cbkid
cbkid / service.cs
Created February 13, 2012 07:14
使用C#代码安装 Windows 服务
using System;
using System.Collections.Generic;
using System.ServiceProcess;
using System.Configuration.Install;
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
<!-- ItemContainerStyle with the Trigger for Selected -->
<Style x:Key="RedGlowItemContainer" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border BorderThickness="1"
x:Name="IconBorder" HorizontalAlignment="Left" BorderBrush="#00000000">
<Border.Background>
<SolidColorBrush Color="{DynamicResource DefaultBorderBrushDarkColor}"/>
</Border.Background>
@cbkid
cbkid / thumbnail.cs
Created November 9, 2011 03:44
win7下获取文件缩略图包括其他信息(视频时长等)
using Microsoft.WindowsAPICodePack.Shell;
ShellFile file = ShellFile.FromFilePath(this.Location);
image.Source = file.Thumbnail.BitmapSource;
@cbkid
cbkid / command.cs
Created November 7, 2011 02:18
wpf mvvm mode
//xaml代码
<Button x:Name="bt_public" Grid.Column="8" Style="{DynamicResource ButtonStylePlay}" Command="{Binding EditCommand}" CommandParameter="4" IsEnabled="False" VerticalAlignment="Center" d:LayoutOverrides="GridBox" HorizontalAlignment="Center" Margin="3,0"
ToolTip="发布"
>
@cbkid
cbkid / RaseEvent.cs
Created September 5, 2011 07:02
RaseEvent
private void UserControl_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
// Create a new event and raise it on the desired UserControl.
var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta);
eventArg.RoutedEvent = UIElement.MouseWheelEvent;
eventArg.Source = sender;
var controlToScroll = ScrollContainer;
controlToScroll.RaiseEvent(eventArg);
@cbkid
cbkid / vclistcontrol.cpp
Created May 12, 2011 02:50
listControl
m_list.InsertColumn(0, "Ux",LVCFMT_CENTER, 200);
m_list.InsertColumn( 1, "different", LVCFMT_CENTER, 200 );
for(i=0; i<m_ad.size(); i++)
{
str.Format("%lf", m_ad[i].index);
int iRow = m_list.InsertItem(i, str);
str.Format("%lf", m_ad[i].diff*100000);
m_list.SetItemText(iRow, 1, str);
//m_list.InsertItem(0, str);