Ejemplo n.º 1
0
void FocusedAXObserverCallback(AXObserverRef Observer, AXUIElementRef Element, CFStringRef Notification, void *ContextData)
{
    Assert(Element, "AXOBserverCallback() Element was null")

    window_info *Window = KWMFocus.Window;
    if(!Window)
        return;

    if(CFEqual(Notification, kAXTitleChangedNotification))
        Window->Name = GetWindowTitle(Element);

    if(IsWindowFloating(Window->WID, NULL) ||
       IsApplicationFloating(Window))
        UpdateBorder("focused");

    if(!IsWindowFloating(Window->WID, NULL) &&
        KWMToggles.EnableDragAndDrop &&
        KWMToggles.DragInProgress &&
        CFEqual(Notification, kAXWindowMovedNotification))
    {
        KWMToggles.DragInProgress = false;
        KWMTiling.FloatingWindowLst.push_back(Window->WID);
        RemoveWindowFromBSPTree(KWMScreen.Current, Window->WID, false, false);

        if(KWMMode.Focus != FocusModeDisabled &&
           KWMMode.Focus != FocusModeAutofocus &&
           KWMToggles.StandbyOnFloat)
        {
            KWMMode.Focus = FocusModeStandby;
        }
    }
}
Ejemplo n.º 2
0
/**
 *  Schliesst das Fenster.
 *
 *  @author FloSoft
 */
void VideoWinAPI::DestroyScreen(void)
{
    // Fenster schliessen
    EndDialog(screen, 0);

    if(dm_prev.dmBitsPerPel != 0)
        ChangeDisplaySettings(&dm_prev, CDS_RESET);

    if(screen_rc)
    {
        if(!wglMakeCurrent(NULL, NULL))
            return;

        if(!wglDeleteContext(screen_rc))
            return;

        screen_rc = NULL;
    }

    if((screen_dc) && (!ReleaseDC(screen, screen_dc)))
        return;

    screen_dc = NULL;

    if((screen) && (!DestroyWindow(screen)))
        return;

    screen = NULL;

    UnregisterClassA(GetWindowTitle(), GetModuleHandle(NULL));

    isFullscreen_ = false;
}
Ejemplo n.º 3
0
void KPGlutUserInterface::OpenWindow(int argc, char **argv)
{
    glutInit(&argc, argv);
    BLogger::Log("GLUT UserInterface initialization");
#ifdef GLUT_API_VERSION
    BLogger::Log("GLUT API Version ", GLUT_API_VERSION);
#endif
#ifdef GLUT_XLIB_IMPLEMENTATION
    BLogger::Log("GLUT XLIB Implementation #", GLUT_XLIB_IMPLEMENTATION);
#endif
#ifdef FREEGLUT
    int glutVersion = glutGet(GLUT_VERSION);
    BLogger::Log("FREEGLUT Version ",
                 (glutVersion / 10000) % 100, '.',
                 (glutVersion /   100) % 100, '.',
                 glutVersion          % 100);
#endif
#ifdef OPENGLUT
    auto glutVersion = glutGet(GLUT_VERSION);
    BLogger::Log("OPENGLUT Version ",
                 (glutVersion / 10000) % 100, '.',
                 (glutVersion /   100) % 100, '.',
                 glutVersion          % 100);
#endif

    if (!IsWindowResolutionSupported(config->ScreenXResolution,
                                     (config->ScreenXResolution * 3) / 4))
    {
        config->ScreenXResolution = 640;
    }

    // Open OpenGL Window with GLUT
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(config->ScreenXResolution,
                       (config->ScreenXResolution * 3) / 4);
    //glutInitWindowPosition (10, 10);
    windowID = glutCreateWindow(GetWindowTitle().c_str());

    if (config->FullScreen)
    {
        glutFullScreen();
    }

    DebugPrintOpenGLVersion();

    if (windowID <= 0)
    {
        throw std::runtime_error("Error in glutCreateWindow");
    }

    InitializeAfterOpen();
}
Ejemplo n.º 4
0
void FocusedAXObserverCallback(AXObserverRef Observer, AXUIElementRef Element, CFStringRef Notification, void *ContextData)
{
    pthread_mutex_lock(&KWMThread.Lock);

    window_info *Window = KWMFocus.Window;
    if(Window && CFEqual(Notification, kAXTitleChangedNotification))
        Window->Name = GetWindowTitle(Element);
    else if(CFEqual(Notification, kAXWindowResizedNotification) ||
            CFEqual(Notification, kAXWindowMovedNotification))
        UpdateBorder("focused");

    pthread_mutex_unlock(&KWMThread.Lock);
}
Ejemplo n.º 5
0
/**
 *  Erstellt das Fenster mit entsprechenden Werten.
 *
 *  @param[in] width      Breite des Fensters
 *  @param[in] height     Höhe des Fensters
 *  @param[in] fullscreen Vollbildmodus ja oder nein
 *
 *  @return @p true bei Erfolg, @p false bei Fehler
 */
bool VideoSDL::CreateScreen(unsigned short width, unsigned short height, const bool fullscreen)
{
    char title[512];

    if(!initialized)
        return false;

    // TODO: Icon setzen


    // GL-Attribute setzen
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);

#ifdef _WIN32
    // das spinnt ja total unter windows ...
    this->isFullscreen_ = false;
#else
    this->isFullscreen_ = fullscreen;
#endif

    // Videomodus setzen
    if(!(screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | (this->isFullscreen_ ? SDL_FULLSCREEN : SDL_RESIZABLE))))
    {
        fprintf(stderr, "%s\n", SDL_GetError());
        return false;
    }

    sprintf(title, "%s - v%s-%s", GetWindowTitle(), GetWindowVersion(), GetWindowRevision());
    SDL_WM_SetCaption(title, 0);

#ifdef _WIN32
    SetWindowTextA(GetConsoleWindow(), title);
#endif

    std::fill(keyboard.begin(), keyboard.end(), false);

    this->screenWidth  = width;
    this->screenHeight = height;

    SDL_ShowCursor(SDL_DISABLE);

    return true;
}
Ejemplo n.º 6
0
int MediaPlayers::Check() {
    index = -1;
    bool recognized = CurrentEpisode.anime_id > anime::ID_UNKNOWN;

    // Go through windows, starting with the highest in the Z order
    HWND hwnd = GetWindow(g_hMain, GW_HWNDFIRST);
    while (hwnd != nullptr) {
        for (auto item = items.begin(); item != items.end(); ++item) {
            if (!item->enabled)
                continue;
            if (item->visible && !IsWindowVisible(hwnd))
                continue;
            // Compare window classes
            for (auto c = item->classes.begin(); c != item->classes.end(); ++c) {
                if (*c == GetWindowClass(hwnd)) {
                    // Compare file names
                    for (auto f = item->files.begin(); f != item->files.end(); ++f) {
                        if (IsEqual(*f, GetFileName(GetWindowPath(hwnd)))) {
                            if (item->mode != MEDIA_MODE_WEBBROWSER || !GetWindowTitle(hwnd).empty()) {
                                // Stick with the previously recognized window, if there is one
                                if (!recognized || item->window_handle == hwnd) {
                                    // We have a match!
                                    index = index_old = item - items.begin();
                                    new_title = GetTitle(hwnd, *c, item->mode);
                                    EditTitle(new_title, index);
                                    if (current_title != new_title) title_changed_ = true;
                                    current_title = new_title;
                                    item->window_handle = hwnd;
                                    return index;
                                }
                            }
                        }
                    }
                }
            }
        }
        // Check next window
        hwnd = GetWindow(hwnd, GW_HWNDNEXT);
    }

    // Not found
    return -1;
}
Ejemplo n.º 7
0
STDMETHODIMP CInternalPropertyPage::GetPageInfo(PROPPAGEINFO* pPageInfo)
{
    CAutoLock cAutoLock(this);

    CheckPointer(pPageInfo, E_POINTER);

    LPOLESTR pszTitle;
    HRESULT hr = AMGetWideString(CStringW(GetWindowTitle()), &pszTitle);
    if (FAILED(hr)) {
        return hr;
    }

    pPageInfo->cb = sizeof(PROPPAGEINFO);
    pPageInfo->pszTitle = pszTitle;
    pPageInfo->pszDocString = nullptr;
    pPageInfo->pszHelpFile = nullptr;
    pPageInfo->dwHelpContext = 0;
    pPageInfo->size = GetWindowSize();

    return S_OK;
}
Ejemplo n.º 8
0
void FocusedAXObserverCallback(AXObserverRef Observer, AXUIElementRef Element, CFStringRef Notification, void *ContextData)
{
    if(KWMToggles.EnableDragAndDrop &&
       KWMToggles.DragInProgress &&
       CFEqual(Notification, kAXWindowMovedNotification) &&
       !IsWindowFloating(KWMFocus.Window->WID, NULL))
    {
        KWMToggles.DragInProgress = false;
        KWMTiling.FloatingWindowLst.push_back(KWMFocus.Window->WID);
        RemoveWindowFromBSPTree(KWMScreen.Current, KWMFocus.Window->WID, false, false);

        if(KWMMode.Focus != FocusModeDisabled && KWMMode.Focus != FocusModeAutofocus && KWMToggles.StandbyOnFloat)
            KWMMode.Focus = FocusModeStandby;
    }

    if(CFEqual(Notification, kAXTitleChangedNotification) && KWMFocus.Window)
        KWMFocus.Window->Name = GetWindowTitle(Element);

    if(IsFocusedWindowFloating())
        UpdateBorder("focused");
}
Ejemplo n.º 9
0
bool App3D::Configure(void)
{
	try
	{
		if(root->restoreConfig() || root->showConfigDialog())
		{
			// If returned true, user clicked OK so initialise
			// Here we choose to let the system create a default rendering window by passing 'true'
			window = root->initialise(true,  GetWindowTitle());
			return true;
		}
		else 
		{
			return false;
		}
	}
	catch (Ogre::InvalidParametersException &e)
	{
		return false;
		
	}
}
Ejemplo n.º 10
0
wstring MediaPlayers::GetTitle(HWND hwnd, const wstring& class_name, int mode) {
    switch (mode) {
    // File handle
    case MEDIA_MODE_FILEHANDLE:
        return GetTitleFromProcessHandle(hwnd);
    // Winamp API
    case MEDIA_MODE_WINAMPAPI:
        return GetTitleFromWinampAPI(hwnd, false);
    // Special message
    case MEDIA_MODE_SPECIALMESSAGE:
        return GetTitleFromSpecialMessage(hwnd, class_name);
    // MPlayer
    case MEDIA_MODE_MPLAYER:
        return GetTitleFromMPlayer();
    // Browser
    case MEDIA_MODE_WEBBROWSER:
        return GetTitleFromBrowser(hwnd);
    // Window title
    case MEDIA_MODE_WINDOWTITLE:
    default:
        return GetWindowTitle(hwnd);
    }
}
Ejemplo n.º 11
0
/**
 * This function is called by MakeCurrent() and determines whether or
 * not a new rendering context should be bound to Chromium or the native
 * OpenGL.
 * \return  GL_FALSE if native OpenGL should be used, or GL_TRUE if Chromium
 *          should be used.
 */
