OSDN Git Service

windows版で、windowsを最大化したときに元のウィンドウサイズを保持するように変更。元のウィンドウの位置については対応できていない。(from XAngband)
authoriks <iks@0568b783-4c39-0410-ac80-bf13821ea2a2>
Sat, 7 Mar 2009 21:24:35 +0000 (21:24 +0000)
committeriks <iks@0568b783-4c39-0410-ac80-bf13821ea2a2>
Sat, 7 Mar 2009 21:24:35 +0000 (21:24 +0000)
src/main-win.c

index bfa243b..2fddbbf 100644 (file)
@@ -434,6 +434,16 @@ static term_data data[MAX_TERM_DATA];
 static term_data *my_td;
 
 /*
 static term_data *my_td;
 
 /*
+ * Remember normal size of main window when maxmized
+ */
+POINT normsize;
+
+/*
+ * was main window maximized on previous playing
+ */
+bool win_maximized = FALSE;
+
+/*
  * game in progress
  */
 bool game_in_progress = FALSE;
  * game in progress
  */
 bool game_in_progress = FALSE;
@@ -1067,18 +1077,27 @@ static void term_getsize(term_data *td)
 /*
  * Write the "prefs" for a single term
  */
 /*
  * Write the "prefs" for a single term
  */
-static void save_prefs_aux(term_data *td, cptr sec_name)
+static void save_prefs_aux(int i)
 {
 {
+       term_data *td = &data[i];
+       char sec_name[128];
        char buf[1024];
 
        RECT rc;
        char buf[1024];
 
        RECT rc;
+       WINDOWPLACEMENT lpwndpl;
 
        /* Paranoia */
        if (!td->w) return;
 
 
        /* Paranoia */
        if (!td->w) return;
 
+       /* Make section name */
+       sprintf(sec_name, "Term-%d", i);
+
        /* Visible */
        /* Visible */
-       strcpy(buf, td->visible ? "1" : "0");
-       WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
+       if (i > 0)
+       {
+               strcpy(buf, td->visible ? "1" : "0");
+               WritePrivateProfileString(sec_name, "Visible", buf, ini_file);
+       }
 
        /* Font */
 #ifdef JP
 
        /* Font */
 #ifdef JP
@@ -1113,14 +1132,30 @@ static void save_prefs_aux(term_data *td, cptr sec_name)
        wsprintf(buf, "%d", td->tile_hgt);
        WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
 
        wsprintf(buf, "%d", td->tile_hgt);
        WritePrivateProfileString(sec_name, "TileHgt", buf, ini_file);
 
+       /* Get window placement and dimensions */
+       lpwndpl.length = sizeof(WINDOWPLACEMENT);
+       GetWindowPlacement(td->w, &lpwndpl);
+
+       /* Acquire position in *normal* mode (not minimized) */
+       rc = lpwndpl.rcNormalPosition;
+
        /* Window size (x) */
        /* Window size (x) */
-       wsprintf(buf, "%d", td->cols);
+       if (i == 0) wsprintf(buf, "%d", normsize.x);
+       else wsprintf(buf, "%d", td->cols);
        WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
 
        /* Window size (y) */
        WritePrivateProfileString(sec_name, "NumCols", buf, ini_file);
 
        /* Window size (y) */
-       wsprintf(buf, "%d", td->rows);
+       if (i == 0) wsprintf(buf, "%d", normsize.y);
+       else wsprintf(buf, "%d", td->rows);
        WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
 
        WritePrivateProfileString(sec_name, "NumRows", buf, ini_file);
 
+       /* Maxmized (only main window) */
+       if (i == 0)
+       {
+               strcpy(buf, IsZoomed(td->w) ? "1" : "0");
+               WritePrivateProfileString(sec_name, "Maximized", buf, ini_file);
+       }
+
        /* Acquire position */
        GetWindowRect(td->w, &rc);
 
        /* Acquire position */
        GetWindowRect(td->w, &rc);
 
@@ -1133,8 +1168,11 @@ static void save_prefs_aux(term_data *td, cptr sec_name)
        WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
 
        /* Window Z position */
        WritePrivateProfileString(sec_name, "PositionY", buf, ini_file);
 
        /* Window Z position */
-       strcpy(buf, td->posfix ? "1" : "0");
-       WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
+       if (i > 0)
+       {
+               strcpy(buf, td->posfix ? "1" : "0");
+               WritePrivateProfileString(sec_name, "PositionFix", buf, ini_file);
+       }
 }
 
 
 }
 
 
@@ -1170,11 +1208,7 @@ static void save_prefs(void)
        /* Save window prefs */
        for (i = 0; i < MAX_TERM_DATA; ++i)
        {
        /* Save window prefs */
        for (i = 0; i < MAX_TERM_DATA; ++i)
        {
-               term_data *td = &data[i];
-
-               sprintf(buf, "Term-%d", i);
-
-               save_prefs_aux(td, buf);
+               save_prefs_aux(i);
        }
 }
 
        }
 }
 
