Thursday, August 30, 2007

[Action Required] Battery Tracker - download new version

Less, then 12 hours and more then 2500 downloads - that's the verdict for this tool. Awareness, there are some critical bugs found in Battery Tracker. Please download the new version (from the same location) and replace the version on your computer. This is required action, due the version from August, 29th has number of bugs, that prevent you from sending me system traces. Sorry for inconvenience and thank you for cooperation.

Download Battery Tracker >>

Wednesday, August 29, 2007

Battery Tracker - Power management and battery tracing tool

A lot of people ask me about how to measure power charging or discharging rate. How to know the quality of your battery and power needs of operating system. How to be sure, that Vista Battery Saver really helps to prolong your battery life and detect exactly how it prolongs it. Two evenings and I wrote small utility, that helps you to know exactly what happens with your laptop battery and helps me to understand what to fix and what to add to VBS to make it better.

image

All you need to do, is to download Battery Tracker, run it, and after some time of tracing hit Stop Tracking link. It asks you to save traces. Write work conditions or any other useful information and then press Save button then, hitting Submit link, send it to me via email. If you want me to know any particular event, write it into text area. By pressing Add link you'll save in into current trace.

Log data-minding tool still not ready to public release, thus currently you can not work with log files, however, submitting this information, highly important for me for future development of Vista Battery Saver. Also, this program works on Windows XP, so if you still have it, please send me traces as well (this mode is not checked enough)

This tool is not collecting any personal information, so, you can quietly submit traces to me. Thank you for cooperation.

Download Battery Tracker >>

Sunday, August 26, 2007

XBox 360 don't know to swim

The moral of that story is "Do your homework before you play video games" via Nathan Weinberg

How to test localized application?

You finished writing World-Ready application. It detects current system culture, or possibly, UI culture, or, even Region and change it's layout language to language, detected with those methods. Now, you want to test it on different locales. What to do? You can go to test PC or, if you're advanced user, install virtual PC images and test the application, while changing Regional and Language Options for each of locale, you want to test. Pretty complicated, especially,  when you want to change UI culture - MUI application requires restart. How to make it easier?

image

You can try tinny test application, I wrote to perform such task. All you have to do is open your target application via LocTester (or just drop the executable into it and play with cultures to test localization support. Here the screenshot of LocTester

image

And small video, that demonstrates the way you'll use it.

Now a little bit about localization in general. First  of all, we have to decide what we want from localization. If all you want is locale-specific dates, currencies or formats, you, probably have to use CultureInfo.CurrentCulture class, if all you want is detect the geographical location of end users, use RegionInfo.CurrentRegion (it's derived from CurrentCulture). In case, you do not need to change formats, but you want to localize user interface for those users, who has Start button on other language, use CurrentCulture.CurrentUICulture class. How to use it? Simple

 

if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("fr"))

{


this.ChangeUICulture("fr");

}


else if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("de"))

{


this.ChangeUICulture("de");

}


else if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("it"))

{


this.ChangeUICulture("it");

}







Now test it with LocTester to see results. You can compare them later, by changing system locale :)



Download LocTester Binaries >>



Download LocTester Source >>

Friday, August 24, 2007

Italian locale for Vista Battery Saver

Grazie to Andrea Dellamonica from Tisource for Italian translation of Vista Battery Saver. Get latest installer from CodePlex (some minor fixes there)

I want to purchase Code Signing Digital ID for VBS to sign code and pass Certified for Vista. There are more, then 500K installation of this software. All we need is 99$ (simple certificate) or 399$ (advanced), thus if each 1000th person will donate 1$, we can buy the certificate and have one dollar spare :). Chip in for Microsoft Authenticode here

Thursday, August 23, 2007

Add Windows Live SkyDrive attachment to your post, by using Windows Live Writer

As you, probably, know, about two months ago, Windows Live team released new sharing platform, named SkyDrive (known as Windows Live Folders). This is really useful service, that allows you to share up to 500MB of your files in internet, by using nice and simple user interface. Why not to use it for attachments (especially, when current version of CS here has known bug to use attachment API :) ).

I think, that all of you using Windows Live Writer to write and publish your posts, thus I decided to write simple and "straight-forward" plugin to use SkyDrive from WLW. Feel free to download, use, rate and tell what you think about.

Unfourchantly, there is no API for SkyDrive, thus the plugin is really big one. :)

Have a nice drive.

Download Windows Live SkyDrive Attachment plugin for Windows Live Writer >>

Microsoft Live comes to Nokia

