From b464ea04613dec7223cd1b26aad9be3f44ae6ac9 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Mon, 26 Aug 2013 23:43:32 +0000 Subject: [PATCH] winport: - add save console window position; --- desmume/src/windows/console.cpp | 42 +++++++++++++++++++++++++------ desmume/src/windows/console.h | 3 ++- desmume/src/windows/main.cpp | 31 ++++++++++++++++++++--- desmume/src/windows/resource.h | 1 + desmume/src/windows/resources.rc | Bin 231414 -> 231558 bytes 5 files changed, 65 insertions(+), 12 deletions(-) diff --git a/desmume/src/windows/console.cpp b/desmume/src/windows/console.cpp index f2540a9a1..de09ce8fc 100644 --- a/desmume/src/windows/console.cpp +++ b/desmume/src/windows/console.cpp @@ -1,5 +1,5 @@ /* - Copyright 2008-2011 DeSmuME team + Copyright 2008-2013 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,7 +24,8 @@ ///////////////////////////////////////////////////////////////// Console #define BUFFER_SIZE 100 -HANDLE hConsole = NULL; +HANDLE hConsole = NULL; +HWND gConsoleWnd = NULL; void printlog(const char *fmt, ...); std::wstring SkipEverythingButProgramInCommandLine(wchar_t* cmdLine) @@ -112,7 +113,6 @@ void OpenConsole() //newer and improved console title: SetConsoleTitleW(SkipEverythingButProgramInCommandLine(GetCommandLineW()).c_str()); - if(shouldRedirectStdout) { freopen("CONOUT$", "w", stdout); @@ -120,19 +120,47 @@ void OpenConsole() freopen("CONIN$", "r", stdin); } + gConsoleWnd = GetConsoleWindow(); + if (gConsoleWnd) + { + RECT rc = {0}; + if (GetWindowRect(gConsoleWnd, &rc)) + { + rc.left = GetPrivateProfileInt("Console", "PosX", rc.left, IniName); + rc.top = GetPrivateProfileInt("Console", "PosY", rc.top, IniName); + rc.right = GetPrivateProfileInt("Console", "Width", (rc.right - rc.left), IniName); + rc.bottom = GetPrivateProfileInt("Console", "Height", (rc.bottom - rc.top), IniName); + SetWindowPos(gConsoleWnd, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOACTIVATE); + } + } + printlog("%s\n",EMU_DESMUME_NAME_AND_VERSION()); printlog("- compiled: %s %s\n",__DATE__,__TIME__); if(attached) printf("\nuse cmd /c desmume.exe to get more sensible console behaviour\n"); printlog("\n"); } -void CloseConsole() { - if (hConsole == NULL) return; - printlog("Closing..."); - FreeConsole(); +void CloseConsole() +{ + RECT pos = {0}; + + if (GetWindowRect(gConsoleWnd, &pos)) + { + WritePrivateProfileInt("Console", "PosX", pos.left, IniName); + WritePrivateProfileInt("Console", "PosY", pos.top, IniName); + WritePrivateProfileInt("Console", "Width", (pos.right - pos.left), IniName); + WritePrivateProfileInt("Console", "Height", (pos.bottom - pos.top), IniName); + } + FreeConsole(); hConsole = NULL; } +void ConsoleTop(bool top) +{ + if (!gConsoleWnd) return; + SetWindowPos(gConsoleWnd, (top?HWND_TOPMOST:HWND_NOTOPMOST), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); +} + void printlog(const char *fmt, ...) { va_list args; diff --git a/desmume/src/windows/console.h b/desmume/src/windows/console.h index e4668f06f..582652f47 100644 --- a/desmume/src/windows/console.h +++ b/desmume/src/windows/console.h @@ -1,5 +1,5 @@ /* - Copyright 2008-2009 DeSmuME team + Copyright 2008-2013 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,5 +32,6 @@ void OpenConsole(); void CloseConsole(); +void ConsoleAlwaysTop(bool top); #endif \ No newline at end of file diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 09174c821..f5bd26aa1 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -441,6 +441,8 @@ int romnum = 0; DWORD threadID; WINCLASS *MainWindow=NULL; +bool gShowConsole = false; +bool gConsoleTopmost = false; //HWND hwnd; //HDC hdc; @@ -2543,8 +2545,9 @@ int MenuInit() ResetSaveStateTimes(); - HMENU configMenu = GetSubMenuByIdOfFirstChild(mainMenu,IDM_3DCONFIG); - HMENU advancedMenu = GetSubMenuByIdOfFirstChild(configMenu,ID_ADVANCED); + HMENU configMenu = GetSubMenuByIdOfFirstChild(mainMenu, IDM_3DCONFIG); + HMENU advancedMenu = GetSubMenuByIdOfFirstChild(configMenu, ID_ADVANCED); + HMENU toolsMenu = GetSubMenuByIdOfFirstChild(mainMenu, IDM_DISASSEMBLER); DeleteMenu(advancedMenu,ID_ADVANCED,MF_BYCOMMAND); #ifndef DEVELOPER_MENU_ITEMS @@ -2575,6 +2578,9 @@ int MenuInit() DeleteMenu(configMenu,GetSubMenuIndexByHMENU(configMenu,advancedMenu),MF_BYPOSITION); #endif + if (!gShowConsole) + DeleteMenu(toolsMenu, IDM_CONSOLE_ALWAYS_ON_TOP, MF_BYCOMMAND); + return 1; } @@ -3532,8 +3538,14 @@ int WINAPI WinMain (HINSTANCE hThisInstance, static const bool defaultConsoleEnable = false; #endif - if(GetPrivateProfileBool("Display", "Show Console", defaultConsoleEnable, IniName)) + gShowConsole = GetPrivateProfileBool("Display", "Show Console", defaultConsoleEnable, IniName); + gConsoleTopmost = GetPrivateProfileBool("Console", "Always On Top", false, IniName); + + if (gShowConsole) + { OpenConsole(); // Init debug console + ConsoleAlwaysTop(gConsoleTopmost); + } //-------------------------------- int ret = _main(); @@ -4526,7 +4538,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM MainWindow->checkMenu(IDM_RENDER_LQ2X, video.currentfilter == video.LQ2X ); MainWindow->checkMenu(IDM_RENDER_LQ2XS, video.currentfilter == video.LQ2XS ); MainWindow->checkMenu(IDM_RENDER_HQ2X, video.currentfilter == video.HQ2X ); - MainWindow->checkMenu(IDM_RENDER_HQ4X, video.currentfilter == video.HQ4X ); + MainWindow->checkMenu(IDM_RENDER_HQ4X, video.currentfilter == video.HQ4X ); MainWindow->checkMenu(IDM_RENDER_HQ2XS, video.currentfilter == video.HQ2XS ); MainWindow->checkMenu(IDM_RENDER_2XSAI, video.currentfilter == video._2XSAI ); MainWindow->checkMenu(IDM_RENDER_SUPER2XSAI, video.currentfilter == video.SUPER2XSAI ); @@ -4580,6 +4592,9 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM DesEnableMenuItem(mainMenu, IDM_SCREENSEP_COLORBLACK, false); } + // Tools + MainWindow->checkMenu(IDM_CONSOLE_ALWAYS_ON_TOP, gConsoleTopmost); + UpdateHotkeyAssignments(); //Add current hotkey mappings to menu item names CallRegisteredLuaFunctions(LUACALL_ONINITMENU); @@ -6064,6 +6079,14 @@ DOKEYDOWN: } return 0; + case IDM_CONSOLE_ALWAYS_ON_TOP: + { + gConsoleTopmost = !gConsoleTopmost; + ConsoleAlwaysTop(gConsoleTopmost); + WritePrivateProfileBool("Console", "Always On Top", gConsoleTopmost, IniName); + } + return 0; + case IDM_SHOWTOOLBAR: { bool maximized = IsZoomed(hwnd)==TRUE; diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index f9116ddf0..bbbc579d0 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -710,6 +710,7 @@ #define IDC_SNDCTRL_LEFTOUTTEXT 1468 #define IDC_SNDCTRL_RIGHTOUT 1469 #define IDC_SNDCTRL_RIGHTOUTTEXT 1470 +#define IDM_CONSOLE_ALWAYS_ON_TOP 1500 #define IDC_SOUND0MUTE 2001 #define IDC_SOUND1MUTE 2002 #define IDC_SOUND2MUTE 2003 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 44814b572d0eb0644a47da2e3acf542d4198b41d..cab7edfc36a2194020a3134bd826095697271e94 100644 GIT binary patch delta 81 zcmey?&(}7Quc3vpg=q_Ol@ufAbi?aR;{47G`3!js#XvHLA(cU4y8Kfn?dj`oFmZAF lGx#wCGx#(3Ft|>Sf68PyUEmUv#q_>^Oaj|aNipl>0sz&P5C;