In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?

You don’t have write any C/JNI code. From Java: import sun.awt.windows.WComponentPeer; public static long getHWnd(Frame f) { return f.getPeer() != null ? ((WComponentPeer) f.getPeer()).getHWnd() : 0; } Caveats: This uses a sun.* package. Obviously this is not public API. But it is unlikely to change (and I think less likely to break than the solutions … Read more

Removing window border?

In C/C++ LONG lStyle = GetWindowLong(hwnd, GWL_STYLE); lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU); SetWindowLong(hwnd, GWL_STYLE, lStyle); WS_CAPTION is defined as (WS_BORDER | WS_DLGFRAME). You can get away with removing just these two styles, since the minimize maximize and sytem menu will disappear when the caption disappears, but it’s best to … Read more

How to copy string to clipboard in C?

Read the MSDN documentation for the SetClipboardData function. It appears you are missing a few steps and releasing the memory prematurely. First of all, you must call OpenClipboard before you can use SetClipboardData. Secondly, the system takes ownership of the memory passed to the clipboard and it must be unlocked. Also, the memory must be … Read more

Alignment requirements for atomic x86 instructions vs. MS’s InterlockedCompareExchange documentation?

x86 does not require alignment for a lock cmpxchg instruction to be atomic. However, alignment is necessary for good performance. This should be no surprise, backward compatibility means that software written with a manual from 14 years ago will still run on today’s processors. Modern CPUs even have a performance counter specifically for split-lock detection … Read more

Symlinks on windows?

NTFS file system has junction points, I think you may use them instead, You can use python win32 API module for that e.g. import win32file win32file.CreateSymbolicLink(fileSrc, fileTarget, 1) If you do not want to rely on win32API module, you can always use ctypes and directly call CreateSymbolicLink win32 API e.g. import ctypes kdll = ctypes.windll.LoadLibrary(“kernel32.dll”) … Read more

How to gracefully terminate a process?

EnumWindows enumerates all the top level windows in a process. GetWindowThreadProcessId gets the process and Id of each thread. You now have enough information to gracefully close any GUI application. You can send WM_CLOSE messages to any window you wish to close. Many windows handle WM_CLOSE to prompt the user to save documents.You can send … Read more