Page 4 of 5
Opening a file
Given the getDialog method we can now move on to make use of any dialogs we open. In this case it’s an Open File dialog box with title “Open”:
IntPtr OpenHwnd = getDialog(
We now need to enter text into the dialog’s edit control which Winspector reveals has a control ID of 1152. Its window handle is:
IntPtr EditHwnd = GetDlgItem(
We can use the WM_SETTEXT message to send a string to any edit control – the code for which is:
const uint WM_SETTEXT = 0xC;
We also need a slightly different definition of SendMessage to cope with a pointer to a string:
CharSet = CharSet.Auto,
SetLastError = false)]
static extern IntPtr SendMessage(
[Out, In] StringBuilder lParam);
You can enter both definitions and the system will work out which to use in any particular case. We could now just send the text, but even though the dialog and its edit control exist they could be still in the middle of initialising. This would mean that we could write the text successfully only to have it blanked out again as soon as initialisation is completed! The correct way of dealing with this is to enquire what the state of the dialog is or to set the text and then check that it is indeed set (using a GetText message).
The simplest solution is to just yield control to the other threads in the system for a tenth of a second or more:
StringBuilder file =
IntPtr set = SendMessage(
The file name entered into the dialog box is the default name for the first VOB making up the main program on a DVD in drive D.
Finally we can click the Open button, control ID 1, by sending it a WM_COMMAND message:
IntPtr DlgOpenBtnHwnd =
new HandleRef(VobEdit, OpenHwnd),
This closes the dialog and returns its results to the application.