winapi

C# WPF - custom resizing

I am needing to make a custom window with WindowStyle.None, AllowsTransparency = true, etc. One requirement is a custom ResizeGrip control. I have this working with ResizeMode.CanResizeWithGrip, taking some code from an open source project found here: Fluid Kit See the "GlassWindow" class if you're interested. To do the work, I'm cal...

.NET Interop IntPtr vs. ref

Probably a noob question but interop isn't one of my strong points yet. Aside from limiting the number of overloads is there any reason I should declare my DllImports like: [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam); And use them like this: IntPtr lParam = Marshal...

Turn a C string with NULL bytes into a char array

I am using GetOpenFileName with multiple select capabilities. The files picked are returned in a LPSTR. Inside this LPSTR, the files selected are separated by NULL bytes. I want to split the LPSTR into an array and then loop over that array. In PHP I would do: $array = explode("\0", $string); But since I am new to C, I have no idea ...

How to create a module that reads the frame buffer, and saves the content as an image.

In Windows, there seems to be at least two ways to get to the frame buffer: GDI and DirectX. The problem is that in order to use GDI or DirectX, it seems that you must be running a GUI application, and then from this application you can call the appropriate GDI and DirectX functions. For example: #include <windows.h> int WINAPI WinMai...

Resize a file (down)

I'm attempting to shrink a file in place. I'm replacing the contents of one file with those of another and when I'm done I want to make sure if the source file is smaller than the dest file, the dest file shrinks correctly. (Why: because the dest file is a backup and writing to the media is very expensive, so I only write the deltas to ...

CheckTokenMembership in VB6 - Crashing on FreeSID on Windows 7 and Windows 2008

Hello All, I am using the CheckTokenMembership Windows API to check if the user is an Administrator. Here's the code: Option Explicit Private Const SECURITY_BUILTIN_DOMAIN_RID As Long = &H20 Private Const DOMAIN_ALIAS_RID_ADMINS As Long = &H220 Private Declare Function AllocateAndInitializeSid Lib "advapi32.dll" (pId...

How to determine the size of an icon from a HICON?

I have an icon identified by an HICON handle that I want to draw centered on a custom control. How do I determine the size of the icon so that I can calculate the correct drawing position? ...

Behavior of WS_CLIPCHILDREN and InvalidateRect in Windows 7

To reduce flickering I create my parent windows using the WS_CLIPCHILDREN flag and I call InvalidateRect during the WM_SIZE event. This approach has worked well in Windows XP. However, I recently started programming on Windows 7 and I'm now experiencing rendering issues when resizing windows. When resizing a window its contents is not re...

Creating a UAC like environment

I want to create an environment like UAC. i.e. my dialog should appear to the user and unless he responds to it, i want to disable the background. User should not be able to carry out any activity. For this purpose I created a new desktop and display my dialog on the new desktop. But i want something like UAC where the background seems...

Crashing with gdiplus(new Bitmap)

My application is crashing on Bitmap* image = new Bitmap(hicon) in a old Win XP installation. The stack trace is showing it is in gdiplus.dll, the version of the dll in this system is 5.1.3097.0. I tried with a newer version of dll (5.1.6001.0) and it was working fine. Is this a bug with GDI Plus? or am I doing something wrong. What is ...

Waitable timers or a timer queue? Pros and cons of each?

I've got a Windows service that needs to do certain things periodically. Should I use waitable timer objects or timer queues? What are the pros and cons of the two approaches? Is this a false dichotomy? Is there a third way? ...

[Win32 API] Can I Get Notified When Some Process Starts?

I need to know (preferably with the least latency) when foo.exe is launched. Right now, I have a thread that sits in a light loop (~10 Hz) and walks the process tree looking foo.exe. This is less than elegant and I was wondering whether I could register with some part of the Windows API to get a callback when any process starts. If n...

How to effectively kill a process in C++ (Win32) ?

I am currently writing a very lightweight program so I have to use C++ since it is not bound to .NET framework which drastically increases size of the program. I need to be able to terminate process and to do that I need to get a process handle. Unfortuanately I haven't figured how to do that yet. P.S. I know that to kill a process yo...

A simple C++ framework for Win32 Windows Applications?

Is there a simple/small framework (Other than .NET) which allows you to create windowed applications with C++ under Win32. Just like a little DLL I can include with my app. It should have basic functions like creating a window , buttons , text edits and handling them. ...

MSVC and Win32: Call to DialogBox(...) skipping WM_INITDIALOG

I'm writing a GUI driven by dialog boxes using Win32 and MSVC 6.0, and I'm struggling to understand the usage of WM_INITDIALOG. It's my understanding that WM_INITDIALOG will be called by the dialog process prior to painting it to the screen. The issue I'm having is that WM_INITDIALOG is being called only when I am stepping through the ...

How to find out API functions of DLL files?

Is there a way to get all the API (Export) functions from a DLL file? I know that programs such as Depends and PE Explorer can do that but none of them retrieve the argument list. ...

How do I draw zoomed text without changing effective text width?

I have some code that does custom drawing. Basically it is form fill program that has a WYSIWYG editor. The editor allows a zoom level to be set. I am having problems with the width of my labels jumping to different sizes relative to everything else on the form. An example of the code I am using to output the text is below. I'm pret...

How to lock pages in memory using WinAPI?

I need to prevent application's memory pages from being swapped out of RAM on Windows. Is there a WinAPI function equivalent of POSIX mlockall() to achieve that? ...

Programmatically adding a directory to Windows PATH environment variable

I'm writing a Win32 DLL with a function that adds a directory to the Windows PATH environment variable (to be used in an installer). Looking at the environment variables in Regedit or the Control Panel after the DLL has run shows me that my DLL has succeeded in adding the path to *HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Sess...

Critical Sections that Spin on Posix?

The Windows API provides critical sections in which a waiting thread will spin a limited amount of times before context switching, but only on a multiprocessor system. These are implemented using InitializeCriticalSectionAndSpinCount. (See http://msdn.microsoft.com/en-us/library/ms682530.aspx.) This is efficient when you have a critic...