Tag: Windows Vista

Windows 7: Task Dialog Part 2 – A more detailed task dialog

In the last installment, we’ve seen using the basic version of task dialog. But usually when we see the task dialogs in Windows Vista or 7, it’s more detailed and can have flashy icons etc. Let’s see how to take more control over the task dialogs.

TaskDialogIndirect function can be used to have more options with task dialogs. TASKDIALOGCONFIG structure is used along with TaskDialogIndirect API.

clip_image001

As you’re seeing above the task dialog contains different type of controls, icons and capable of displaying more information to the user. It can have lengthy big buttons, radio buttons, checkbox, footer area, progressbar, custom icon, displaying predefined buttons like OK, Cancel, Yes, No etc. even we can have control over the buttons in the titlebar( minimize, maximize button etc)

The following code describes creating a task dialog with more flexible options. User can specify the callback functions which can be used to control the behavior if the controls and contents in the task bar. Filling the TASKDIALOGCONFIG structure is simple and straight forward as we’re seeing the code. The detailed option can be obtained from MSDN page.


HRESULT CALLBACK CTaskDialogSampleDlg::TaskDialogCallbackProc(
  __in  HWND hwnd,
  __in  UINT uNotification,
  __in  WPARAM wParam,
  __in  LPARAM lParam,
  __in  LONG_PTR dwRefData
)
{
	if( TDN_CREATED == uNotification )
	{
		::SendMessage( hwnd, TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, IDOK, TRUE );
		::SendMessage( hwnd, TDM_SET_PROGRESS_BAR_RANGE, 0, 100 );
	}
	else if( TDN_HYPERLINK_CLICKED == uNotification )
	{
		ShellExecute( 0, L"open", (LPCTSTR) lParam, 0, 0, SW_SHOW );
	}
	else if( TDN_TIMER == uNotification )
	{
		static int i = 0;
		::SendMessage( hwnd, TDM_SET_PROGRESS_BAR_POS, i++,0 );
	}

	return 0;
}

void CTaskDialogSampleDlg::OnBnClickedButton1()
{
	int nButtonPressed                  = 0;
	TASKDIALOGCONFIG config             = {0};
	const TASKDIALOG_BUTTON buttons[]   = {
		{ IDOK, L"Elevate Privilege" },
		{ IDCANCEL, L"Run with user privilege" }
	};

	const TASKDIALOG_BUTTON radiobuttons[] = {
		{ IDCANCEL, L"Test Radio" }};
	config.cbSize                       = sizeof(config);
	config.hInstance                    = AfxGetApp()->m_hInstance;
	config.dwCommonButtons              = TDCBF_OK_BUTTON | TDCBF_CANCEL_BUTTON;
	config.pszMainIcon                  = TD_SHIELD_ICON;
	config.pszMainInstruction           = L"Main Instruction";
	config.pszContent                   = L"This is the content.";
	config.pszVerificationText          = L"Conifirm license agreement";
	config.pButtons                     = buttons;
	config.cButtons                     = ARRAYSIZE(buttons);
	config.pRadioButtons				= radiobuttons;
	config.cRadioButtons				= ARRAYSIZE( radiobuttons );
	config.dwFlags						= TDF_SHOW_PROGRESS_BAR |
		TDF_EXPAND_FOOTER_AREA | TDF_ENABLE_HYPERLINKS | TDF_CAN_BE_MINIMIZED
		| TDF_USE_COMMAND_LINKS | TDF_CALLBACK_TIMER;
	config.pszExpandedInformation		= _T( "<a href=\"http://codereflect.com/\" >Codereflect.com</a>" );
	config.pfCallback = TaskDialogCallbackProc;
	BOOL bVerification = FALSE;
	TaskDialogIndirect(&config, &nButtonPressed, NULL, &bVerification);

	switch (nButtonPressed)
	{
	case IDOK:
		break; // the user pressed button 0 (change password).
	case IDCANCEL:
		break; // user canceled the dialog
	default:
		break; // should never happen
	}
}

