[Windows API] Programmatically invoking Map Network Drive dialog.

This how the map network drive dialog look like. So how do we show this dialog programmatically? The windows API’s for showing this dialog is: WNetConnectionDialog and WNetConnectionDialog1. I’ve demonstrated both WNetConnectionDialog and WNetConnectionDialog1 in this code snippet. WNetConnectionDialog is a simple API which takes a window handle and a DWORD. While WNetConnectionDialog1 is an […]
Continue reading…

 

[Windows API] Code to get file size

In this blog post I’ll be demonstrating different API’s and techniques used to retrieve size of a file. I haven’t tested this much, you might want to add parameter integrity check etc., also probably better error checks. Use this code at your own risk. Using GetFileSizeEx Using _wstat64 Using GetFileInformationByHandleEx Using FindFirstFileW Using fseek and […]
Continue reading…

 

Turn on/off buffering for streams in c++

Use io manipulator ‘unitbuf’ to turn off stream buffering and ‘nounitbuf’ to turn on stream buffering. If ‘unitbuf’ is on the stream object is flushed after every insertion else the stream is not force flushed. For e.g. endl triggers a flush in cases of ‘nounitbuf’. Sample code: fstream fstr( “c://Hello.txt” ); [sourcecode language=”cpp”]cout << unitbuf […]
Continue reading…

 

PickIconDlg function explained

In windows if you ever changed the icon of a shortcut then you’ll know what the API PickIconDlg does. Basically this function will let you select any icon embedded as a resource in a .dll or .exe file for use in your application. Just select in the dialog the icon that you like and click ok. Here is a […]
Continue reading…

 

Retrieve handle type string using NtQueryObject

Hmm so after a long time I’m back with a new post. This time I came across a cool API called NtQueryObject. One purpose of the API is to find the name of object type it’s given. For example if you are passing a process handle this API will return “Process” as the string. The […]
Continue reading…

 

Mandatory styles for a child dialog

If you are creating a dialog with style WS_CHILD then make sure you also have DS_CONTROL  and DS_CONTROLPARENT enabled for the dialog. The reason being that the dialog at a time is a control (embedded inside another window) and a control parent (housing other controls). If these styles are not specified calls to GetWindowRect and […]
Continue reading…

 

How to show “Open with” dialog?

It’s quite handy to show the standard windows open with dialog, which lists all installed applications along with a browse button. In Windows XP there is no straight forward way of doing this. In Windows Vista onwards Microsoft has provided a shell API for this purpose. It’s called SHOpenWithDialog. Some sample code (couldn’t test this […]
Continue reading…

 

How to create a unicode window in a non-unicode application?

Recently a user asked this question in MSDN forums. He had MBCS enabled for his application and also wanted to enable unicode characters in a particular edit control. Note MFC only create unicode controls if UNICODE is defined in project settings. So in order to explicitly create controls that support UNICODE characters we use the […]
Continue reading…

 

Some issues when working with ComboBox

The main reason for posting this issue is to help MFC/Win32 beginners. But anyway it’s a good read ;), so once upon a time… If you’re a beginner with window’s ComboBox controls then you might end up with a bald head thinking and thinking about a weird behavior of combo’s after it’s creation. The combo […]
Continue reading…

 

How to use SendInput?

So what does SendInput API do? SendInput API is a helper function to simulate keyboard and mouse inputs. It’s an ideal function to insert characters into a password which otherwise is not possible. Here is what MSDN says about this function… “The SendInput function inserts the events in the INPUT structures serially into the keyboard […]
Continue reading…