Esempio n. 1
0
static LRESULT CALLBACK GraphicsWindow_WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	CHECKPOINT_M( ssprintf("%p, %u, %08x, %08x", hWnd, msg, wParam, lParam) );

	/* Suppress autorun. */
	if( msg == g_iQueryCancelAutoPlayMessage )
		return true;

	switch( msg )
	{
	case WM_ACTIVATE:
	{
		const bool bInactive = (LOWORD(wParam) == WA_INACTIVE);
		const bool bMinimized = (HIWORD(wParam) != 0);
		const bool bHadFocus = g_bHasFocus;
		g_bHasFocus = !bInactive && !bMinimized;
		LOG->Trace( "WM_ACTIVATE (%i, %i): %s", bInactive, bMinimized, g_bHasFocus? "has focus":"doesn't have focus" );
		if( !g_bHasFocus )
		{
			RString sName = GetNewWindow();
			static set<RString> sLostFocusTo;
			sLostFocusTo.insert( sName );
			RString sStr;
			for( set<RString>::const_iterator it = sLostFocusTo.begin(); it != sLostFocusTo.end(); ++it )
				sStr += (sStr.size()?", ":"") + *it;

			LOG->MapLog( "LOST_FOCUS", "Lost focus to: %s", sStr.c_str() );
		}

		if( !g_bD3D && !g_CurrentParams.windowed && !g_bRecreatingVideoMode )
		{
			/* In OpenGL (not D3D), it's our job to unset and reset the full-screen video mode
			 * when we focus changes, and to hide and show the window.  Hiding is done in WM_KILLFOCUS,
			 * because that's where most other apps seem to do it. */
			if( g_bHasFocus && !bHadFocus )
			{
				ChangeDisplaySettings( &g_FullScreenDevMode, CDS_FULLSCREEN );
				ShowWindow( g_hWndMain, SW_SHOWNORMAL );
			}
			else if( !g_bHasFocus && bHadFocus )
			{
				ChangeDisplaySettings( NULL, 0 );
			}
		}

		return 0;
	}
	case WM_KILLFOCUS:
		if( !g_bD3D && !g_CurrentParams.windowed && !g_bRecreatingVideoMode )
			ShowWindow( g_hWndMain, SW_SHOWMINNOACTIVE );
		break;

	/* Is there any reason we should care what size the user resizes the window to? */
//	case WM_GETMINMAXINFO:

	case WM_SETCURSOR:
		if( !g_CurrentParams.windowed )
		{
			SetCursor( NULL );
			return 1;
		}
		break;

	case WM_SYSCOMMAND:
		switch( wParam&0xFFF0 )
		{
		case SC_MONITORPOWER:
		case SC_SCREENSAVE:
			return 0;
		}
		break;

	case WM_POWERBROADCAST:
		if(wParam==PBT_APMPOWERSTATUSCHANGE) {
			SYSTEM_POWER_STATUS powerstatus;
			GetSystemPowerStatus(&powerstatus);
			Message msg("PowerSupplyChange");
			switch(powerstatus.ACLineStatus) {
				case 0:
					msg.SetParam( "Online",false);
				break;

				case 1:
					msg.SetParam( "Online",true);
				break;

				default:
				case 255:
					msg.SetParam( "Online",false);
				break;
			}

			if(powerstatus.BatteryFlag & 8) {
				msg.SetParam( "Charging", true);
			} else {
				msg.SetParam( "Charging", false);
			}

			msg.SetParam( "BatteryExists", (powerstatus.BatteryFlag & 128) != 128);

			msg.SetParam( "BatteryCharge", (int)powerstatus.BatteryLifePercent);
			msg.SetParam( "BatteryLifetime", (int)powerstatus.BatteryLifeTime);
			msg.SetParam( "BatteryFullLifetime", (int)powerstatus.BatteryFullLifeTime);

			MESSAGEMAN->Broadcast( msg );
		}
		break;

	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		BeginPaint( hWnd, &ps );
		EndPaint( hWnd, &ps );
		break;
	}

	case WM_KEYDOWN:
	case WM_KEYUP:
	case WM_SYSKEYDOWN:
	case WM_SYSKEYUP:
		/* We handle all input ourself, via DirectInput. */
		return 0;

	case WM_CLOSE:
		LOG->Trace("WM_CLOSE: shutting down");
		ArchHooks::SetUserQuit();
		return 0;

	case WM_WINDOWPOSCHANGED:
	{
		/* If we're fullscreen and don't have focus, our window is hidden, so GetClientRect
		 * isn't meaningful. */
		if( !g_CurrentParams.windowed && !g_bHasFocus )
			break;

		RECT rect;
		GetClientRect( hWnd, &rect );

		int iWidth = rect.right - rect.left;
		int iHeight = rect.bottom - rect.top;
		if( g_CurrentParams.width != iWidth || g_CurrentParams.height != iHeight )
		{
			g_CurrentParams.width = iWidth;
			g_CurrentParams.height = iHeight;
			g_bResolutionChanged = true;
		}
		break;
	}
	}

	CHECKPOINT_M( ssprintf("%p, %u, %08x, %08x", hWnd, msg, wParam, lParam) );

	if( m_bWideWindowClass )
		return DefWindowProcW( hWnd, msg, wParam, lParam );
	else
		return DefWindowProcA( hWnd, msg, wParam, lParam );
}
Esempio n. 2
0
BOOL ConfigDialog::dialogEvent(HWND hWnd,
                               UINT message,
                               WPARAM wParam,
                               LPARAM lParam)
{
    switch (message) {
    case WM_INITDIALOG:
        // Set the spinbox range and its buddy edit control
        SendDlgItemMessage(hWnd, IDC_WAIT_SPIN, UDM_SETRANGE, 0,
                           (LPARAM)MAKELONG((short)9999, (short)1));
        SendDlgItemMessage(hWnd, IDC_WAIT_SPIN, UDM_SETBUDDY,
                           (WPARAM)GetDlgItem(hWnd, IDC_WAIT_NUM), 0);

        // Populate the picture path combo box with saved values
        for (int i = 0; i < settings.getNumRememberedPicturePaths(); i++) {
            std::wstring path = settings.getRememberedPicturePath(i);
            SendDlgItemMessage(hWnd, IDC_PICTURES_PATH, CB_ADDSTRING, 0,
                               (LPARAM)path.c_str());
        }

        updateControls(hWnd,
                       settings.getBasePicturesPath(),
                       settings.getNextPictureWait(),
                       settings.showSmallImages());

        return TRUE;
    case WM_CLOSE:
        EndDialog(hWnd, IDC_CANCEL);
        return TRUE;
    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDC_OK:
            {
                // Pictures Folder
                TCHAR buffer[MAX_PATH+1];
                int text_lenght = GetDlgItemText(hWnd, IDC_PICTURES_PATH,
                                                    buffer, MAX_PATH);
                wstring base_path(buffer, text_lenght);

                // Check that the directory exists before remembering the user settings.
                FileInfo file_info(base_path);
                if (!file_info.exists() || !file_info.isDirectory()) {
                    wstring message = L"Unable to find directory '" + base_path + L"'.\n\n"
                                        L"Please change the selected directory and try again.";
                    MessageBox(hWnd, message.c_str(), L"PhotoViewer", 0);
                    return TRUE;
                }

                settings.setBasePicturesPath(base_path);

                // Reset the last picture, so we start from the first one
                // in the base path
                settings.setLastPicturePath(L"");

                // Wait
                int wait = (int)GetDlgItemInt(hWnd, IDC_WAIT_NUM, NULL, FALSE);
                if (wait < 1) {
                    wait = 1;
                }
                settings.setNextPictureWait(wait * 1000);

                // For short wait times just use a box or bilinear filter as they're
                // quicker.  We don't always use these because they don't look as good
                // as the Catmull Rom filter.
                if (wait == 1) {
                    settings.setRescaleFilterType(FILTER_BOX);
                }
                else if (wait <= 3) {
                    settings.setRescaleFilterType(FILTER_BILINEAR);
                }
                else {
                    settings.setRescaleFilterType(FILTER_CATMULLROM);
                }

                // Ignore Small image
                if (SendDlgItemMessage(hWnd, IDC_SKIP_SMALL_IMAGES, BM_GETCHECK, 0, 0) ==
                        BST_CHECKED) {
                    settings.setShowSmallImages(false);
                }
                else {
                    settings.setShowSmallImages(true);
                }

                EndDialog(hWnd, IDC_OK);
            }
            return TRUE;
        case IDC_CANCEL:
            EndDialog(hWnd, IDC_CANCEL);
            return TRUE;
        case IDC_BROWSE:
            {
                BROWSEINFO browse_info;
                browse_info.hwndOwner = hWnd;
                browse_info.pidlRoot = NULL;
                browse_info.lpszTitle = L"Select folder containing images.";
                browse_info.pszDisplayName = NULL;
                browse_info.ulFlags =  BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON;
                browse_info.lpfn = NULL;
                browse_info.lParam = 0;
                browse_info.iImage = 0;
                LPITEMIDLIST itemIDList;
                if ((itemIDList = SHBrowseForFolder(&browse_info)) != NULL) {
                    TCHAR buffer[MAX_PATH+1];
                    SHGetTargetFolderPath(itemIDList, buffer);
                    if (wstring(buffer).length() != 0)
                        SetDlgItemText(hWnd, IDC_PICTURES_PATH, buffer);
                }
            }
            return TRUE;
        case IDC_DEFAULT:
            settings.resetLastPicturePath();
            updateControls(hWnd,
                            settings.getDefaultBasePicturesPath(),
                            settings.getDefaultNextPictureWait(),
                            settings.showSmallImagesDefault());
            break;
        case IDC_ABOUT:
            MessageBox(hWnd, L"Screensaver for viewing a collection of images.\n\n"
                        L"Developed and maintained by [email protected]\n\n"
                        L"Some Rights Reserved.\n"
                        L"http://creativecommons.org/licenses/by-nc-sa/3.0/\n\n"
                        L"This software uses the FreeImage open source image library.\n"
                        L"FreeImage is used under the §6.1 FIPL license.\n"
                        L"http://freeimage.sourceforge.net/\n",
                        L"About PhotoViewer", 0);
            break;
        }
        break;
    }
    return FALSE;
}
Esempio n. 3
0
LRESULT CALLBACK Fq4EditorWindow::OnCommand( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    int wmId = LOWORD( wParam );
    switch ( wmId )
    {
    case IDM_KINGS:
        {
            int count = GiveTeam( m_kingDatas );
            std::wstring&& message = LogTeamResult( count, m_kingDatas.size() );
            MessageBox( hWnd, message.c_str(), L"國王們", MB_OK );
        }
        break;

    case IDM_FOREST:
        {
            int count = GiveTeam( m_forestDatas );
            std::wstring&& message = LogTeamResult( count, m_forestDatas.size() );
            MessageBox( hWnd, message.c_str(), L"森林國 雷斯達", MB_OK );
        }
        break;

    case IDM_ELF:
        {
            int count = GiveTeam( m_elfDatas );
            std::wstring&& message = LogTeamResult( count, m_elfDatas.size() );
            MessageBox( hWnd, message.c_str(), L"精靈國 薩內多", MB_OK );
        }
        break;

    case IDM_MINE:
        {
            int count = GiveTeam( m_mineDatas );
            std::wstring&& message = LogTeamResult( count, m_mineDatas.size() );
            MessageBox( hWnd, message.c_str(), L"礦山國 格林斯", MB_OK );
        }
        break;

    case IDM_SEA:
        {
            int count = GiveTeam( m_seaDatas );
            std::wstring&& message = LogTeamResult( count, m_seaDatas.size() );
            MessageBox( hWnd, message.c_str(), L"海盜國 慕尼頓", MB_OK );
        }
        break;

    case IDM_PLAIN_MAGICIAN:
        {
           int count = GiveTeam( m_plainMagicianDatas );
           std::wstring&& message = LogTeamResult( count, m_plainMagicianDatas.size() );
           MessageBox( hWnd, message.c_str(), L" 平原國 休利亞(魔法軍團)", MB_OK );
        }
        break;

    case IDM_PLAIN_KNIGHT:
        {
            int count = GiveTeam( m_plainKnightDatas );
            std::wstring&& message = LogTeamResult( count, m_plainKnightDatas.size() );
            MessageBox( hWnd, message.c_str(), L"平原國 休利亞(騎士軍團)", MB_OK );
        }
        break;

    case IDM_ITEM:
        {
            GiveItem();
            MessageBox( hWnd, L"所有道具 +10", L"ITEM", MB_OK );
        }
        break;

    case IDM_MONEY:
        {
            GiveMoney();
            MessageBox( hWnd, L"獲得 $10000", L"MONEY", MB_OK );
        }
        break;

    case IDM_TIRED:
        {
            ReleaseFatigue();
        }
    break;

    default:
        return EditorWindow::OnCommand( hWnd, message, wParam, lParam );
    }

    return 0;
}