static GLboolean
stubCheckUseChromium( WindowInfo *window )
{
	int x, y;
	unsigned int w, h;

	/* If the provided window is CHROMIUM, we're clearly intended
	 * to create a CHROMIUM context.
	 */
	if (window->type == CHROMIUM)
		return GL_TRUE;

	if (stub.ignoreFreeglutMenus) {
		const char *glutMenuTitle = "freeglut menu";
		char title[1000];
		GetWindowTitle(window, title);
		if (crStrcmp(title, glutMenuTitle) == 0) {
			crDebug("GL faker: Ignoring freeglut menu window");
			return GL_FALSE;
		}
	}

	/*  If the user's specified a window count for Chromium, see if
		*  this window satisfies that criterium.
		*/
	stub.matchChromiumWindowCounter++;
	if (stub.matchChromiumWindowCount > 0) {
		if (stub.matchChromiumWindowCounter != stub.matchChromiumWindowCount) {
			crDebug("Using native GL, app window doesn't meet match_window_count");
			return GL_FALSE;
		}
	}

	/* If the user's specified a window list to ignore, see if this
	 * window satisfies that criterium.
	 */
	if (stub.matchChromiumWindowID) {
		GLuint i;

		for (i = 0; i <= stub.numIgnoreWindowID; i++) {
			if (stub.matchChromiumWindowID[i] == stub.matchChromiumWindowCounter) {
				crDebug("Ignore window ID %d, using native GL", stub.matchChromiumWindowID[i]);
				return GL_FALSE;
			}
		}
	}

	/* If the user's specified a minimum window size for Chromium, see if
	 * this window satisfies that criterium. 
	 */
	if (stub.minChromiumWindowWidth > 0 && 
	    stub.minChromiumWindowHeight > 0) {
		stubGetWindowGeometry( window, &x, &y, &w, &h );
		if (w >= stub.minChromiumWindowWidth && 
		    h >= stub.minChromiumWindowHeight) {

			/* Check for maximum sized window now too */
			if (stub.maxChromiumWindowWidth && 
			    stub.maxChromiumWindowHeight) {
				if (w < stub.maxChromiumWindowWidth &&
				    h < stub.maxChromiumWindowHeight)
					return GL_TRUE;
				else 
					return GL_FALSE;
			}

			return GL_TRUE;
		}
		crDebug("Using native GL, app window doesn't meet minimum_window_size");
		return GL_FALSE;
	}
	else if (stub.matchWindowTitle) {
		/* If the user's specified a window title for Chromium, see if this
		 * window satisfies that criterium.
		 */
		GLboolean wildcard = GL_FALSE;
		char title[1000];
		char *titlePattern;
		int len;
		/* check for leading '*' wildcard */
		if (stub.matchWindowTitle[0] == '*') {
			titlePattern = crStrdup( stub.matchWindowTitle + 1 );
			wildcard = GL_TRUE;
		}
		else {
			titlePattern = crStrdup( stub.matchWindowTitle );
		}
		/* check for trailing '*' wildcard */
		len = crStrlen(titlePattern);
		if (len > 0 && titlePattern[len - 1] == '*') {
			titlePattern[len - 1] = '\0'; /* terminate here */
			wildcard = GL_TRUE;
		}

		GetWindowTitle( window, title );
		if (title[0]) {
			if (wildcard) {
				if (crStrstr(title, titlePattern)) {
					crFree(titlePattern);
					return GL_TRUE;
				}
			}
			else if (crStrcmp(title, titlePattern) == 0) {
				crFree(titlePattern);
				return GL_TRUE;
			}
		}
		crFree(titlePattern);
		crDebug("Using native GL, app window title doesn't match match_window_title string (\"%s\" != \"%s\")", title, stub.matchWindowTitle);
		return GL_FALSE;
	}

	/* Window title and size don't matter */
	CRASSERT(stub.minChromiumWindowWidth == 0);
	CRASSERT(stub.minChromiumWindowHeight == 0);
	CRASSERT(stub.matchWindowTitle == NULL);

	/* User hasn't specified a width/height or window title.
	 * We'll use chromium for this window (and context) if no other is.
	 */

	return GL_TRUE;  /* use Chromium! */
}
Ejemplo n.º 12
0
void FocusedAXObserverCallback(AXObserverRef Observer, AXUIElementRef Element, CFStringRef Notification, void *ContextData)
{
    pthread_mutex_lock(&KWMThread.Lock);

    window_info *Window = KWMFocus.Window;
    if(Window && CFEqual(Notification, kAXTitleChangedNotification))
        Window->Name = GetWindowTitle(Element);
    else if(CFEqual(Notification, kAXFocusedWindowChangedNotification))
    {
        if(!Window || Window->WID != GetWindowIDFromRef(Element))
        {
            window_info *OSXWindow = GetWindowByID(GetWindowIDFromRef(Element));
            screen_info *OSXScreen = GetDisplayOfWindow(OSXWindow);
            if(OSXWindow && OSXScreen)
            {
                screen_info *ScreenOfWindow = GetDisplayOfWindow(Window);
                bool SameScreen = ScreenOfWindow == OSXScreen;
                if(ScreenOfWindow && !SameScreen)
                    UpdateActiveWindowList(ScreenOfWindow);

                if(ScreenOfWindow && Window &&
                   GetWindowByID(Window->WID) == NULL &&
                   !SameScreen)
                {
                    space_info *SpaceOfWindow = GetActiveSpaceOfScreen(ScreenOfWindow);
                    if(SpaceOfWindow->Settings.Mode == SpaceModeBSP)
                        RemoveWindowFromBSPTree(ScreenOfWindow, Window->WID, false, false);
                    else if(SpaceOfWindow->Settings.Mode == SpaceModeMonocle)
                        RemoveWindowFromMonocleTree(ScreenOfWindow, Window->WID, false, false);

                    SpaceOfWindow->FocusedWindowID = 0;
                }

                if(!SameScreen)
                    GiveFocusToScreen(OSXScreen->ID, NULL, false, false);

                SetKwmFocus(Element);
                if(SameScreen && !IsFocusedWindowFloating())
                    KWMFocus.InsertionPoint = KWMFocus.Cache;
            }
        }
    }
    else if(CFEqual(Notification, kAXWindowResizedNotification) ||
            CFEqual(Notification, kAXWindowMovedNotification))
    {
        if(KWMTiling.LockToContainer)
            LockWindowToContainerSize(Window);

        UpdateBorder("focused");
        if(Window && Window->WID == KWMScreen.MarkedWindow)
            UpdateBorder("marked");
    }
    else if(CFEqual(Notification, kAXUIElementDestroyedNotification) ||
            CFEqual(Notification, kAXWindowMiniaturizedNotification))
    {
        UpdateBorder("focused");
        if(Window && Window->WID == KWMScreen.MarkedWindow)
            ClearMarkedWindow();
    }

    pthread_mutex_unlock(&KWMThread.Lock);
}
Ejemplo n.º 13
0
wstring MediaPlayers::GetTitleFromBrowser(HWND hwnd) {
    int stream_provider = STREAM_UNKNOWN;
    int web_engine = WEBENGINE_UNKNOWN;

    // Get window title
    wstring title = GetWindowTitle(hwnd);
    EditTitle(title, index);

    // Return current title if the same web page is still open
    if (CurrentEpisode.anime_id > 0)
        if (InStr(title, current_title) > -1)
            return current_title;

    // Delay operation to save some CPU
    static int counter = 0;
    if (counter < 5) {
        counter++;
        return current_title;
    } else {
        counter = 0;
    }

    // Select web browser engine
    if (items.at(index).engine == L"WebKit") {
        web_engine = WEBENGINE_WEBKIT;
    } else if (items.at(index).engine == L"Gecko") {
        web_engine = WEBENGINE_GECKO;
    } else if (items.at(index).engine == L"Trident") {
        web_engine = WEBENGINE_TRIDENT;
    } else if (items.at(index).engine == L"Presto") {
        web_engine = WEBENGINE_PRESTO;
    } else {
        return L"";
    }

    // Build accessibility data
    acc_obj.children.clear();
    if (acc_obj.FromWindow(hwnd) == S_OK) {
        acc_obj.BuildChildren(acc_obj.children, nullptr, web_engine);
        acc_obj.Release();
    }

    // Check other tabs
    if (CurrentEpisode.anime_id > 0) {
        AccessibleChild* child = nullptr;
        switch (web_engine) {
        case WEBENGINE_WEBKIT:
        case WEBENGINE_GECKO:
            child = FindAccessibleChild(acc_obj.children, L"", L"page tab list");
            break;
        case WEBENGINE_TRIDENT:
            child = FindAccessibleChild(acc_obj.children, L"Tab Row", L"");
            break;
        case WEBENGINE_PRESTO:
            child = FindAccessibleChild(acc_obj.children, L"", L"client");
            break;
        }
        if (child) {
            for (auto it = child->children.begin(); it != child->children.end(); ++it) {
                if (InStr(it->name, current_title) > -1) {
                    // Tab is still open, just not active
                    return current_title;
                }
            }
        }
        // Tab is closed
        return L"";
    }

    // Find URL
    AccessibleChild* child = nullptr;
    switch (web_engine) {
    case WEBENGINE_WEBKIT:
        child = FindAccessibleChild(acc_obj.children, L"Address and search bar", L"grouping");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Address", L"grouping");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Location", L"grouping");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Address field", L"editable text");
        break;
    case WEBENGINE_GECKO:
        child = FindAccessibleChild(acc_obj.children, L"Search or enter address", L"editable text");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Go to a Website", L"editable text");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Go to a Web Site", L"editable text");
        break;
    case WEBENGINE_TRIDENT:
        child = FindAccessibleChild(acc_obj.children, L"Address and search using Bing", L"editable text");
        if (child == nullptr)
            child = FindAccessibleChild(acc_obj.children, L"Address and search using Google", L"editable text");
        break;
    case WEBENGINE_PRESTO:
        child = FindAccessibleChild(acc_obj.children, L"", L"client");
        if (child && !child->children.empty()) {
            child = FindAccessibleChild(child->children.at(0).children, L"", L"tool bar");
            if (child && !child->children.empty()) {
                child = FindAccessibleChild(child->children, L"", L"combo box");
                if (child && !child->children.empty()) {
                    child = FindAccessibleChild(child->children, L"", L"editable text");
                }
            }
        }
        break;
    }

    // Check URL for known streaming video providers
    if (child) {
        // Anime News Network
        if (Settings.Recognition.Streaming.ann_enabled &&
                InStr(child->value, L"animenewsnetwork.com/video") > -1) {
            stream_provider = STREAM_ANN;
            // Crunchyroll
        } else if (Settings.Recognition.Streaming.crunchyroll_enabled &&
                   InStr(child->value, L"crunchyroll.com/") > -1) {
            stream_provider = STREAM_CRUNCHYROLL;
            // Hulu
            /*
            } else if (InStr(child->value, L"hulu.com/watch") > -1) {
              stream_provider = STREAM_HULU;
            */
            // Veoh
        } else if (Settings.Recognition.Streaming.veoh_enabled &&
                   InStr(child->value, L"veoh.com/watch") > -1) {
            stream_provider = STREAM_VEOH;
            // Viz Anime
        } else if (Settings.Recognition.Streaming.viz_enabled &&
                   InStr(child->value, L"vizanime.com/ep") > -1) {
            stream_provider = STREAM_VIZANIME;
            // YouTube
        } else if (Settings.Recognition.Streaming.youtube_enabled &&
                   InStr(child->value, L"youtube.com/watch") > -1) {
            stream_provider = STREAM_YOUTUBE;
        }
    }

    // Clean-up title
    switch (stream_provider) {
    // Anime News Network
    case STREAM_ANN:
        EraseRight(title, L" - Anime News Network");
        Erase(title, L" (s)");
        Erase(title, L" (d)");
        break;
    // Crunchyroll
    case STREAM_CRUNCHYROLL:
        EraseLeft(title, L"Crunchyroll - Watch ");
        break;
    // Hulu
    case STREAM_HULU:
        EraseLeft(title, L"Watch ");
        EraseRight(title, L" online | Free | Hulu");
        EraseRight(title, L" online | Plus | Hulu");
        break;
    // Veoh
    case STREAM_VEOH:
        EraseLeft(title, L"Watch Videos Online | ");
        EraseRight(title, L" | Veoh.com");
        break;
    // Viz Anime
    case STREAM_VIZANIME:
        EraseRight(title, L" - VIZ ANIME: Free Online Anime - All The Time");
        break;
    // YouTube
    case STREAM_YOUTUBE:
        EraseRight(title, L" - YouTube");
        break;
    // Some other website, or URL is not found
    case STREAM_UNKNOWN:
        title.clear();
        break;
    }

    return title;
}
Ejemplo n.º 14
0
void KPSdl12UserInterface::OpenWindow(int /* argc */ , char ** /* argv */)
{
    auto flags = SDL_OPENGL | SDL_RESIZABLE;

    BLogger::Log("SDL UserInterface initialization");
    auto pVersion = SDL_Linked_Version();
    BLogger::Log("SDL Linked version: ",
                 static_cast<unsigned int>(pVersion->major), '.',
                 static_cast<unsigned int>(pVersion->minor), '.',
                 static_cast<unsigned int>(pVersion->patch));
    BLogger::Log("SDL Header version: ",
                 SDL_MAJOR_VERSION, '.', SDL_MINOR_VERSION, '.',
                 SDL_PATCHLEVEL);
    pVersion = Mix_Linked_Version();
    BLogger::Log("SDL_mixer Linked version: ",
                 static_cast<unsigned int>(pVersion->major), '.',
                 static_cast<unsigned int>(pVersion->minor), '.',
                 static_cast<unsigned int>(pVersion->patch));
    BLogger::Log("SDL_mixer Header version: ",
                 MIX_MAJOR_VERSION, '.', MIX_MINOR_VERSION, '.',
                 MIX_PATCHLEVEL);

    // Open OpenGL Window with SDL
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) < 0)
    {
        std::stringstream message;

        message << "Error in SDL_Init: " << SDL_GetError();
        throw std::runtime_error(message.str());
    }

    // Full-screen mode is not supported. Disable full-screen flag.
    config->FullScreen = false;

    if (!IsWindowResolutionSupported(config->ScreenXResolution,
                                     (config->ScreenXResolution * 3) / 4))
    {
        config->ScreenXResolution = 640;
    }

    screen = SDL_SetVideoMode(
                 config->ScreenXResolution,
                 (config->ScreenXResolution * 3) / 4,
                 config->ColorDepth,
                 flags);

    if (screen == nullptr)
    {
        std::stringstream message;

        message << "Error in SDL_SetVideoMode: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    SDL_WM_SetCaption(GetWindowTitle().c_str(), GetWindowTitle().c_str());

    DebugPrintOpenGLVersion();
    InitializeAudio(config->TextureName);
    InitializeAfterOpen();
}
Ejemplo n.º 15
0
void SFMLWorld::RunWorld(void)
{
    contextSettings = GenerateContext();
	window = new sf::RenderWindow(GetModeToUse(windowWidth, windowHeight),
                                  GetWindowTitle().c_str(),
                                  GetSFStyleFlags(), contextSettings);
	Clock cl = Clock();

	totalElapsedSeconds = 0.0f;
	worldOver = false;
	float elapsed;
	sf::Event windowEvent;

	InitializeWorld();
    windowHasFocus = true;

	cl.restart();

	while (window->isOpen() && !worldOver)
	{
		//Handle window events first.
		while (window->pollEvent(windowEvent))
		{
			if (windowEvent.type == sf::Event::Closed)
			{
				OnCloseWindow();

			}
			else if (windowEvent.type == sf::Event::Resized)
			{
				OnWindowResized(windowEvent.size.width, windowEvent.size.height);
			}
            else if (windowEvent.type == sf::Event::LostFocus)
            {
                windowHasFocus = false;
                OnWindowLostFocus();
            }
            else if (windowEvent.type == sf::Event::GainedFocus)
            {
                windowHasFocus = true;
                OnWindowGainedFocus();
            }
			else
			{
				OnOtherWindowEvent(windowEvent);
			}
		}

		//Get elapsed time.
		elapsed = cl.getElapsedTime().asSeconds();
		cl.restart();
		totalElapsedSeconds += elapsed;

        //Update various managers.
        Input.Update(elapsed, totalElapsedSeconds);
        Timers.UpdateTimers(elapsed);

		//Update and render.
		if (elapsed > 0.0f)
		{
			UpdateWorld(elapsed);

			RenderWorld(elapsed);
		}
	}

	OnWorldEnd();

    delete window;
    window = 0;
}
Ejemplo n.º 16
0
bool emX11WindowPort::Cycle()
{
	XWindowAttributes attr;
	XSizeHints xsh;
	emString str;
	emCursor cur;
	::Window win;
	::Cursor xcur;
	emX11WindowPort * wp;
	double vrx,vry,vrw,vrh,fx,fy,fw,fh;
	int i,x,y,w,h;
	Status xs;

	if (
		FullscreenUpdateTimer &&
		IsSignaled(FullscreenUpdateTimer->GetSignal())
	) {
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		if (
			fabs(PaneX-vrx)>0.51 || fabs(PaneY-vry)>0.51 ||
			fabs(PaneW-vrw)>0.51 || fabs(PaneH-vrh)>0.51
		) {
			PosForced=true;
			PosPending=true;
			SizeForced=true;
			SizePending=true;
			SetViewGeometry(vrx,vry,vrw,vrh,Screen.PixelTallness);
		}

		// Workaround for lots of focus problems with several window managers:
		if (Screen.GrabbingWinPort==this) {
			XMutex.Lock();
			XGetInputFocus(Disp,&win,&i);
			XMutex.Unlock();
			wp=NULL;
			for (i=Screen.WinPorts.GetCount()-1; i>=0; i--) {
				if (Screen.WinPorts[i]->Win==win) {
					wp=Screen.WinPorts[i];
					break;
				}
			}
			if (wp==this) {
				if (!Focused) {
					Focused=true;
					SetViewFocused(true);
					emWarning("emX11WindowPort: Focus workaround 1 applied.");
				}
			}
			else {
				while (wp) {
					if (wp==this) break;
					wp=wp->Owner;
				}
				if (!wp) {
					XMutex.Lock();
					xs=XGetWindowAttributes(Disp,Win,&attr);
					XMutex.Unlock();
					if (xs && attr.map_state==IsViewable) {
						XMutex.Lock();
						XSetInputFocus(Disp,Win,RevertToNone,CurrentTime);
						XMutex.Unlock();
						emWarning("emX11WindowPort: Focus workaround 2 applied.");
					}
				}
			}
		}
	}

	if (
		!PostConstructed && !PosForced && Owner &&
		(GetWindowFlags()&emWindow::WF_FULLSCREEN)==0
	) {
		Screen.GetVisibleRect(&vrx,&vry,&vrw,&vrh);
		fx=Owner->GetViewX()-Owner->BorderL;
		fy=Owner->GetViewY()-Owner->BorderT;
		fw=Owner->GetViewWidth()+Owner->BorderL+Owner->BorderR;
		fh=Owner->GetViewHeight()+Owner->BorderT+Owner->BorderB;
		fx+=fw*0.5;
		fy+=fh*0.5;
		fw=GetViewWidth()+BorderL+BorderR;
		fh=GetViewHeight()+BorderT+BorderB;
		fx-=fw*0.5+emGetDblRandom(-0.03,0.03)*vrw;
		fy-=fh*0.5+emGetDblRandom(-0.03,0.03)*vrh;
		if (fx>vrx+vrw-fw) fx=vrx+vrw-fw;
		if (fy>vry+vrh-fh) fy=vry+vrh-fh;
		if (fx<vrx) fx=vrx;
		if (fy<vry) fy=vry;
		SetViewGeometry(
			fx+BorderL,fy+BorderT,
			GetViewWidth(),GetViewHeight(),
			Screen.PixelTallness
		);
		PosPending=true;
		PosForced=true;
	}

	if (PosPending || SizePending) {
		x=((int)GetViewX())-BorderL;
		y=((int)GetViewY())-BorderT;
		w=(int)GetViewWidth();
		h=(int)GetViewHeight();
		memset(&xsh,0,sizeof(xsh));
		xsh.flags     =PMinSize;
		xsh.min_width =MinPaneW;
		xsh.min_height=MinPaneH;
		if (PosForced) {
			xsh.flags|=PPosition|USPosition;
			xsh.x=x;
			xsh.y=y;
		}
		if (SizeForced) {
			xsh.flags|=PSize|USSize;
			xsh.width=w;
			xsh.height=h;
		}
		XMutex.Lock();
		XSetWMNormalHints(Disp,Win,&xsh);
		if (PosPending && SizePending) {
			XMoveResizeWindow(Disp,Win,x,y,w,h);
		}
		else if (PosPending) {
			XMoveWindow(Disp,Win,x,y);
		}
		else {
			XResizeWindow(Disp,Win,w,h);
		}
		XMutex.Unlock();
		PosPending=false;
		SizePending=false;
	}

	if (TitlePending) {
		str=GetWindowTitle();
		if (Title!=str) {
			Title=str;
			XMutex.Lock();
			XmbSetWMProperties(Disp,Win,Title.Get(),NULL,NULL,0,NULL,NULL,NULL);
			XMutex.Unlock();
		}
		TitlePending=false;
	}

	if (IconPending) {
		SetIconProperty(GetWindowIcon());
		IconPending=false;
	}

	if (CursorPending) {
		cur=GetViewCursor();
		if (Cursor!=cur) {
			Cursor=cur;
			xcur=Screen.GetXCursor(cur);
			XMutex.Lock();
			XDefineCursor(Disp,Win,xcur);
			XMutex.Unlock();
		}
		CursorPending=false;
	}

	if (!PostConstructed) {
		PostConstruct();
		PostConstructed=true;
	}

	if (!InvalidRects.IsEmpty() && Mapped) {
		UpdatePainting();
		if (!LaunchFeedbackSent) {
			LaunchFeedbackSent=true;
			SendLaunchFeedback();
		}
	}

	return false;
}
Ejemplo n.º 17
0
/**
 *  Erstellt das Fenster mit entsprechenden Werten.
 *
 *  @param[in] width      Breite des Fensters
 *  @param[in] height     Höhe des Fensters
 *  @param[in] fullscreen Vollbildmodus ja oder nein
 *
 *  @return @p true bei Erfolg, @p false bei Fehler
 *
 *  @bug Hardwarecursor ist bei Fenstermodus sichtbar,
 *       Cursor deaktivieren ist fehlerhaft
 *
 *  @author FloSoft
 */
