Rip the dialog position calculating code to a function and use it in more dialogbox.

This commit is contained in:
owomomo 2019-06-18 01:02:55 +08:00
parent 17a36d9b9f
commit 5a80b67e57
12 changed files with 157 additions and 147 deletions

View File

@ -294,9 +294,21 @@ BOOL CALLBACK CheatConsoleCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
{
case WM_INITDIALOG:
{
if (ChtPosX == -32000) ChtPosX = 0; //Just in case
if (ChtPosY == -32000) ChtPosY = 0;
SetWindowPos(hwndDlg, 0, ChtPosX, ChtPosY, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
POINT pt;
if (ChtPosX != 0 && ChtPosY != 0)
{
pt.x = ChtPosX;
pt.y = ChtPosY;
pt = CalcSubWindowPos(hwndDlg, &pt);
}
else
pt = CalcSubWindowPos(hwndDlg, NULL);
ChtPosX = pt.x;
ChtPosY = pt.y;
// SetWindowPos(hwndDlg, 0, ChtPosX, ChtPosY, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
CheckDlgButton(hwndDlg, IDC_CHEAT_PAUSEWHENACTIVE, pauseWhileActive ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHEAT_GLOBAL_SWITCH, globalCheatDisabled ? BST_UNCHECKED : BST_CHECKED);
@ -1112,10 +1124,6 @@ BOOL CALLBACK GGConvCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
break;
case WM_MOUSEMOVE:
break;
case WM_HSCROLL:
break;
}
return FALSE;
}
@ -1213,7 +1221,7 @@ void DoGGConv()
ShowWindow(hGGConv, SW_SHOWNORMAL);
SetForegroundWindow(hGGConv);
} else
hGGConv = CreateDialog(fceu_hInstance,"GGCONV",NULL,GGConvCallB);
hGGConv = CreateDialog(fceu_hInstance,"GGCONV", hAppWnd, GGConvCallB);
}
inline void GetCheatStr(char* buf, int a, int v, int c)

View File

@ -32,6 +32,7 @@ void AskSaveCheat();
void SaveCheatAs(HWND hwnd, bool flush = false);
void UpdateCheatRelatedWindow();
extern POINT CalcSubWindowPos(HWND hDlg, POINT* conf);
// deselect the old one and select the new one
#define ListView_MoveSelectionMark(hwnd, prevIndex, newIndex) \

View File

@ -471,13 +471,14 @@ LRESULT CALLBACK HeaderEditorProc(HWND hDlg, UINT uMsg, WPARAM wP, LPARAM lP)
{
header = (iNES_HEADER*)lP;
if (!header)
{
if (GameInfo)
DestroyWindow(hDlg);
else
EndDialog(hDlg, 0);
} else
goto wm_close;
else
InitHeaderEditDialog(hDlg, header);
// Put the window aside the main window when in game.
if (GameInfo)
CalcSubWindowPos(hDlg, NULL);
}
break;
case WM_COMMAND:

View File