@@ -1182,14 +1216,25 @@ static void save_prefs(void)
 /*
  * Load the "prefs" for a single term
  */
 /*
  * Load the "prefs" for a single term
  */
-static void load_prefs_aux(term_data *td, cptr sec_name)
+static void load_prefs_aux(int i)
 {
 {
+       term_data *td = &data[i];
+       char sec_name[128];
        char tmp[1024];
 
        int wid, hgt;
 
        char tmp[1024];
 
        int wid, hgt;
 
+       /* Make section name */
+       sprintf(sec_name, "Term-%d", i);
+
+       /* Make section name */
+       sprintf(sec_name, "Term-%d", i);
+
        /* Visible */
        /* Visible */
-       td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
+       if (i > 0)
+       {
+               td->visible = (GetPrivateProfileInt(sec_name, "Visible", td->visible, ini_file) != 0);
+       }
 
        /* Desired font, with default */
 #ifdef JP
 
        /* Desired font, with default */
 #ifdef JP
@@ -1231,13 +1276,23 @@ static void load_prefs_aux(term_data *td, cptr sec_name)
        /* Window size */
        td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
        td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
        /* Window size */
        td->cols = GetPrivateProfileInt(sec_name, "NumCols", td->cols, ini_file);
        td->rows = GetPrivateProfileInt(sec_name, "NumRows", td->rows, ini_file);
+       normsize.x = td->cols; normsize.y = td->rows;
+
+       /* Window size */
+       if (i == 0)
+       {
+               win_maximized = GetPrivateProfileInt(sec_name, "Maximized", win_maximized, ini_file);
+       }
 
        /* Window position */
        td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
        td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
 
        /* Window Z position */
 
        /* Window position */
        td->pos_x = GetPrivateProfileInt(sec_name, "PositionX", td->pos_x, ini_file);
        td->pos_y = GetPrivateProfileInt(sec_name, "PositionY", td->pos_y, ini_file);
 
        /* Window Z position */
-       td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
+       if (i > 0)
+       {
+               td->posfix = GetPrivateProfileInt(sec_name, "PositionFix", td->posfix, ini_file);
+       }
 }
 
 
 }
 
 
@@ -1248,8 +1303,6 @@ static void load_prefs(void)
 {
        int i;
 
 {
        int i;
 
-       char buf[1024];
-
        /* Extract the "arg_graphics" flag */
        arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
 
        /* Extract the "arg_graphics" flag */
        arg_graphics = GetPrivateProfileInt("Angband", "Graphics", GRAPHICS_NONE, ini_file);
 
@@ -1267,11 +1320,7 @@ static void load_prefs(void)
        /* Load window prefs */
        for (i = 0; i < MAX_TERM_DATA; ++i)
        {
        /* Load window prefs */
        for (i = 0; i < MAX_TERM_DATA; ++i)
        {
-               term_data *td = &data[i];
-
-               sprintf(buf, "Term-%d", i);
-
-               load_prefs_aux(td, buf);
+               load_prefs_aux(i);
        }
 }
 
        }
 }
 
@@ -3093,9 +3142,12 @@ static void init_windows(void)
 
        term_data_link(td);
        angband_term[0] = &td->t;
 
        term_data_link(td);
        angband_term[0] = &td->t;
+       normsize.x = td->cols;
+       normsize.y = td->rows;
 
        /* Activate the main window */
 
        /* Activate the main window */
-       SetActiveWindow(td->w);
+       if (win_maximized) ShowWindow(td->w, SW_SHOWMAXIMIZED);
+       else ShowWindow(td->w, SW_SHOW);
 
        /* Bring main window back to top */
        SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
 
        /* Bring main window back to top */
        SetWindowPos(td->w, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
@@ -4415,6 +4467,12 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
                                                td->cols = cols;
                                                td->rows = rows;
 
                                                td->cols = cols;
                                                td->rows = rows;
 
+                                               if (!IsZoomed(td->w) && !IsIconic(td->w))
+                                               {
+                                                       normsize.x = td->cols;
+                                                       normsize.y = td->rows;
+                                               }
+
                                                /* Activate */
                                                Term_activate(&td->t);
 
                                                /* Activate */
                                                Term_activate(&td->t);
 
@@ -4488,6 +4546,8 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg,
 
                case WM_ACTIVATEAPP:
                {
 
                case WM_ACTIVATEAPP:
                {
+                       if (IsIconic(td->w)) break;
+
                        for (i = 1; i < MAX_TERM_DATA; i++)
                        {
                                if(data[i].visible)
                        for (i = 1; i < MAX_TERM_DATA; i++)
                        {
                                if(data[i].visible)