The callback function is also easy to manage. There are predefined set of events for each type of control and we can simply make use of these controls by sending various messages to update its state and values. One of the best example is updating the progressbar during the lifetime of messagebox. Once the timer is enabled, the callback function will be automatically fired on discrete time interval. The notify messages are specified in detail in MSDN Documentation. Please check it.

To compile this source code, please use latest version of Visual Studio 2010 or any prior version with Windows Vista/7 SDK. You can also use express edition of Visual C++ to try this API.


How to make a bootable USB for Windows XP 2003 or Vista?

Recently I purchased a Dell Mini 10v with Windows 7 starter edition. As most of you know, netbooks are not coming with any optical drive. USB takes of it’s role. Installing an operating system is hectic with netbook especially if it’s Windows XP. You’re blessed if you’ve the luxury of an external optical drive. But usually nobody would like to own and external big optical drive with the small netbooks.

When I purchased it from Japan it was pre-installed with Windows 7 Japanese version and I prepared the bootable Windows 7 USB drive using and installed using USB to DVD tool from Microsoft Store. It was painless and installation finished within few minutes.

Lately I inspired few my colleagues towards Dell Mini 10v and obviously the installing risk came to my shoulders( I never expected of it!) and they’ve not prefer to Install Windows 7 even I boasted about the quality security of the Win7.

I’ve tried different methods after Googling. One of the proven method was using BartPE which was little bit painful and I failed to Install it several times. Luckly I got another excellent tool called Novicorp WinToFlash which made all the tasks so easy. It’s so simple.

  • Just download the Zip
  • Start WinToFlash in Administrator mode (if you’re running Windows 7 or Windows Vista)
  • Mount the ISO image or insert the DVD/CD to the optical drive
  • Insert the USB drive
  • Now Start the Wizard and select source drive and destination USB drive (take care to choose right path especially if any of your other USB drives are plugged in)

image

Wizard will prepare the USB and will finish it in few minutes

  • Now insert the USB in your netbook and select the USB as the primary boot device. (In Dell System you can press F12 to select the boot device in the POST BIOS screen)
  • First you’ve to choose the commandline option to install. once the files are finished copying the system will reboot and you’ve to choose the USB as first boot device. Now go for option 2 which spawn the remaining setup in the GUI mode.
  • Once you finish, reboot( no need to select USB device as the primary boot device. select your HDD if you changed the option in BIOS). Now the system may report that HAL.dll was not found and failed to boot. If this issue comes you can see several debugging option. Just try each by each and check properly boot or not. Nothing special to do there. It will report some error and when we reboot, if the issue is solved you can simply boot in to the OS otherwise boot again from USB and select the next debug option. Try one by one until succeeded.

There are few issues I’ve faced with Windows XP install during USB install

The C: drive will most probably be occupied by the inserted USB drive. So your dream to install the OS in C: Drive will remain as a dream. I was little bit tricky and first I installed it in Drive E: and in the HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices I swapped the E: Drive with C: drive in my ambition to boot from it( I’ve done it according to Microsoft Guidance). Boot worked fine but it failed to display the login screen. I reinstalled again but this time, I made another boot USB disk and formatted the drive and created a primary partition( however it seems you can do it with Windows XP installation Windows itself. Format a drive once, reboot it may take place of the C drive. I’ve not tried it though). After that booted from Windows bootable USB. Now this can occupy another drive name as the partition was already existing there.

It may show you that format the USB device and install in it during the initial stage of the boot. You’ve to press ESC key then it will display the attached hard disk and it’s partition. Format it once again if needed or install straight in the new partition. For me installing from USB was damn slow even I used USB 2.0 device.

Now you’re done. Any queries, ask as comments.

Note that I’ve successfully tried only Windows XP. Windows 2003 and Windows Vista are the other options in the Novicorp WinToFlash tool.

Kudos to the team who created this excellent tool and I blame Microsoft for not providing an easy tool to install their OS.


  • Translate to yours!

  • Keep this running!

  • The People!

  • If I’ve proven, be connected

  • Recent Posts

  • Pages

  • Copyright © 1996-2010 Reflections of my thoughts..... All rights reserved.