winapi

Blocking mouse input from a service in Vista

I maintain a variety of managed userlabs on a university campus. These machines all currently run Windows XP and we have a windows service that is used to "lock" a machine by blocking any keyboard or mouse input. The locking happens during our scripted OS installation so that users aren't able to accidentally halt or break the process....

Win32 current directory, locking & shell integration

In Win32, your main thread's current working directory is set to the location the executable was launched from. My problem is that even after a call to SetCurrentDirectory() to somewhere else, the process apparently still has a filesystem object referencing this initial startup directory (verifiable with a tool like Process Explorer) - w...

In C#, is there a way to consistently be able to get the selected text contents of currently focused window?

In my c# .Net application, I've been trying to be able to retrieve the currently selected text in the currently focused window. (Note that it can be any window open in windows, such as word, or safari). I'm able to retrieve the handle to the currently focused control. (Using a couple of interop calls to user32.dll, and kernel32.dll). ...

Adding an host programmatically (name resolution under Windows)

I would like to programmatically add to Windows a name / IP association so that this name can be resolved locally. This does not have to be persisted between reboots. The only way I now is to add an entry to the "hosts" file, but this feels hacky especially since I would like to automate this. Is there any way to do this using a comman...

Is there any preferable way to get user/group information from an Active Directory domain in Python?

For a Django application that I'm working on, I wanted to allow group membership to be determined by Active Directory group. After a while of digging through the pywin32 documentation, I came up with this: >>> import win32net >>> win32net.NetUserGetGroups('domain_name.com', 'username') [(u'Domain Users', 7), ...] I spent a while goog...

Trim a string in C

Briefly: I'm after the equivalent of .NET's String.Trim in C using the win32 and standard C api (compiling with MSVC2008 so I have access to all the C++ stuff if needed, but I am just trying to trim a char*). Given that there is strchr, strtok, and all manner of other string functions, surely there should be a trim function, or one t...

GetOpenFileName() with OFN_ALLOWMULTISELECT flag set

Hello, I'm trying to use the GetOpenFileName() common dialog box call to pop open a dialog box and allow the user to select multiple files. I've got the OFN_ALLOWMULTISELECT flag set, as well as OFN_EXPLORER set so I get the "new style" file selection box. When I set up my OPENFILENAME structure, I have ofn.lpstrFile pointing to a buff...

Installing Root CA Cert via code on Win32

Hey all, We've just set up a new remote access solution using Microsoft's TS Gateway, which requires a couple of somewhat fiddly steps on the end users behalf in order to get it working (installing our root ca cert, requirement of RDP 6.1 client etc). In order to make this setup process as easy as possible (a lot of these users aren't ...

Win32 Thread scheduling.

As I understand, windows thread scheduler does not discriminate beween threads belonging two different processes, provided all of them have the same base priority. My question is if I have two applications one with only one thread and the other with say 50 threads all with same base priority, does it mean that the second process enjoys m...

how to create command application like run command for vista

how to create application like window run command using C#. When i insert any command (for example: ipconfig) , this return result (for example: 192.168.1.1) on the textbox. how to get windows command list? how to get command result? how to get installed application list on the machine? ...

How to tell if a network adapter is removable on Windows

Hello, community! How can I tell if a given network adapter retrieved through the Win32 GetAdaptersInfo() or GetAdaptersAddresses() functions is a removable one, like USB, SmartCard, etc? The documentation for these functions does not seem to contain any means of getting that information, so I'm assuming I have to go ask Windows for ea...

Why a child window may not receive mouse events?

I have a custom WTL control which is a panel with a list and a custom scroll bar. class Panel : public ATL::CWindowImpl<Panel>, public WTL::CDoubleBufferImpl<Panel> { public: DECLARE_WND_CLASS("Panel") BEGIN_MSG_MAP_EX(Panel) MSG_WM_CREATE(OnCreate) MSG_WM_DESTROY(OnDestroy) MSG_WM_SIZE(OnSize) CHAIN_MSG_MAP...

RegisterDeviceNotification Returns NULL but notifications still recieved.

I'm using RegisterDeviceNotification to watch for changes to a USB device, using the WM_DEVICECHANGE event. However, when I call RegisterDeviceNotification() it returns NULL for the notification handle, which should indicate that it failed. But GetLastError() returns ERROR_SUCCESS and the notifications actually go through. This causes ...

Is midiOutPrepareHeader a quick call?

Does midiOutPrepareHeader, midiInPrepareHeader just setup some data fields, or does it do something that is more time intensive? I am trying to decide whether to build and destroy the MIDIHDR's as needed, or to maintain a pool of them. ...

Windows development for hardcore Java guy

I'm a little ashamed for asking this, because, you know, I've been very anti-MS for a long time. I have been fortunate enough as to make a living outside Visual Studio. As I grown older there are "some" things I would like to try, and to be very honest, this Q&A site has inspired me and I realize that VS and Windows Development doesn't ...

How to specify kbd modifiers with SendInput()?

I'm using the Windows API SendInput() call to simulate keyboard events. The following snippet (irrelevant details omitted) works perfectly for sending a sequence of characters: wchar_t txt = ...; INPUT *input = ...; size_t nInput = 0; for (unsigned int j = 0; j < length; j++) { input[nInput].ki.wVk = 0; input[nInput].ki.wScan ...

How do I determine if a DIB is bottom-up or top-down ?

If I create a DIB using CreateDIBSection(), I can specify wether it should be top-down or bottom-up by setting the biHeight field of the BITMAPINFOHEADER struct to a negative or positive value. However, if i call GetObject() on such a bitmap to fill a DIBSECTION structure, then both the dsBm.bmHeight and dsBmih.biHeight seem to be always...

Stopping a thread in Win32/MFC

I was reading through some threading related code and found this piece of code: MyThread::start() { //Create a thread m_pThread = AfxBeginThread(/*some parameters*/) //Create a duplicate handle for the created thread m_hDuplicateHandle = DuplicateHandle(/* some more parameters*/) } MyThread::stop() { //Set some variables so ...

How to catch an exception thrown in a critical section?

I'm working on win 32 multithreading with c++. Scenario: I have a function used by multiple threads. This function as a critical sections (or any kind of construct that can lock a resource). In the critical section an exception is thrown. At this point I need to take care of unlocking the resource in the exception catch block. Is there ...

Are there any common Design patterns or common idioms that are important for C++ win32 multithreading programming?

One example could be: RAII - Resource Acquisition is Initialization used with critical sections Any others that are important, popular and you often use? ...