Nokia always was bad to Windows Mobile, however, it looks like, even with Symbian, they can not be popular enough without Windows Live Services. See yourself. I already using Windows Live Messenger on my E61 device and it's really great. Worth to download and test, however they want you to pay for it... (not now, but afterward)

via Josh

Vista Battery Saver paperclips

Today, looking in Tafiti, I found additional sources noticed Vista Battery Saver. Actually, small sources such as Wired, Download.com and Chip (German). If you're noticed about other big sources wrote about the utility, leave a comment here to update this post

Wednesday, August 22, 2007

Z-Order hack for WinForms interop controls in WPF

If you ever tried to put something from WPF world over Windows Forms controls (interop), you, probably, found it impossible. After it, while searching internet, you found AirSpace article, that clearly describes the reasons and rules. Digging more will bring you to the blog of Jeremiah Morrill, who fighting with AirSpace issue about a year. But this can not help you (and especially to your angry client). From one hand, it's too hard to tell your client: "Sorry, we do now support it". From the other hand, you do not want to mess with complicated 3rd party controls with fair performance. What to do? Scrap it with GDI+. Here the example of scrapping WebBrowser control with it's internal function DrawToBitmap(). We can incorporate it into BitmapSource solution and have nice graphics instead of static control, when you need it. Just collapse WindowsFormsHost and Show Image control with graphical representation of  your Win32 control

 

BitmapSource GetScreen()

{


Bitmap bm = new Bitmap(wb.ClientRectangle.Width, wb.ClientRectangle.Height);

wb.DrawToBitmap(bm, wb.Bounds);


BitmapSource src = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bm.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,

System.Windows.Media.Imaging.
BitmapSizeOptions.FromEmptyOptions());

src.Freeze();


bm.Dispose();


bm =
null;

return src;




}




Wait a second... Why it takes a while to capture the browser screen? Let's see what Control.DrawToBitmap() method doing.





 

public void DrawToBitmap(Bitmap bitmap, Rectangle targetBounds)

{





int width = Math.Min(this.Width, targetBounds.Width);

int height = Math.Min(this.Height, targetBounds.Height);

Bitmap image = new Bitmap(width, height, bitmap.PixelFormat);

using (Graphics graphics = Graphics.FromImage(image))

{


IntPtr hdc = graphics.GetHdc();

using (Graphics graphics2 = Graphics.FromImage(bitmap))

{


IntPtr handle = graphics2.GetHdc();

BitBlt(
new HandleRef(graphics2, handle), targetBounds.X, targetBounds.Y, width, height, new HandleRef(graphics, hdc), 0, 0, 0xcc0020);

graphics2.ReleaseHdcInternal(handle);


}


graphics.ReleaseHdcInternal(hdc);


}




Well, why to repaint graphics with BitBlit? Really, I can not see any reason of it. Let's just copy handler





 

BitmapSource GetScreenInt()



{



Bitmap bm =new Bitmap(wb.ClientRectangle.Width, wb.ClientRectangle.Height);

Graphics g =Graphics.FromImage(bm);

PrintWindow(wb.Handle, g.GetHdc(), 0);


g.ReleaseHdc();


g.Flush();





BitmapSource src = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bm.GetHbitmap(),IntPtr.Zero,Int32Rect.Empty,

System.Windows.Media.Imaging.
BitmapSizeOptions.FromEmptyOptions());

src.Freeze();


bm.Dispose();


bm =
null;

return src;




}


Now, the operation takes less, then 0.3 seconds. Pretty good, isn't it? The only thing, you'll need is unmanaged signature of PrintWindow. Here is comes





 

[DllImport("user32.dll", SetLastError=true)]

static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);

 






Have a nice day

Where is Tafiti?

Want your search be cool? Let me introduce you Tafiti (Swahili) - Do research. What it good for? Let's imagine, you want to search, save your searches and then share your search results with others. You, probably, can use save search feature of Google, then save the result page url with del.icio.us and send it with Yahoo mail or IM it with eBuddy or Meebo. You, probably, want to blog it at Live.Spaces, Blogger, LiveJournal, FaceBook or, even, Twitter Now you have a lot of searches - how to manage them? You, probably, can "shelf" them with Yahoo Pipes or MS Popfly. Complicated enough? Not yet. What to do, if you want to add one search set to another - to get most complete results? Well, just try Tafiti.

 image 

The system built with Silverlight and Live.Search makes all those able. Search, save, share, research.

image

Great idea + nice user interface * most recent and full results = ideal user experience for everyday action items

Tuesday, August 21, 2007