bool VideoWinAPI::CreateScreen(unsigned short width, unsigned short height, const bool fullscreen)
{
    if(!initialized)
        return false;

    std::wstring wTitle = AnsiToUtf8(GetWindowTitle());

    WNDCLASSW  wc;
    wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc      = WindowProc;
    wc.cbClsExtra       = 0;
    wc.cbWndExtra       = 0;
    wc.hInstance        = GetModuleHandle(NULL);
    wc.hIcon            = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_SYMBOL));
    wc.hCursor          = NULL;
    wc.hbrBackground    = NULL;
    wc.lpszMenuName     = NULL;
    wc.lpszClassName    = wTitle.c_str();

    // Fensterklasse registrieren
    if (!RegisterClassW(&wc))
        return false;

    DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    DWORD dwStyle   = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;

    if(fullscreen)
    {
        dwExStyle   = WS_EX_APPWINDOW;
        dwStyle     = WS_POPUP;

        EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &dm_prev);
    }
    else
    {
        // Bei Fensteranwendung die Breiten und Hoehen der Fensterrahmen, Titelleiste draufaddieren
        width += 2 * GetSystemMetrics(SM_CXFIXEDFRAME);
        height += 2 * GetSystemMetrics(SM_CXFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION);
    }

    // Fenster erstellen
    screen = CreateWindowExW(dwExStyle, wTitle.c_str(), wTitle.c_str(), dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, GetModuleHandle(NULL), NULL);

    if(screen == NULL)
        return false;

    SetClipboardViewer(screen);

    std::stringstream title;
    title << GetWindowTitle() << " - v" << GetWindowVersion() << "-" << GetWindowRevisionShort();

    wTitle = AnsiToUtf8(title.str().c_str());

    SetWindowTextW(screen, wTitle.c_str());
    SetWindowTextW(GetConsoleWindow(), wTitle.c_str());

    // Pixelformat zuweisen
    GLuint PixelFormat;
    static PIXELFORMATDESCRIPTOR pfd =
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,
        8, // 8 Bit
        8, // red
        0,
        8, // green
        0,
        8, // blue
        0,
        8, // alpha
        0,
        0,
        0,
        0,
        0,
        0,
        32, // 32 Bit
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0,
        0,
        0
    };

    screen_dc = GetDC(screen);
    if(screen_dc == NULL)
        return false;

    // Pixelformat auswaehlen
    PixelFormat = ChoosePixelFormat(screen_dc, &pfd);
    if(PixelFormat == 0)
        return false;

    // Pixelformat zuweisen
    if(!SetPixelFormat(screen_dc, PixelFormat, &pfd))
        return false;

    // Renderingkontext erstellen
    screen_rc = wglCreateContext(screen_dc);
    if(screen_rc == NULL)
        return false;

    // Renderingkontext aktivieren
    if(!wglMakeCurrent(screen_dc, screen_rc))
        return false;

    // Mauscursor ausblenden
    ShowCursor(FALSE);

    // Bei Fullscreen Aufloesung umstellen
    if(fullscreen)
    {
        // Aktuelle Framerate holen und die spaeter dann benutzen
        DEVMODE prev;
        EnumDisplaySettings(0, ENUM_CURRENT_SETTINGS, &prev);

        DEVMODE dm;
        memset(&dm, 0, sizeof(dm));
        dm.dmSize = sizeof(dm);
        dm.dmFields = DM_DISPLAYFREQUENCY | DM_PELSWIDTH | DM_PELSHEIGHT;
        dm.dmDisplayFrequency = prev.dmDisplayFrequency;
        dm.dmPelsWidth = width;
        dm.dmPelsHeight = height;

        ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
    }

    this->screenWidth  = width;
    this->screenHeight = height;
    this->isFullscreen_ = fullscreen;

    // Das Fenster anzeigen
    ShowWindow(screen, SW_SHOW);
    // Das Fenster in den Vordergrund rcken
    SetForegroundWindow(screen);
    // Dem Fenster den Eingabefokus geben
    SetFocus(screen);

    return true;
}
Ejemplo n.º 18
0
 std::wstring WidgetDelegate::GetAccessibleWindowTitle() const
 {
     return GetWindowTitle();
 }