@ -21,5 +21,5 @@ bool GetComboBoxListItemData(HWND hwnd, UINT id, int* value, char* buf, bool exa
bool SaveINESFile(HWND hwnd, char* path, iNES_HEADER* header);
LRESULT CALLBACK HeaderEditorProc(HWND hDlg, UINT uMsg, WPARAM wP, LPARAM lP);
void DoHeadEdit();
extern POINT CalcSubWindowPos(HWND hDlg, POINT* conf);
#endif

View File

@ -102,9 +102,9 @@ void WinLuaOnStop(int hDlgAsInt)
INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
RECT r;
RECT r2;
int dx1, dy1, dx2, dy2;
// RECT r;
// RECT r2;
// int dx1, dy1, dx2, dy2;
switch (msg) {
@ -113,43 +113,10 @@ INT_PTR CALLBACK DlgLuaScriptDialog(HWND hDlg, UINT msg, WPARAM wParam, LPARAM l
// remove the 30000 character limit from the console control
SendMessage(GetDlgItem(hDlg, IDC_LUACONSOLE),EM_LIMITTEXT,0,0);
GetWindowRect(hAppWnd, &r);
dx1 = (r.right - r.left) / 2;
dy1 = (r.bottom - r.top) / 2;
GetWindowRect(hDlg, &r2);
dx2 = (r2.right - r2.left) / 2;
dy2 = (r2.bottom - r2.top) / 2;
//int windowIndex = 0;//std::find(LuaScriptHWnds.begin(), LuaScriptHWnds.end(), hDlg) - LuaScriptHWnds.begin();
//int staggerOffset = windowIndex * 24;
//r.left += staggerOffset;
//r.right += staggerOffset;
//r.top += staggerOffset;
//r.bottom += staggerOffset;
// push it away from the main window if we can
const int width = (r.right-r.left);
const int width2 = (r2.right-r2.left);
const int rspace = GetSystemMetrics(SM_CXSCREEN)- (r.left+width2+width);
if(rspace > r.left && r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
{
r.right += width;
r.left += width;
}
else if((int)r.left - (int)width2 > 0)
{
r.right -= width2;
r.left -= width2;
}
else if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
{
r.right += width;
r.left += width;
}
SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
extern POINT CalcSubWindowPos(HWND hDlg, POINT* conf);
CalcSubWindowPos(hDlg, NULL);
RECT r3;
GetClientRect(hDlg, &r3);
windowInfo.width = r3.right - r3.left;

View File

@ -316,23 +316,24 @@ int BlockingCheck()
MSG msg;
moocow = 1;
while( PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ) )
while(PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
{
if( GetMessage( &msg, 0, 0, 0)>0 )
if(GetMessage(&msg, 0, 0, 0) > 0)
{
//other accelerator capable dialogs could be added here
extern HWND hwndMemWatch;
int handled = 0;
if(hCheat)
if(IsChild(hCheat, msg.hwnd))
handled = IsDialogMessage(hCheat, &msg);
if(!handled && hMemFind)
{
if(IsChild(hMemFind, msg.hwnd))
handled = IsDialogMessage(hMemFind, &msg);
}
extern HWND hGGConv;
bool debug = IsChild(hGGConv, msg.hwnd) && msg.message == WM_KEYDOWN;
if(hCheat && IsChild(hCheat, msg.hwnd))
handled = IsDialogMessage(hCheat, &msg);
if(!handled && hMemFind && IsChild(hMemFind, msg.hwnd))
handled = IsDialogMessage(hMemFind, &msg);
if(!handled && hwndMemWatch)
{
if(IsChild(hwndMemWatch,msg.hwnd))
@ -340,68 +341,110 @@ int BlockingCheck()
if(!handled)
handled = IsDialogMessage(hwndMemWatch,&msg);
}
if(!handled && RamSearchHWnd)
{
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 3);
if(!handled && RamSearchHWnd && IsChild(RamSearchHWnd, msg.hwnd))
handled = IsDialogMessage(RamSearchHWnd, &msg);
}
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 4);
if(!handled && RamWatchHWnd)
{
if(IsDialogMessage(RamWatchHWnd, &msg))
{
if(handled = IsDialogMessage(RamWatchHWnd, &msg))
if(msg.message == WM_KEYDOWN) // send keydown messages to the dialog (for accelerators, and also needed for the Alt key to work)
SendMessage(RamWatchHWnd, msg.message, msg.wParam, msg.lParam);
handled = true;
}
}
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 5);
if(!handled && taseditorWindow.hwndTASEditor)
{
if(taseditorEnableAcceleratorKeys)
if(IsChild(taseditorWindow.hwndTASEditor, msg.hwnd))
handled = TranslateAccelerator(taseditorWindow.hwndTASEditor, fceu_hAccel, &msg);
if(!handled && taseditorWindow.hwndTASEditor){
if(!handled){
handled = IsDialogMessage(taseditorWindow.hwndTASEditor, &msg);
}
}
if(!handled && taseditorWindow.hwndFindNote)
{
if(IsChild(taseditorWindow.hwndFindNote, msg.hwnd))
handled = IsDialogMessage(taseditorWindow.hwndFindNote, &msg);
}
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 6);
if(!handled && taseditorWindow.hwndFindNote && IsChild(taseditorWindow.hwndFindNote, msg.hwnd))
handled = IsDialogMessage(taseditorWindow.hwndFindNote, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 7);
extern HWND uug;
if(!handled && uug && IsChild(uug, msg.hwnd))
handled = IsDialogMessage(uug, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 8);
if(!handled && pwindow && IsChild(pwindow, msg.hwnd))
handled = IsDialogMessage(pwindow, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 9);
if(!handled && hCDLogger && IsChild(hCDLogger, msg.hwnd))
handled = IsDialogMessage(hCDLogger, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 10);
if(!handled && hTracer && IsChild(hTracer, msg.hwnd))
handled = IsDialogMessage(hTracer, &msg);
extern HWND hGGConv;
if (debug && !handled)
printf("GGConv unhandled WM_KEYDOWN: %d\n", 11);
if(!handled && hGGConv && IsChild(hGGConv, msg.hwnd))
handled = IsDialogMessage(hGGConv, &msg);
if (debug)
if(!handled)
printf("GGConv unhandled WM_KEYDOWN: %d\n", 12);
else
printf("GGConv handled\n");
if(!handled && hDebug && IsChild(hDebug, msg.hwnd))
handled = IsDialogMessage(hDebug, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 13);
extern HWND hPPUView;
if(!handled && hPPUView && IsChild(hPPUView, msg.hwnd))
handled = IsDialogMessage(hPPUView, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 14);
extern HWND hNTView;
if(!handled && hNTView && IsChild(hNTView, msg.hwnd))
handled = IsDialogMessage(hNTView, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 15);
extern HWND hTextHooker;
if(!handled && hTextHooker && IsChild(hTextHooker, msg.hwnd))
handled = IsDialogMessage(hTextHooker, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 16);
extern HWND LuaConsoleHWnd;
if(!handled && LuaConsoleHWnd && IsChild(LuaConsoleHWnd, msg.hwnd))
handled = IsDialogMessage(LuaConsoleHWnd, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 17);
extern HWND logwin;
if(!handled && logwin && IsChild(logwin, msg.hwnd))
handled = IsDialogMessage(logwin, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 18);
extern HWND hHeadEditor;
if (!handled && hHeadEditor && IsChild(hHeadEditor, msg.hwnd))
handled = IsDialogMessage(hHeadEditor, &msg);
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 19);
/* //adelikat - Currently no accel keys are used in the main window. Uncomment this block to activate them.
if(!handled)
if(msg.hwnd == hAppWnd)
@ -415,6 +458,8 @@ int BlockingCheck()
*/
if(!handled)
{
if (debug && !handled) printf("GGConv unhandled WM_KEYDOWN: %d\n", 20);
TranslateMessage(&msg);
DispatchMessage(&msg);
}

View File

@ -1398,38 +1398,15 @@ static BOOL SelectingByKeyboard()
LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT r;
RECT r2;
int dx1, dy1, dx2, dy2;
static int watchIndex=0;
switch(uMsg)
{
case WM_INITDIALOG: {
RamSearchHWnd = hDlg;
GetWindowRect(hWnd, &r);
dx1 = (r.right - r.left) / 2;
dy1 = (r.bottom - r.top) / 2;
CalcSubWindowPos(hDlg, NULL);
GetWindowRect(hDlg, &r2);
dx2 = (r2.right - r2.left) / 2;
dy2 = (r2.bottom - r2.top) / 2;
// push it away from the main window if we can
const int width = (r.right-r.left);
const int width2 = (r2.right-r2.left);
if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
{
r.right += width;
r.left += width;
}
else if((int)r.left - (int)width2 > 0)
{
r.right -= width2;
r.left -= width2;
}
SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
switch(rs_o)
{
case '<':

View File

@ -30,6 +30,7 @@ void DoRamSearchOperation(); //Perform a search
extern HWND RamSearchHWnd;
extern LRESULT CALLBACK RamSearchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern POINT CalcSubWindowPos(HWND hDlg, POINT* conf);
// Too much work to do for resorting the values, and finding the biggest number
// by sorting in ram list doesn't help too much in usually use, so I gave it up.

View File

@ -1026,47 +1026,16 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
case WM_INITDIALOG:
{
RECT r, r2;
int dx1, dy1, dx2, dy2;
GetWindowRect(hWnd, &r); //Ramwatch window
dx1 = (r.right - r.left) / 2;
dy1 = (r.bottom - r.top) / 2;
GetWindowRect(hDlg, &r2); // TASer window
dx2 = (r2.right - r2.left) / 2;
dy2 = (r2.bottom - r2.top) / 2;
// push it away from the main window if we can
const int width = (r.right-r.left);
const int height = (r.bottom - r.top);
const int width2 = (r2.right-r2.left);
if(r.left+width2 + width < GetSystemMetrics(SM_CXSCREEN))
if (RWSaveWindowPos)
{
r.right += width;
r.left += width;
POINT pt = { ramw_x, ramw_y };
pt = CalcSubWindowPos(hDlg, &pt);
ramw_x = pt.x;
ramw_y = pt.y;
}
else if((int)r.left - (int)width2 > 0)
{
r.right -= width2;
r.left -= width2;
}
//-----------------------------------------------------------------------------------
//If user has Save Window Pos selected, override default positioning
if (RWSaveWindowPos)
{
//If ramwindow is for some reason completely off screen, use default instead
if (ramw_x > (-width*2) || ramw_x < (width*2 + GetSystemMetrics(SM_CYSCREEN)) )
r.left = ramw_x; //This also ignores cases of windows -32000 error codes
//If ramwindow is for some reason completely off screen, use default instead
if (ramw_y > (0-height*2) ||ramw_y < (height*2 + GetSystemMetrics(SM_CYSCREEN)) )
r.top = ramw_y; //This also ignores cases of windows -32000 error codes
}
//-------------------------------------------------------------------------------------
SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
else
CalcSubWindowPos(hDlg, NULL);
ramwatchmenu=GetMenu(hDlg);
rwrecentmenu=CreateMenu();
UpdateRW_RMenu(rwrecentmenu, RAMMENU_FILE_RECENT, RW_MENU_FIRST_RECENT_FILE);

View File

@ -12,11 +12,11 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Neutral resources
// ·ÇÌض¨ÓïÑÔ resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1252)
#pragma code_page(936)
/////////////////////////////////////////////////////////////////////////////
//
@ -2801,7 +2801,7 @@ END
#endif // APSTUDIO_INVOKED
#endif // Neutral resources
#endif // ·ÇÌض¨ÓïÑÔ resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -3220,3 +3220,43 @@ void UpdateSortColumnIcon(HWND hwndListView, int sortColumn, bool sortAsc)
}
}
}
// Push the window away from the main FCEUX window
POINT CalcSubWindowPos(HWND hDlg, POINT* conf)
{
POINT pt; // dialog position
RECT wR, dR; // Window rect, dialog rect
// Try to calc the default position, it doesn't overlap the main window and ensure it's in the screen;
GetWindowRect(hAppWnd, &wR);
GetWindowRect(hDlg, &dR);
pt.x = wR.left;
pt.y = wR.top;
LONG wW = wR.right - wR.left; // window width
LONG dW = dR.right - dR.left; // dialog width
if (pt.x + wW + dW < GetSystemMetrics(SM_CXSCREEN))
pt.x += wW; // if there is enough place for the dialog on the right, put the dialog there
else if (pt.x - dW > 0)
pt.x -= dW; // otherwise, we check if we can put it on the left
// If the dialog has a configured window position, override the default position
if (conf)
{
LONG wH = wR.bottom - wR.top;
// It is overrided only when the configured position is not completely off screen
if (conf->x > -wW * 2 || conf->x < wW * 2 + GetSystemMetrics(SM_CXSCREEN))
pt.x = conf->x;
if (conf->y > -wH * 2 || conf->y < wH * 2 + GetSystemMetrics(SM_CYSCREEN))
pt.y = conf->y;
}
// finally set the window position
SetWindowPos(hDlg, NULL, pt.x, pt.y, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
// return the calculated point, maybe the caller can use it for further.
return pt;
}

View File

@ -38,6 +38,7 @@ void SetMainWindowStuff();
void GetMouseData(uint32 (&md)[3]);
void GetMouseRelative(int32 (&md)[3]);
//void ChangeMenuItemText(int menuitem, string text);
POINT CalcSubWindowPos(HWND hDlg, POINT* conf);
template<int BUFSIZE>
inline std::string GetDlgItemText(HWND hDlg, int nIDDlgItem) {