How to DoEvents in WPF?

From VB 5 (even 4) most advanced developers know little nice void method DoEvents. What is it? This is the great way to perform non-blocking wait. The method releases Windows messages pump, other words, performs execution loop. Why this good? Let's see. Following code (C# 1.1) just hangs until the loop will reach it's final value.

for(int i=0;i<1000;i++)
{
label1.Text = i.ToString();
}

How to force it to show values?

for(int i=0;i<1000;i++)
{
label1.Text = i.ToString();
DoEvents();
}

If you want to test this code and see something, put Thread.Sleep(1000); after label1.text... :) Just in case

But in WPF we have no DoEvents() method in application class? What to do? Well, we know, what Dispatcher is. We also know, that it use DispatcherFrame to pump messages, so, why not create our own DoEvents?

void DoEvents(){
DispatcherFrame f = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, 
(SendOrPostCallback)delegate(object arg) {
    DispatcherFrame fr =  arg as DispatcherFrame;
    fr.Continue=True;
}, f);
Dispatcher.PushFrame(frame);
}

Now, by using this method, we'll release message pump and make our long asynchronous methods not block dispatcher thread, but still wait for the end of execution. Here the example how to do it.

DispatcherOperation op = Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
(DispatcherOperationCallback)delegate {
    //DoSomethingReallyLong
    int res = 1;
    int pre = -1;
    for(int i=0;i<1000;++i) {
     int sum = res + pre;
    pre = res;
    res = sum;
     }
    return res;
},null);

while(op != DispatcherOperationStatus.Completed) {
   DoEvents();
}

Console.WriteLine(op.Result);

That's all, folks.

Monday, August 20, 2007

How to measure text length in TextBlock

We already know how to measure text length in TextBox, but if you'll try to do it in TextBlock, you'll discover, that there are no properties for text length. The only thing, can looks like measurement is Block.TextHeight, that for some reason returns always NaN. What to do? Let's look into textblock properties. ActualWidth will calculate the length of textblock and it's text, based on LayoutEngine. This means, that if you'll put it into StackPanel, ActualWidth will return the full StackPanel length, but not the length of the actual text. However, if the text is bigger that available space set by LayoutEngine, then ActualWidth property will return the actual text size. So, what to do? We can put start Width of TextBlock to 0 and then resize it by code. Not quit nice solution. Maybe, let TextBlock to calculate it width itself. A lot of code with MeasureOverride? Really not. Let's bind the TextBlock Width to it's Actual Width.

 

<TextBlock Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}"/>

 






In this case, TextBlock without text inside it get 0 as width and if the text will grow, the width of textblock will grow also. Following sample demonstrate the results.





 

<StackPanel>

<TextBox Name="txt"/>

<
TextBlock Width="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth}" Name="tb" Text="{Binding ElementName=txt, Path=Text}"/>

<
TextBlock Text="{Binding ElementName=tb, Path=ActualWidth}"/>

</
StackPanel>

 






Nice, clean and useful solution. Thank you WPF.

Vista Battery Saver beta 2 r1 - refresh

New minor release of VBS. In this release - fixes of grammar in English strings (tnx to John Guin), German and French localization +bug with German version fixed (tnx to Muty and Vista french community), changes in default power plans and installer.

Thank you, contributors, keep doing great job - we're very close to RC1 - Features will be included - idle awareness, LCD dimming support (for some models), possibly services disablement.

Download Vista Battery Saver Beta 2 r1 >>

Saturday, August 18, 2007

New major version 2.0 of Nokia Mail For Exchange has been released

Yes-yes-yes!!! Blackberry killer for Nokia hit 2.0! A lot of features, where really missing. Here are examples (I found, there are more)

  • Task synchronization (Yes!!!!!!)
  • GAL lookup - now you have not hold all your AD contacts locally
  • You not have to accept all meetings requests tentative (Yupeeee!)
  • There got back disablement of synchronization while roaming! (it was in 1.01, then the feature was removed for some reason - it costs me a lot!)

Ah, that's the best application, I ever have on my E61

Download it ASAP

via e-series

Thursday, August 09, 2007

Microsoft research - some useful updates

A got a couple of questions about planned next generation image manipulation software. I promised, that all of those questions will be answered soon. The time is come and Microsoft presents it's newest researches at Siggraph '07 (International conference and exhibition on computer graphics and interactive technologies). Here the full list of tools and technologies will be presented. It worth to download and use them - they are great.

Tuesday, August 07, 2007

How to use Windows Vista Search API from WPF application?

