Calvin Hsia's WebLog

thoughts from a professional developer

Browse by Tags

Tagged Content List
  • Blog Post: DPI Aware Sample

    Last time I showed a way to use immediate mode graphics in WPF by showing balls bouncing around in a window. This time, we’ll add a few features. I’ve made the program DPI (Dots Per Inch) Aware. On most machines it works correctly. However, on my brand new Surface Pro 3 (really nice!), the screen resolution...
  • Blog Post: Windows Error Reporting and the Appdomain.UnhandledException Event

    Sometimes applications fail. If you are the author and it fails on your machine, typically you fire up the code in a debugger, figure out the issue, fix it, and rebuild the code. If the applications is out in the wild, perhaps with millions of users, it gets much more complicated. Yet, the goal is still...
  • Blog Post: Create multiple threads to see if work is done simultaneously

    When you hear about threads and threading, you hear that they allow concurrent execution of code, which is supposed to lead to better performance. Most computers nowadays have more than one CPU, meaning that each CPU can be executing code at the same time. Hit Ctrl-Shift-Escape to bring up Task Manager...
  • Blog Post: Process Windows Messages in your WPF application

      I have some code that attaches and injects code into a target application (like Visual Studio or IE) to examine its memory use. In order to do that, my code freezes the target.   I wanted my application to respond to WM_QUERYENDSESSION so that when the user is shutting down, it unfreezes...
  • Blog Post: The cost of using nothing

    What is the cost of using nothing? Seems like a silly question. Suppose you see code like this: void * MyClass::DoSomething() { int size = sizeof(MyThing) * m_NumItems; var ptr = malloc(size); return ptr; } It’s a method that allocates space for m_NumItems MyThings...
  • Blog Post: Using multiple heaps efficiently

    You can inspect the processes that run on your machine using Task Manager (Ctrl-Shift-Escape) or , Process Explorer from Sysinternals Or you can write your own: here’s source code: What is your computer doing with all that memory? Write your own memory browser (if you’re using Dev10...
  • Blog Post: Use Named Pipes and Shared Memory for inter process communication with a child process or two

    I wanted to inject some very low impact code that would run in any “parent” process, like Notepad or Excel or Visual Studio. I wanted to have some User Interface for the data that my injected code gathered about the parent process, and that would work best in a different “child” process, preferably using...
  • Blog Post: What is your computer doing with all that memory? Write your own memory browser

    What is your computer doing with all that memory? There are various kinds of memory allocated and used in each process. These include: · Managed memory (VB.Net, C#, managed C++) · Heap memory · Stacks · Images (files loaded into a process) VirtualAlloc is the basis of these allocations...
  • Blog Post: You can use HWndHost to host a Win32 HWnd window inside a WPF element

    Suppose you have some old code lying around that creates a Win32 window with an HWnd (perhaps ATL , MFC , or just C/ C++). For example, if you type some erroneous code into a VB application in Visual Studio: Dim x=4: catch ex As Exception The “Exception” will be squiggled and the end of...
  • Blog Post: Dynamically load a DLL from a runtime specified path

    When running VB.Net or C# code, often it’s useful to call native code. One way is using PInvoke. (for other ways, see How fast is interop code? ) For example, you can call GetWindowText to get the title of a window. To get it’s managed signature, you can use this code from http://www.pinvoke.net...
  • Blog Post: Compress and timestamp your pictures to gain disk space

    I was running out of space again on my notebook. As years go by, digital cameras can take pictures with more megapixels, but that means they take up more space. Thus my pictures from 10 years ago are much smaller than this year’s. Since I have multiple copies of my picture collection (28...
  • Blog Post: Extract TreeView or ListView ImageList icons from a DLL

    An ImageList can be used for a ListView or TreeView control to contain many images in a single file, usually embedded as a resource. Visual Studio itself has many icons. If you open Windows Explorer or Internet Explorer, you can see many icons in toolbars, ListViews or TreeViews. Using...
  • Blog Post: Create a WPF Form to choose a text color

    I wanted to choose some nice colors for various kinds of text, so I wrote a simple text color picker using Windows Presentation Foundation (WPF) . The code creates a TextBlock and 4 slider controls: one for Alpha channel (Opacity) and one each for Red, Green and Blue. The code shows how to...
  • Blog Post: Resize your pictures for your phone or pocket pc

    I have many digital pictures, and I'd like to put some of my favorites on my SmartPhone . However the files are much higher resolution than the device's display. This means the files take a lot more memory on the phone, and they take longer to process. I wrote some code to resize the images automatically...
  • Blog Post: Generate and run PowerShell scripts dynamically

    In my prior post Use new XML Features of VB to generate dynamic scripts and text files , we generated a simple batch file. It’s difficult to modify the registry or manipulate a COM object PowerShell scripts allow you to manipulate files, registry and COM objects, using a uniform object manipulation...
  • Blog Post: Find which DLLs in your system are rebased

    You can use CreateToolhelp32Snapshot and its family of functions to enumerate the running processes on your machine, including the modules loaded by each process My prior post ( DLL Image base addresses are the same in XP, different on Vista ) described how Dlls are loaded and how some can be rebased...
  • Blog Post: DLL Image base addresses are the same in XP, different on Vista

    When you start a program on your Windows XP computer, a process is created and several DLLs (Dynamic Link Libraries) are loaded into the process. Some DLLs are “system” DLLs, such as Kernel32.dll, GDI32.dll, User32.dll. These DLLs are loaded early in the process start time, because they provide...
  • Blog Post: Help->About->System Info doesn't work on Vista

    A customer (thanks Grady!) reported that choosing Help->About->System Info on Vista causes a MessageBox to display “Microsoft System Info cannot be found or run.” Why is that? Simple investigation: run Regedit on WinXP and Vista to inspect this key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft...
  • Blog Post: Allowing Optional parameters in your COM objects

    It’s simple to create a VFP object that can be used within other applications. I show how useful it is in Blogs get 300 hits per hour: Visual FoxPro can count. That sample builds the T1.C1 object that uses methods with multiple parameters. T1.C1 is a general purpose server which in that example is...
  • Blog Post: How to schedule your computer to run tasks automatically

    Our building will have a power failure at a particular time. You may want your computer to stay on til just before the power goes out due to various reasons: It may be a web or file server serving other clients around the world. You may want to access it from a remote location Choose...
  • Blog Post: Create your own Flip Task Bar with live thumbnails using Vista Desktop Window Manager DWM

    The sample below uses Desktop Window Manager under Windows Vista with Aero to get dynamic live thumbnails of running applications. If a movie is playing in Windows Media Player, it will play in the thumbnail too! EnumChildWindows or EnumWindows is used to enumerate all running windows created by...
  • Blog Post: Vista Aero DWM seems to optimize out GDI paint calls

    In this post: Foxpro Menu items, combo boxes not refreshing selected item under Aero in Vista I describe a problem in Foxpro where menu and list items that are supposed to be non-selected aren’t painted correctly. I described a workaround: call the GdiSetBatchLimit API, which limits the GDI paint functions...
  • Blog Post: Fun with Vista Aero using the DwmExtendFrameIntoClientArea

    You can have a little fun with Vista Aero using the DwmExtendFrameIntoClientArea function. This will cause the VFP border to paint the glass effect around the fox border DECLARE integer DwmExtendFrameIntoClientArea IN dwmapi integer hWnd , string @ daMargins cStr= REPLICATE ( BINTOC...
  • Blog Post: Windows Vista Aero BorderStyle Paint problem as non Administrator

    Above is an image of an inner form (from the C++ project below) before and after I dragged it a little bit up and left to obscure the title bar, then back to the original position. You can see the title, icon, close/minimize buttons were not painted correctly. The same thing happens in Foxpro and VS...
  • Blog Post: Add a manifest to control your application Vista UAC behavior

    Try this on Windows XP or Vista (I don’t remember if manifests are allowed on Win2000: can someone confirm please? Thanks) Start Notepad, then choose File->Open and navigate to c:\windows\system32\notepad.exe and click Open. Hit Ctrl-F to find the text “assembly” You’ve now found the embedded...
Page 1 of 5 (102 items) 12345