Exemple #1
0
AuthSspi::AuthSspi()
	: hasContext(false), ctName(*getDefaultMemoryPool()), wheel(false)
{
	TimeStamp timeOut;
	hasCredentials = initEntries() && (fAcquireCredentialsHandle(0, "NTLM",
					SECPKG_CRED_BOTH, 0, 0, 0, 0,
					&secHndl, &timeOut) == SEC_E_OK);
}
LRESULT dsp_preset_switcher::on_message( HWND parent_wnd , UINT msg , WPARAM wp , LPARAM lp )
{
	switch( msg )
	{
		case WM_CREATE:
		{
			if( wnd_my_combo_box != NULL )
			{
				console::printf( CONSOLE_HEADER "Error: wnd_my_combo_box != NULL" );
				return -1;
			}
			if( ui_hfont != NULL )
			{
				console::printf( CONSOLE_HEADER "Error: ui_hfont != NULL" );
				return -1;
			}

			// get columns UI font
			ui_hfont = uCreateIconFont();
			if( ui_hfont == NULL )
			{
				console::printf( CONSOLE_HEADER "uCreateIconFont() failed" );
				return -1;
			}

			wnd_my_combo_box = CreateWindowEx( 0 , WC_COMBOBOX , nullptr , ( CBS_DROPDOWNLIST | CBS_SORT | WS_CHILD | WS_VISIBLE | WS_TABSTOP ) , 0 , 0 , INIT_WIDTH , CW_USEDEFAULT , parent_wnd , NULL , core_api::get_my_instance() , nullptr );
			if( wnd_my_combo_box == NULL )
			{
				console::printf( CONSOLE_HEADER "CreateWindowEx() failed" );

				DeleteFont( ui_hfont );
				ui_hfont = NULL;
				return -1;
			}

			dsp_preset_switcher::PARENT_HWND_LIST.remove_item( parent_wnd );
			dsp_preset_switcher::PARENT_HWND_LIST.add_item( parent_wnd );

			// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
			// Sets the font that a control is to use when drawing text.
			uSendMessage( wnd_my_combo_box , WM_SETFONT , ( WPARAM ) ui_hfont , MAKELPARAM( 1 , 0 ) );

			// get metrics
			RECT rc;
			GetWindowRect( wnd_my_combo_box , &rc );
			HEIGHT = RECT_CY( rc );

			// get dsp names and add to combo box
			pfc::list_t<pfc::string8> l;
			initEntries( l );

			// set initial selection
			const bool ret = setEntry( CFG_IDX );
			if( !ret )
				CFG_IDX = -1;

			// determine width
			// MSDN Remarks: After an application has finished drawing with the new font object , it should always replace a new font object with the original font object.
			CONST HDC dc = GetDC( wnd_my_combo_box );
			CONST HFONT font_old = SelectFont( dc , ui_hfont );
			for( t_size i = 0 , imax = l.get_count(); i < imax ; ++i )
			{
				const char *str = l[i].get_ptr();
				const int cx = ui_helpers::get_text_width( dc , str , strlen( str ) );
				min_width = max( min_width , ( t_size ) cx );
			}
			SelectFont( dc , font_old );
			ReleaseDC( parent_wnd , dc );

			// get min width
			COMBOBOXINFO cbi = { 0 };
			cbi.cbSize = sizeof( cbi );
			GetComboBoxInfo( wnd_my_combo_box , &cbi );

			RECT rc_client;
			GetClientRect( wnd_my_combo_box , &rc_client );
			min_width += RECT_CX( rc_client ) - RECT_CX( cbi.rcItem );

			return 0;
		}

		case WM_DESTROY:
		{
			dsp_preset_switcher::PARENT_HWND_LIST.remove_item( GetParent( wnd_my_combo_box ) );
			DestroyWindow( wnd_my_combo_box );
			wnd_my_combo_box = NULL;

			DeleteFont( ui_hfont );
			ui_hfont = NULL;

			return 0;
		}

		case WM_GETMINMAXINFO:
		{
			CONST LPMINMAXINFO ptr = ( LPMINMAXINFO ) lp;
			ptr->ptMinTrackSize.x = min_width;

			ptr->ptMinTrackSize.y = HEIGHT;
			ptr->ptMaxTrackSize.y = HEIGHT;
			return 0;
		}

		case WM_WINDOWPOSCHANGED:
		{
			CONST LPWINDOWPOS ptr = ( LPWINDOWPOS ) lp;
			if( !( ptr->flags & SWP_NOSIZE ) )
			{
				SetWindowPos( wnd_my_combo_box , HWND_TOP , 0 , 0 , ptr->cx , HEIGHT , SWP_NOZORDER );
			}

			return 0;
		}

		case WM_COMMAND:
		{
			if( wp == ( CBN_SELCHANGE << 16 ) )
			{
				int idx;
				pfc::string8 text;
				bool ret = getSelection( idx , text );
				if( !ret )
					break;

				CFG_IDX = idx;
				ret = selDspName( idx , text.get_ptr() );
				if( !ret )
					syncSelection( -1 );
				return 0;
			}

			break;
		}

		case WM_USER_DSP_CORE_CHANGE:
		{
			if( skip_msg )
			{
				skip_msg = false;
				return 0;
			}

			// just rescan DSP name entries and remove the current selected one
			pfc::list_t<pfc::string8> d;
			initEntries( d );
			CFG_IDX = -1;
			return 0;
		}

		case WM_USER_SYNC_CHANGE:
		{
			if( wp == -1 )
			{
				pfc::list_t<pfc::string8> l;
				initEntries( l );
				return 0;
			}

			skip_msg = true;
			setEntry( wp );
			return 0;
		}

		default:
		{
			//console::printf( CONSOLE_HEADER "default case: %u" , msg );
			break;
		}
	}

	// Calls the default window procedure to provide default processing for any window messages that an application does not process. 
	// This function ensures that every message is processed.
	return uDefWindowProc( parent_wnd , msg , wp , lp );
}