Prevent Windows workstation (desktop) from locking while running a WPF program

The solution has been pointed out through the comments, but I’m providing a simple starter solution for anyone else arriving via a web search: /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { [DllImport(“kernel32.dll”, CharSet = CharSet.Auto, SetLastError = true)] static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); public App() { … Read more

Good or evil – SetParent() win32 API between different processes

You can have a parent-child relationship with the windows in different processes. It’s tricky to get it to work right in all cases. You may have to debug various strange symptoms. Normally, windows in separate processes would get their messages from separate input queues using separate message pumps. When you use SendMessage to a window … Read more

Should I deal with files longer than MAX_PATH?

It’s not a real problem. NTFS support filenames up to 32K (32,767 wide characters). You need only use correct API and correct syntax of filenames. The base rule is: the filename should start with ‘\\?\’ (see http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx) like \\?\C:\Temp. The same syntax you can use with UNC: \\?\UNC\Server\share\Path. Important to understand that you can use … Read more

Why are “TranslateMessage” and “DispatchMessage” separate calls?

The more traditional message loop looks like this: while (GetMessage(&msg, 0, 0, 0)) { if (!TranslateAccelerator(hwndMain, haccel, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } It is a pretty big hint to what you’d want to do before dispatching the message: catch messages that ought to be intercepted and treated specially before the window sees them. Keyboard … Read more

Create an Application without a Window

When you write a WinMain program, you automatically get the /SUBSYSTEM option to be windows in the compiler. (Assuming you use Visual Studio). For any other compiler a similar option might be present but the flag name might be different. This causes the compiler to create an entry in the executable file format (PE format) … Read more

How to get the process name in C++

I guess the OpenProcess function should help, given that your process possesses the necessary rights. Once you obtain a handle to the process, you can use the GetModuleFileNameEx function to obtain full path (path to the .exe file) of the process. #include “stdafx.h” #include “windows.h” #include “tchar.h” #include “stdio.h” #include “psapi.h” // Important: Must include … Read more

window border width and height in Win32 – how do I get it?

The GetWindowRect and GetClientRect functions can be used calculate the size of all the window borders. Suite101 has a article on resizing a window and the keeping client area at a know size. Here is their sample code: void ClientResize(HWND hWnd, int nWidth, int nHeight) { RECT rcClient, rcWind; POINT ptDiff; GetClientRect(hWnd, &rcClient); GetWindowRect(hWnd, &rcWind); … Read more