Ejemplo n.º 19
0
void KPSdl2UserInterface::OpenWindow(int /* argc */ , char ** /* argv */)
{
    auto flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
    SDL_version compiled;
    SDL_version linked;
    std::stringstream message;

    SDL_VERSION(&compiled);
    SDL_GetVersion(&linked);

    BLogger::Log("SDL UserInterface initialization");
    BLogger::Log("SDL linked version: ",
                 static_cast<unsigned int>(linked.major), '.',
                 static_cast<unsigned int>(linked.minor), '.',
                 static_cast<unsigned int>(linked.patch));
    BLogger::Log("SDL compiled version: ",
                 static_cast<unsigned int>(compiled.major), '.',
                 static_cast<unsigned int>(compiled.minor), '.',
                 static_cast<unsigned int>(compiled.patch));
    BLogger::Log("SDL Header version: ",
                 SDL_MAJOR_VERSION, '.', SDL_MINOR_VERSION, '.',
                 SDL_PATCHLEVEL);
    BLogger::Log("SDL Revision: ", SDL_GetRevision());
    auto pVersion = Mix_Linked_Version();
    BLogger::Log("SDL_mixer Linked version: ",
                 static_cast<unsigned int>(pVersion->major), '.',
                 static_cast<unsigned int>(pVersion->minor), '.',
                 static_cast<unsigned int>(pVersion->patch));
    BLogger::Log("SDL_mixer Header version: ",
                 MIX_MAJOR_VERSION, '.', MIX_MINOR_VERSION, '.',
                 MIX_PATCHLEVEL);

    // Set OpenGL's context to 2.1 subset functionality profile.
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);

    // Open OpenGL Window with SDL
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
    {
        message << "Error in SDL_Init: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    if (config->FullScreen)
    {
        flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    }

    if (!IsWindowResolutionSupported(config->ScreenXResolution,
                                     (config->ScreenXResolution * 3) / 4))
    {
        config->ScreenXResolution = 640;
    }

    window = SDL_CreateWindow(
                 GetWindowTitle().c_str(),
                 SDL_WINDOWPOS_UNDEFINED,
                 SDL_WINDOWPOS_UNDEFINED,
                 config->ScreenXResolution,
                 (config->ScreenXResolution * 3) / 4,
                 flags);

    if (window == nullptr)
    {
        message << "Error in SDL_CreateWindow: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    // We intentionally do not use the SDL renderer. It only supports 2D
    // and on Windows would use DirectX and not the OpenGL backend.
    // Instead the OpenGL renderer is used together with ligGLEW.
    glContext = SDL_GL_CreateContext(window);

    if (glContext == nullptr)
    {
        message << "Error in SDL_GL_CreateContext: " << SDL_GetError();
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    // Do updates synchronized with VSync
    SDL_GL_SetSwapInterval(1);

    auto glewReturn = glewInit();

    if (glewReturn != GLEW_OK)
    {
        message << "Error in glewInit: " << glewGetErrorString(glewReturn);
        SDL_Quit();
        throw std::runtime_error(message.str());
    }

    BLogger::Log("GLEW version: ", glewGetString(GLEW_VERSION));

    SDL_DisplayMode mode;

    SDL_GetWindowDisplayMode(window, &mode);
    BLogger::Log("SDL pixel format: ", SDL_GetPixelFormatName(mode.format));
    BLogger::Log("SDL refresh rate: ", mode.refresh_rate, " Hz");

    DebugPrintOpenGLVersion();
    DebugPrintOpenGLContextVersion();
    InitializeAudio(config->TextureName);
    InitializeAfterOpen();
}
Ejemplo n.º 20
0
BOOL CALLBACK DlgProcParentWindow(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DWORD ws;
	struct ParentWindowData *dat;
	dat = (struct ParentWindowData *) GetWindowLong(hwndDlg, GWL_USERDATA);
	if (!dat && msg!=WM_INITDIALOG) return FALSE;
	switch (msg) {
	case WM_INITDIALOG:
		{
			HMENU hMenu;
			HANDLE hSContact;
			int savePerContact = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT);
			struct NewMessageWindowLParam *newData = (struct NewMessageWindowLParam *) lParam;
			dat = (struct ParentWindowData *) malloc(sizeof(struct ParentWindowData));
			dat->foregroundWindow = GetForegroundWindow();
			dat->hContact = newData->hContact;
			dat->nFlash = 0;
			dat->nFlashMax = DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_FLASHCOUNT, SRMSGDEFSET_FLASHCOUNT);
			dat->childrenCount = 0;
			dat->children = NULL;
			dat->hwnd = hwndDlg;
			dat->flags = g_dat->flags;// | SMF_SHOWTITLEBAR;
			dat->mouseLBDown = 0;
			dat->windowWasCascaded = 0;
			dat->bMinimized = 0;
			dat->hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hwndDlg, NULL, g_hInst, NULL);
			{
				int statwidths[4];
				RECT rc;
				SendMessage(dat->hwndStatus, SB_SETMINHEIGHT, GetSystemMetrics(SM_CYSMICON), 0);
				GetWindowRect(dat->hwndStatus, &rc);
				/*
				statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH - SB_SENDING_WIDTH;
				statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH - SB_SENDING_WIDTH; //rc.right - rc.left - SB_CHAR_WIDTH;
				statwidths[2] = rc.right - rc.left - SB_TYPING_WIDTH; //rc.right - rc.left - SB_CHAR_WIDTH;
				statwidths[3] = -1;
				SendMessage(dat->hwndStatus, SB_SETPARTS, 4, (LPARAM) statwidths);
				*/
				statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH;
				statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH;
				statwidths[2] = -1;
				SendMessage(dat->hwndStatus, SB_SETPARTS, 3, (LPARAM) statwidths);
			}
			dat->hwndTabs = GetDlgItem(hwndDlg, IDC_TABS);
			dat->hwndActive = NULL;
			SetWindowLong(hwndDlg, GWL_USERDATA, (LONG) dat);
			if (g_dat->hIconList != NULL) {
				TabCtrl_SetImageList(dat->hwndTabs, g_dat->hIconList);
			}
			WindowList_Add(g_dat->hParentWindowList, hwndDlg, 0);
			dat->tabCtrlDat = (struct TabCtrlData *) malloc(sizeof(struct TabCtrlData));
			dat->tabCtrlDat->bDragging = FALSE;
			SetWindowLong(dat->hwndTabs, GWL_USERDATA, (LONG) dat->tabCtrlDat);
			OldTabCtrlProc = (WNDPROC) SetWindowLong(dat->hwndTabs, GWL_WNDPROC, (LONG) TabCtrlProc);
			ws = GetWindowLong(dat->hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM);
			if (dat->flags & SMF_TABSATBOTTOM) {
				ws |= TCS_BOTTOM;
			}
			SetWindowLong(dat->hwndTabs, GWL_STYLE, ws);
			ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION);
			if (dat->flags & SMF_SHOWTITLEBAR) {
				ws |= WS_CAPTION;
				SetWindowLong(hwndDlg, GWL_STYLE, ws);
			} else {
				RECT rc;
				SetWindowLong(hwndDlg, GWL_STYLE, ws);
				GetWindowRect(hwndDlg, &rc);
				SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
							 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER  | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
			}
			ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
			ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
			SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
			if (dat->flags & SMF_USETRANSPARENCY) {
   				pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}
			if (!(dat->flags & SMF_SHOWSTATUSBAR)) {
				ShowWindow(dat->hwndStatus, SW_HIDE);
			}
			hSContact = !(dat->flags & SMF_USETABS) && savePerContact ? dat->hContact : NULL;
			dat->bTopmost = DBGetContactSettingByte(hSContact, SRMMMOD, SRMSGSET_TOPMOST, SRMSGDEFSET_TOPMOST);
			if (ScriverRestoreWindowPosition(hwndDlg, hSContact, SRMMMOD, "", 0, SW_HIDE)) {
				if (ScriverRestoreWindowPosition(hwndDlg, hSContact, SRMMMOD, "", RWPF_NOSIZE, SW_HIDE)) {
					SetWindowPos(GetParent(hwndDlg), 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_HIDEWINDOW);
				} else {
					SetWindowPos(hwndDlg, 0, 0, 0, 450, 300, SWP_NOZORDER | SWP_NOMOVE | SWP_HIDEWINDOW);
				}
			}
			if (!(dat->flags & SMF_USETABS)) {
				if (!savePerContact && DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_CASCADE, SRMSGDEFSET_CASCADE))
					WindowList_Broadcast(g_dat->hParentWindowList, DM_CASCADENEWWINDOW, (WPARAM) hwndDlg, (LPARAM) & dat->windowWasCascaded);
			}
			hMenu = GetSystemMenu( hwndDlg, FALSE );
			AppendMenu( hMenu, MF_SEPARATOR, 0, NULL );
			if (dat->bTopmost) {
				AppendMenu( hMenu, MF_ENABLED | MF_CHECKED | MF_STRING, IDM_TOPMOST, TranslateT("Always On Top"));
                SetWindowPos(hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
			} else {
				AppendMenu( hMenu, MF_ENABLED | MF_UNCHECKED | MF_STRING, IDM_TOPMOST, TranslateT("Always On Top"));
			}
		}
		return TRUE;
	case WM_GETMINMAXINFO:
	{
		MINMAXINFO *mmi = (MINMAXINFO *) lParam;
		SIZE size;
		if (GetKeyState(VK_CONTROL) & 0x8000) {
			WINDOWPLACEMENT wp;
			RECT rcDesktop;
			wp.length = sizeof(wp);
			GetWindowPlacement(hwndDlg, &wp);
			SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0);
			mmi->ptMaxSize.x = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
			mmi->ptMaxSize.y = rcDesktop.bottom - rcDesktop.top;
			mmi->ptMaxPosition.x = wp.rcNormalPosition.left;
			if(IsIconic(hwndDlg)) {
				mmi->ptMaxPosition.y = rcDesktop.top;
			} else {
				mmi->ptMaxPosition.y = 0;
			}
		}
		GetMinimunWindowSize(dat, &size);
		mmi->ptMinTrackSize.x = size.cx;
		mmi->ptMinTrackSize.y = size.cy;
		return FALSE;
	}

	case WM_SIZE:
		if (wParam == SIZE_MINIMIZED) {
			dat->bMinimized = 1;

		}
		if (IsIconic(hwndDlg))	{
			MoveWindow(dat->hwndActive, dat->childRect.left, dat->childRect.top, dat->childRect.right-dat->childRect.left, dat->childRect.bottom - dat->childRect.top, TRUE);
		} else {
//		}
//		if (!IsIconic(hwndDlg)) {
			int i;
			RECT rc, rcStatus, rcChild, rcWindow;
			SIZE size;
			dat->bMinimized = 0;
			GetClientRect(hwndDlg, &rc);
			GetWindowRect(hwndDlg, &rcWindow);
			rcStatus.top = rcStatus.bottom = 0;
			if (dat->flags & SMF_SHOWSTATUSBAR) {
				int statwidths[4];
				GetWindowRect(dat->hwndStatus, &rcStatus);
				statwidths[0] = rc.right - rc.left - SB_CHAR_WIDTH - SB_TYPING_WIDTH;
				statwidths[1] = rc.right - rc.left - SB_TYPING_WIDTH;
				statwidths[2] = -1;
				SendMessage(dat->hwndStatus, SB_SETPARTS, 3, (LPARAM) statwidths);
				SendMessage(dat->hwndStatus, WM_SIZE, 0, 0);
			}
			MoveWindow(dat->hwndTabs, 0, 2, (rc.right - rc.left), (rc.bottom - rc.top) - (rcStatus.bottom - rcStatus.top) - 2,	FALSE);
			RedrawWindow(dat->hwndTabs, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ERASE);
			GetMinimunWindowSize(dat, &size);
			if ((rcWindow.bottom-rcWindow.top) < size.cy || (rcWindow.right-rcWindow.left) < size.cx) {
				if ((rcWindow.bottom-rcWindow.top) < size.cy) {
					rcWindow.bottom = rcWindow.top + size.cy;
				}
				if ((rcWindow.right-rcWindow.left) < size.cx) {
					rcWindow.right = rcWindow.left + size.cx;
				}
				MoveWindow(hwndDlg, rcWindow.left, rcWindow.top, rcWindow.right - rcWindow.left, rcWindow.bottom - rcWindow.top,	TRUE);
			}
			GetChildWindowRect(dat, &rcChild);
			memcpy(&dat->childRect, &rcChild, sizeof(RECT));
			for (i=0;i<dat->childrenCount;i++) {
				if (dat->children[i] == dat->hwndActive) {
					MoveWindow(dat->children[i], rcChild.left, rcChild.top, rcChild.right-rcChild.left, rcChild.bottom - rcChild.top, TRUE);
					RedrawWindow(GetDlgItem(dat->children[i], IDC_LOG), NULL, NULL, RDW_INVALIDATE);
				}
			}
			if (dat->flags & SMF_SHOWSTATUSBAR) {
				RedrawWindow(dat->hwndStatus, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
			}
		}
		return FALSE;
	case WM_SETFOCUS:
		if (dat->hwndActive != NULL) {
			SetFocus(dat->hwndActive);
		}
		return TRUE;
	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDCANCEL:
			//DestroyWindow(hwndDlg);
			return TRUE;
		}
	case WM_NOTIFY:
		{
			NMHDR* pNMHDR = (NMHDR*) lParam;
			if (pNMHDR->hwndFrom == dat->hwndTabs) {
				switch (pNMHDR->code) {
				case TCN_SELCHANGE:
					{
						TCITEM tci = {0};
						int iSel = TabCtrl_GetCurSel(dat->hwndTabs);
						tci.mask = TCIF_PARAM;
						if (TabCtrl_GetItem(dat->hwndTabs, iSel, &tci)) {
							struct MessageWindowData * mdat = (struct MessageWindowData *) tci.lParam;
							ActivateChild(dat, mdat->hwnd);
							SetFocus(dat->hwndActive);
						}
					}
					break;
				case NM_RCLICK:
					{
						TCHITTESTINFO thinfo;
						int tabId, x, y;
						GetCursorPos(&thinfo.pt);
						x = thinfo.pt.x;
						y = thinfo.pt.y;
						ScreenToClient(dat->hwndTabs, &thinfo.pt);
						tabId = TabCtrl_HitTest(dat->hwndTabs, &thinfo);
						if (tabId != -1) {
							struct MessageWindowData * mwd = GetChildFromTab(dat->hwndTabs, tabId);
							//CallService(MS_USERINFO_SHOWDIALOG, (WPARAM) mwd->hContact, 0);
							HMENU hMenu = (HMENU) CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM) mwd->hContact, 0);
							TrackPopupMenu(hMenu, 0, x, y, 0, mwd->hwnd, NULL);
							DestroyMenu(hMenu);
						}
					}
					break;
				}
			} else if (pNMHDR->hwndFrom == dat->hwndStatus)  {
				switch (pNMHDR->code) {
				case NM_CLICK:
					{
						NMMOUSE *nm=(NMMOUSE*)lParam;
						RECT rc;
						SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
						if (nm->pt.x >= rc.left)
							SendMessage(dat->hwndActive, DM_SWITCHUNICODE, 0, 0);
					}
				}
				break;
			}
		}
		break;
	case WM_DROPFILES:
		SendMessage(dat->hwndActive, WM_DROPFILES, wParam, lParam);
		break;
	case WM_TIMER:
		if (wParam == TIMERID_FLASHWND) {
			if ((dat->nFlash > dat->nFlashMax)) {// || ((GetActiveWindow() == hwndDlg) && (GetForegroundWindow() == hwndDlg))) {
				KillTimer(hwndDlg, TIMERID_FLASHWND);
				FlashWindow(hwndDlg, FALSE);
			} else if (dat->nFlash < dat->nFlashMax) {
				FlashWindow(hwndDlg, TRUE);
				dat->nFlash++;
			}
		}
		break;
	case WM_CONTEXTMENU:
	{
		if (dat->hwndStatus && dat->hwndStatus == (HWND) wParam) {
			RECT rc;
			POINT pt, pt2;
			GetCursorPos(&pt);
			pt2.x = pt.x;
			pt2.y = pt.y;
			ScreenToClient(dat->hwndStatus, &pt);
			SendMessage(dat->hwndStatus, SB_GETRECT, SendMessage(dat->hwndStatus, SB_GETPARTS, 0, 0) - 1, (LPARAM)&rc);
			if (pt.x >= rc.left && dat->hwndActive != NULL) {
				int codePage = (int) SendMessage(dat->hwndActive, DM_GETCODEPAGE, 0, 0);
				int i, iSel;
				for(i = 0; i < GetMenuItemCount(g_dat->hMenuANSIEncoding); i++) {
					CheckMenuItem (g_dat->hMenuANSIEncoding, i, MF_BYPOSITION | MF_UNCHECKED);
				}
				if(codePage == CP_ACP) {
					CheckMenuItem(g_dat->hMenuANSIEncoding, 0, MF_BYPOSITION | MF_CHECKED);
				} else {
					CheckMenuItem(g_dat->hMenuANSIEncoding, codePage, MF_BYCOMMAND | MF_CHECKED);
				}
				iSel = TrackPopupMenu(g_dat->hMenuANSIEncoding, TPM_RETURNCMD, pt2.x, pt2.y, 0, hwndDlg, NULL);
				if (iSel >= 500) {
					if (iSel == 500) iSel = CP_ACP;
					SendMessage(dat->hwndActive, DM_SETCODEPAGE, 0, iSel);
				}
			}
			else
				SendMessage(dat->hwndActive, WM_CONTEXTMENU, (WPARAM)hwndDlg, 0);
		}
		break;
	}

	case WM_ACTIVATE:
		if (LOWORD(wParam) == WA_INACTIVE) {
			ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
			ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
			SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
			if (dat->flags & SMF_USETRANSPARENCY) {
   				pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}
		}
		if (LOWORD(wParam) != WA_ACTIVE)
			break;
		if (dat->hwndActive == NULL) { // do not set foreground window at all (always stay in the background !)
//			SendMessage(hwndDlg, DM_DEACTIVATE, 0, 0);
		} else {
			PostMessage(hwndDlg, WM_SETFOCUS, 0, 0);
		}
	case WM_MOUSEACTIVATE:
		if (KillTimer(hwndDlg, TIMERID_FLASHWND)) {
			FlashWindow(hwndDlg, FALSE);
			dat->nFlash = 0;
		}
		ws = GetWindowLong(hwndDlg, GWL_EXSTYLE) & ~WS_EX_LAYERED;
		ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
		SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
		if (dat->flags & SMF_USETRANSPARENCY) {
   			pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->activeAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
		}
		break;
	case WM_LBUTTONDOWN:
		if (!IsZoomed(hwndDlg)) {
			POINT pt;
			GetCursorPos(&pt);
		//	dat->mouseLBDown = 1;
		//	GetCursorPos(&dat->mouseLBDownPos);
			return SendMessage(hwndDlg, WM_SYSCOMMAND, SC_MOVE | HTCAPTION, MAKELPARAM(pt.x, pt.y));
		//	SetCapture(hwndDlg);

		}
		break;
	case WM_LBUTTONUP:
		//if (dat->mouseLBDown) {
		//	dat->mouseLBDown = 0;
		//	ReleaseCapture();
		//}
		break;
	case WM_MOUSEMOVE:/*
		if (dat->mouseLBDown) {
			POINT pt;
			RECT  rc;
			GetCursorPos(&pt);
			GetWindowRect(hwndDlg, &rc);
			SetWindowPos(hwndDlg, 0, rc.left - (dat->mouseLBDownPos.x - pt.x), rc.top - (dat->mouseLBDownPos.y - pt.y), 0, 0, SWP_NOZORDER | SWP_NOSIZE);
			dat->mouseLBDownPos = pt;
		}*/
		break;
	case WM_MOVING:
		{
			int snapPixels = 10;
			RECT rcDesktop;
			RECT *pRect = (RECT *)lParam;
			POINT pt;
			SIZE szSize = {pRect->right-pRect->left,pRect->bottom-pRect->top};
			GetCursorPos(&pt);
			SystemParametersInfo(SPI_GETWORKAREA, 0, &rcDesktop, 0);
			pRect->left = pt.x-dat->mouseLBDownPos.x;
			pRect->top = pt.y-dat->mouseLBDownPos.y;
			pRect->right = pRect->left+szSize.cx;
			pRect->bottom = pRect->top+szSize.cy;
            if (!(GetAsyncKeyState(VK_CONTROL) & 0x8000)) {
				if(pRect->top < snapPixels && pRect->top > -snapPixels) {
					pRect->top = 0;
					pRect->bottom = szSize.cy;
				}
				if(pRect->left < snapPixels && pRect->left > -snapPixels) {
					pRect->left = 0;
					pRect->right = szSize.cx;
				}
				if(pRect->right < rcDesktop.right+snapPixels && pRect->right > rcDesktop.right-snapPixels) {
					pRect->right = rcDesktop.right;
					pRect->left = rcDesktop.right-szSize.cx;
				}
				if(pRect->bottom < rcDesktop.bottom+snapPixels && pRect->bottom > rcDesktop.bottom-snapPixels) {
					pRect->bottom = rcDesktop.bottom;
					pRect->top = rcDesktop.bottom-szSize.cy;
				}
			}
		}
		break;
	case WM_SYSCOMMAND:
		if ((wParam & 0xFFF0) == SC_MOVE) {
			RECT  rc;
			GetWindowRect(hwndDlg, &rc);
			dat->mouseLBDownPos.x = LOWORD(lParam) - rc.left;
			dat->mouseLBDownPos.y = HIWORD(lParam) - rc.top;
		} else if (wParam == IDM_TOPMOST) {
            HMENU hMenu = GetSystemMenu(hwndDlg, FALSE);
            if (dat->bTopmost)  {
                CheckMenuItem(hMenu, IDM_TOPMOST, MF_BYCOMMAND | MF_UNCHECKED);
                SetWindowPos(hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
                dat->bTopmost = FALSE;
            }
            else {
                CheckMenuItem(hMenu, IDM_TOPMOST, MF_BYCOMMAND | MF_CHECKED);
                SetWindowPos(hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
                dat->bTopmost = TRUE;
            }
        }
		break;
	case WM_DESTROY:
		{
			WINDOWPLACEMENT wp = { 0 };
			HANDLE hContact;
			g_dat->hParent = NULL;
			SetWindowLong(hwndDlg, GWL_USERDATA, 0);
			WindowList_Remove(g_dat->hParentWindowList, hwndDlg);
			if (dat->children!=NULL) free (dat->children);
			free(dat->tabCtrlDat);
			free(dat);
			if (!(dat->flags & SMF_USETABS) && DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT))
				hContact = dat->hContact;
			else
				hContact = NULL;
			wp.length = sizeof(wp);
			GetWindowPlacement(hwndDlg, &wp);
			if (!dat->windowWasCascaded) {
				DBWriteContactSettingDword(hContact, SRMMMOD, "x", wp.rcNormalPosition.left);
				DBWriteContactSettingDword(hContact, SRMMMOD, "y", wp.rcNormalPosition.top);
			}
			DBWriteContactSettingDword(hContact, SRMMMOD, "width", wp.rcNormalPosition.right - wp.rcNormalPosition.left);
			DBWriteContactSettingDword(hContact, SRMMMOD, "height", wp.rcNormalPosition.bottom - wp.rcNormalPosition.top);
			DBWriteContactSettingByte(hContact, SRMMMOD, SRMSGSET_TOPMOST, (BYTE)dat->bTopmost);
		}
		break;
	case DM_DEACTIVATE:
		SetForegroundWindow(dat->foregroundWindow);
		break;
	case DM_ERRORDECIDED:
		break;
	case DM_STARTFLASHING:
		if (GetActiveWindow() != hwndDlg || GetForegroundWindow() != hwndDlg) {
			dat->nFlash = 0;
			SetTimer(hwndDlg, TIMERID_FLASHWND, TIMEOUT_FLASHWND, NULL);
		}
		break;
	case DM_REMOVECHILD:
		{
			RemoveChild(dat, (HWND) lParam);
			if (dat->childrenCount != 0) {
				SetFocus(dat->hwndActive);
			} else {
				DestroyWindow(hwndDlg);
			}
		}
		return TRUE;
	case DM_ADDCHILD:
		{
			struct MessageWindowData * mdat = (struct MessageWindowData *) lParam;
			AddChild(dat, mdat);
		}
		return TRUE;
	case DM_ACTIVATECHILD:
//		if((HWND) lParam != dat->hwndActive) {
			ActivateChild(dat, (HWND) lParam);
//		}
		return TRUE;
	case DM_ACTIVATEPREV:
		ActivatePrevChild(dat, (HWND) lParam);
		SetFocus(dat->hwndActive);
		return TRUE;
	case DM_ACTIVATENEXT:
		ActivateNextChild(dat, (HWND) lParam);
		SetFocus(dat->hwndActive);
		return TRUE;
	case DM_SENDMESSAGE:
		{
			int i;
			for (i=0;i<dat->childrenCount;i++) {
				SendMessage(dat->children[i], DM_SENDMESSAGE, wParam, lParam);
			}
		}
		break;
	case DM_OPTIONSAPPLIED:
		{
			RECT rc;
			dat->flags = g_dat->flags;
			if (!(dat->flags & SMF_SHOWSTATUSBAR)) {
				ShowWindow(dat->hwndStatus, SW_HIDE);
			} else {
				ShowWindow(dat->hwndStatus, SW_SHOW);
			}
			ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION);
			if (dat->flags & SMF_SHOWTITLEBAR) {
				ws |= WS_CAPTION;
			}
			SetWindowLong(hwndDlg, GWL_STYLE, ws);

			ws = GetWindowLong(hwndDlg, GWL_EXSTYLE)& ~WS_EX_LAYERED;
			ws |= dat->flags & SMF_USETRANSPARENCY ? WS_EX_LAYERED : 0;
			SetWindowLong(hwndDlg , GWL_EXSTYLE , ws);
			if (dat->flags & SMF_USETRANSPARENCY) {
   				pSetLayeredWindowAttributes(hwndDlg, RGB(255,255,255), (BYTE)(255-g_dat->inactiveAlpha), LWA_ALPHA);
//				RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}

			ws = GetWindowLong(dat->hwndTabs, GWL_STYLE) & ~(TCS_BOTTOM);
			if (dat->flags & SMF_TABSATBOTTOM) {
				ws |= TCS_BOTTOM;
			}
			SetWindowLong(dat->hwndTabs, GWL_STYLE, ws);
			RedrawWindow(dat->hwndTabs, NULL, NULL, RDW_INVALIDATE);
			GetWindowRect(hwndDlg, &rc);
			SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
                        SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
			SendMessage(hwndDlg, WM_SIZE, 0, 0);
			//RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			break;
		}
	case DM_UPDATETITLE:
		{
			struct MessageWindowData * mdat = (struct MessageWindowData *) lParam;
			TCITEM tci;
			int tabId;
			TCHAR *tContactName;
			if (mdat && mdat->hwnd == dat->hwndActive) {
				TCHAR *newtitle, oldtitle[256];
#if defined ( _UNICODE )
				newtitle = GetWindowTitle(mdat->hContact, mdat->szProto);
#else
				newtitle = GetWindowTitle(mdat->hContact, mdat->szProto);
#endif
				GetWindowText(hwndDlg, oldtitle, sizeof(oldtitle));
				if (lstrcmp(newtitle, oldtitle)) { //swt() flickers even if the title hasn't actually changed
					SetWindowText(hwndDlg, newtitle);
					//SendMessage(hwndDlg, WM_SIZE, 0, 0);
				}
				free(newtitle);
			}
			tabId = GetTabFromHWND(dat, mdat->hwnd);
			tContactName = GetTabName(mdat->hContact);
			tci.mask = TCIF_TEXT;
			tci.pszText = tContactName;
			TabCtrl_SetItem(dat->hwndTabs, tabId, &tci);
			free(tContactName);
			break;
		}
	case DM_UPDATEWINICON:
		{
			struct MessageWindowData * mdat = (struct MessageWindowData *) lParam;
			if (mdat) {
				if (mdat->szProto) {
					int i, icoIdx = 0;
					WORD wStatus;
					char *szProto = mdat->szProto;
					HANDLE hContact = mdat->hContact;
					if (strcmp(mdat->szProto, "MetaContacts") == 0 && DBGetContactSettingByte(NULL,"CLC","Meta",0) == 0) {
						hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT,(UINT)mdat->hContact, 0);
						if (hContact != NULL) {
							szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(UINT)hContact,0);
						} else {
							hContact = mdat->hContact;
						}
					}
					wStatus = DBGetContactSettingWord(hContact, szProto, "Status", ID_STATUS_OFFLINE);
					mdat->wStatus = wStatus;
					if (mdat->hwnd == dat->hwndActive) {
						if (DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_STATUSICON, SRMSGDEFSET_STATUSICON)) {
							if (mdat->showTyping && (g_dat->flags&SMF_SHOWTYPINGWIN)) {
								SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) g_dat->hIcons[SMF_ICON_TYPING]);
							} else if (mdat->showUnread && (GetActiveWindow() != hwndDlg || GetForegroundWindow() != hwndDlg)) {
								SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE));
							} else {
								SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedProtoIcon(szProto, wStatus));
							}
						} else {
							SendMessage(hwndDlg, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) LoadSkinnedIcon(SKINICON_EVENT_MESSAGE));
						}
					}
					SendDlgItemMessage(mdat->hwnd, IDC_USERMENU, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadSkinnedProtoIcon(szProto, wStatus));
					icoIdx = 0;
					for (i = 0; i < g_dat->protoNum; i++) {
						if (!strcmp(g_dat->protoNames[i], szProto)) {
							icoIdx = wStatus - ID_STATUS_OFFLINE + (ID_STATUS_OUTTOLUNCH - ID_STATUS_OFFLINE + 1) * (i +1) + 2;
							break;
						}
					}
					if (mdat->hwnd != dat->hwndActive) {
						if (mdat->showTyping) {
							icoIdx = 1;
						} else if (mdat->showUnread & 1) {
							icoIdx = 0;
						}
					}
					i = GetTabFromHWND(dat, mdat->hwnd);
					if (i>=0) {
						TCITEM tci;
						tci.mask = TCIF_IMAGE;
						tci.iImage = icoIdx;
						TabCtrl_SetItem(dat->hwndTabs, i, &tci);
					}
				}
			}
			break;
		}
	case DM_UPDATESTATUSBAR:
		break;
	case DM_SWITCHSTATUSBAR:
		dat->flags ^= SMF_SHOWSTATUSBAR;
		if (!(dat->flags & SMF_SHOWSTATUSBAR)) {
			ShowWindow(dat->hwndStatus, SW_HIDE);
		} else {
			ShowWindow(dat->hwndStatus, SW_SHOW);
		}
		SendMessage(hwndDlg, WM_SIZE, 0, 0);
		break;
	case DM_SWITCHTOOLBAR:
		{
			int i;
			dat->flags ^= SMF_SHOWBTNS;
			for (i=0;i<dat->childrenCount;i++) {
				SendMessage(dat->children[i], DM_SWITCHTOOLBAR, 0, 0);
			}
			SendMessage(hwndDlg, WM_SIZE, 0, 0);
		}
		break;
	case DM_SWITCHTITLEBAR:
		{
			RECT rc;
			dat->flags ^= SMF_SHOWTITLEBAR;
			ws = GetWindowLong(hwndDlg, GWL_STYLE) & ~(WS_CAPTION);
			if (dat->flags & SMF_SHOWTITLEBAR) {
				ws |= WS_CAPTION;
			}
			SetWindowLong(hwndDlg, GWL_STYLE, ws);
			GetWindowRect(hwndDlg, &rc);
			SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
                         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER  | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
//			SendMessage(hwndDlg, WM_SIZE, 0, 0);
			RedrawWindow(hwndDlg, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
		}
		break;
	case DM_CASCADENEWWINDOW:
		if ((HWND) wParam == hwndDlg)
			break;
		{
			RECT rcThis, rcNew;
			GetWindowRect(hwndDlg, &rcThis);
			GetWindowRect((HWND) wParam, &rcNew);
			if (abs(rcThis.left - rcNew.left) < 3 && abs(rcThis.top - rcNew.top) < 3) {
				int offset = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME);
				SetWindowPos((HWND) wParam, 0, rcNew.left + offset, rcNew.top + offset, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
				*(int *) lParam = 1;
			}
		}
		break;
	//case DM_MESSAGESENDING:
	//	dat->messagesInProgress += wParam ? -1 : 1;
	//	if (dat->messagesInProgress < 0) dat->messagesInProgress = 0;
	//	break;
	}
	return FALSE;
}