Another great service, provided by Windows Vista is it's integrated search. Can we use it from our WPF application? Sure we can. This how you'll do it.

First of all you'll need to find Windows Search API library inside Windows SDK. Locate SearchAPI.tlb and process it with tlbimp tool to create managed assembly to reference to. You'll get file, named SeachAPILib.dll. This one, you need. In order to use it, refer to MSDN documentation of Windows Search API 3.0. Actually, using of search API is not much different then using database queries. However, this is not so trivial in core. Actually, the syntax of Windows Search (AQS - Advanced Query Syntax) is very different. But search team create brilliant work to make our life easier. CSearchManager and ISeachQueryHelper - those translate AQS to SQL and, even provide us with proper connection string.

Let's start. First of all, we'll have to create CSeachManager

 

CSearchManager cManager = new CSearchManagerClass();


</PRE< P> 

 






Then, while you are in query, you'll create new ISearchQueryHelper to help you with translations and query strings





 

ISearchQueryHelper cHelper = cManager.GetCatalog("SYSTEMINDEX").GetQueryHelper();

cHelper.QuerySelectColumns =
"\"System.ItemNameDisplay\"";</PRE< P>

 






Well done, now. Ask Vista with old good OleDB provider





 

using (cConnection = new OleDbConnection(

cHelper.ConnectionString))


{


cConnection.Open();


using (OleDbCommand cmd = new OleDbCommand(

cHelper.GenerateSQLFromUserQuery(


SearchString


),


cConnection))


{


if (cConnection.State == ConnectionState.Open)

{


using (OleDbDataReader reader = cmd.ExecuteReader())

{


m_results.Clear();




while (!reader.IsClosed && reader.Read())

{


m_results.Add(reader[0].ToString());


}

reader.Close();





}

}





}


cConnection.Close();


}</PRE< P>

 






Brilliant. Let's move it into WPF by creating DependencyObject, that provide us with all we need for search - search string and array of results





 

public static readonly DependencyProperty SearchTextProperty = DependencyProperty.Register("SearchText", typeof(string), typeof(VistaSearchProviderHelper), new UIPropertyMetadata(default(string),

new PropertyChangedCallback(OnSearchTextChanged)));




static void OnSearchTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)

{


//change

ToAbortFlag = IsWorkingFlag;




if (workerCallback == null)

workerCallback =
new WaitCallback(doSearch);




searchObjState.SearchString = e.NewValue.ToString();


//if (searchObjState.SearchString.Length > 2)

{

workerCallback.BeginInvoke(searchObjState,
null, null);

}





}</PRE< P>

 








 

public string SearchText

{


get { return GetValue(SearchTextProperty).ToString(); }

set { SetValue(SearchTextProperty, value); }

}





static ThreadSafeObservableCollection<string> m_results;

public ReadOnlyObservableCollection<string> Results

{


get { return new ReadOnlyObservableCollection<string>(m_results); }

}</PRE< P>

 






I think you know where to get thread safe observable collection :)



The only thing we should do now is to bind input and output to XAML presentation





 

<StackPanel FocusManager.FocusedElement="{Binding ElementName=searchStr}">

<
StackPanel.DataContext>

<
ObjectDataProvider ObjectType="l:VistaSearchProviderHelper"/>

</
StackPanel.DataContext>

<
TextBox Name="searchStr" Text="{Binding Path=SearchText, UpdateSourceTrigger=PropertyChanged }" FontSize="30"/>

<
ListBox ItemsSource="{Binding Path=Results}" />

</
StackPanel></PRE< P>

 






We done. Now we can search our Windows Vista from custom WPF application. This is not final application for sure, there is a long way to go to make it work perfectly, but this is the beginning of how to do it.



Source code for this article

Thursday, August 02, 2007

This way you love it

Today morning, I noticed about the popularity of Vista Battery Saver. It's in 2nd place by popularity in CodePlex. Thank you all for your support and contributions for this project. Maybe, some day, this program will appears in Windows Vista Extra downloads, or, even in Windows Update. Who knows...

image

Wednesday, August 01, 2007

Damned Oracle

I hate Oracle. I hate it hate it hate it. 4 hours of late work and 5 cups of coffee for only transfer the database from one server to another. Actually, It took only 2.5 hours to transfer, another 1 hours to reinstall in a couple of times and other half an hour to make it finally work. Why things cannot be simple and fluent with this database. Probably because of the army of Oracle DBAs, that will lose their job if such things will be simple?

Impersonal: Deborah, make me think different way :)

But, at the very end, it works as have to work...