[PATCH] winecfg: Add trackbar to set screen resolution in graphics tab

Nigel Liang ncliang at gmail.com
Thu Jul 26 20:05:02 CDT 2007


diff --git a/programs/winecfg/En.rc b/programs/winecfg/En.rc
index 5972c3b..9243e3c 100644
--- a/programs/winecfg/En.rc
+++ b/programs/winecfg/En.rc
@@ -79,12 +79,16 @@ BEGIN
     EDITTEXT        IDC_DESKTOP_WIDTH,64,166,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED
     EDITTEXT        IDC_DESKTOP_HEIGHT,117,166,40,12,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED
 
-    GROUPBOX        " Direct3D ",IDC_STATIC,8,195,244,48
+    GROUPBOX        " Direct3D ",IDC_STATIC,8,190,244,48
 
-    LTEXT           "Vertex Shader Support: ",IDC_STATIC,15,208,80,32
-    COMBOBOX        IDC_D3D_VSHADER_MODE,100,206,145,70,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
+    LTEXT           "Vertex Shader Support: ",IDC_STATIC,15,203,80,32
+    COMBOBOX        IDC_D3D_VSHADER_MODE,100,201,145,70,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
 
-    CONTROL         "Allow Pixel Shader (if supported by hardware)",IDC_D3D_PSHADER_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,224,230,10
+    CONTROL         "Allow Pixel Shader (if supported by hardware)",IDC_D3D_PSHADER_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,219,230,10
+    GROUPBOX        " Screen Resolution ",IDC_STATIC,8,242,244,25
+    CONTROL         "", IDC_RES_TRACKBAR, "msctls_trackbar32",WS_TABSTOP,12,250,187,15
+    EDITTEXT        IDC_RES_DPIEDIT,204,250,23,13,ES_NUMBER|WS_TABSTOP
+    LTEXT           "dpi",IDC_STATIC,235,252,10,8
 END
 
 IDD_DLLCFG DIALOG DISCARDABLE  0, 0, 260, 250
diff --git a/programs/winecfg/resource.h b/programs/winecfg/resource.h
index 811a115..c484cee 100644
--- a/programs/winecfg/resource.h
+++ b/programs/winecfg/resource.h
@@ -152,6 +152,9 @@ #define IDC_D3D_PSHADER_MODE            
 #define IDS_SHADER_MODE_HARDWARE        8100
 #define IDS_SHADER_MODE_NONE            8101
 
+#define IDC_RES_TRACKBAR                1107
+#define IDC_RES_DPIEDIT                 1108
+
 /* applications tab */
 #define IDC_APP_LISTVIEW                1200
 #define IDC_APP_ADDAPP                  1201
diff --git a/programs/winecfg/winecfg.c b/programs/winecfg/winecfg.c
index 42f03fb..89b15e1 100644
--- a/programs/winecfg/winecfg.c
+++ b/programs/winecfg/winecfg.c
@@ -45,6 +45,30 @@ #include "resource.h"
 HKEY config_key = NULL;
 HMENU hPopupMenus = 0;
 
+/* Utility functions to convert between WCHAR and long */
+long wcstolong(WCHAR * wcs)
+{
+    int i;
+    long lRet = 0;
+    BOOL bNeg = FALSE;
+
+    for (i = 0; wcs[i] != '\0'; i++) {
+        if (i == 0 && wcs[i] == '-') {
+            bNeg = TRUE;
+            continue;
+        }
+
+        lRet = lRet * 10 + (wcs[i] - '0');
+    }
+    return (bNeg ? -lRet : lRet);
+}
+
+WCHAR *longtow(long num, WCHAR *wcs)
+{
+    static const WCHAR str[] = { '%', 'l', 'd', 0 };
+    wsprintfW(wcs, str, num);
+    return wcs;
+}
 
 /* this is called from the WM_SHOWWINDOW handlers of each tab page.
  *
diff --git a/programs/winecfg/winecfg.h b/programs/winecfg/winecfg.h
index e23c7bb..c17d8b0 100644
--- a/programs/winecfg/winecfg.h
+++ b/programs/winecfg/winecfg.h
@@ -40,6 +40,9 @@ #define IS_OPTION_FALSE(ch) \
 
 extern WCHAR* current_app; /* NULL means editing global settings  */
 
+long wcstolong(WCHAR * wcs);
+WCHAR *longtow(long num, WCHAR *wcs);
+
 /* Use get_reg_key and set_reg_key to alter registry settings. The changes made through
    set_reg_key won't be committed to the registry until process_all_settings is called,
    however get_reg_key will still return accurate information.
@@ -142,6 +145,7 @@ static inline void set_text(HWND dialog,
 }
 
 #define WINE_KEY_ROOT "Software\\Wine"
+#define MAXBUFLEN 256
 
 extern HMENU     hPopupMenus;
 
diff --git a/programs/winecfg/x11drvdlg.c b/programs/winecfg/x11drvdlg.c
index 8fa183e..9b2e6ca 100644
--- a/programs/winecfg/x11drvdlg.c
+++ b/programs/winecfg/x11drvdlg.c
@@ -36,7 +36,11 @@ #include "winecfg.h"
 WINE_DEFAULT_DEBUG_CHANNEL(winecfg);
 
 #define RES_MAXLEN 5 /* the maximum number of characters in a screen dimension. 5 digits should be plenty, what kind of crazy person runs their screen >10,000 pixels across? */
+#define MINDPI 96
+#define MAXDPI 120
+#define DEFDPI 96
 
+static const char logpixels_reg[] = "System\\CurrentControlSet\\Hardware Profiles\\Current\\Software\\Fonts";
 
 static struct SHADERMODE
 {
@@ -237,12 +241,48 @@ static void on_d3d_pshader_mode_clicked(
     else
         set_reg_key(config_key, keypath("Direct3D"), "PixelShaderMode", "disabled");
 }
+static INT read_logpixels_reg(void)
+{
+    DWORD dwLogPixels;
+    char *buf  = get_reg_key(HKEY_LOCAL_MACHINE, logpixels_reg,
+                             "LogPixels", (const char *)MAXDPI);
+    dwLogPixels = *buf;
+    HeapFree(GetProcessHeap(), 0, buf);
+    return dwLogPixels;
+}
+
+static void init_dpi_editbox(HWND hDlg)
+{
+    HWND hDpiEditBox = GetDlgItem(hDlg, IDC_RES_DPIEDIT);
+    DWORD dwLogpixels;
+    WCHAR szLogpixels[MAXBUFLEN];
+
+    dwLogpixels = read_logpixels_reg();
+    WINE_TRACE("%d\n", (int) dwLogpixels);
+
+    ZeroMemory(szLogpixels, sizeof(WCHAR) * MAXBUFLEN);
+    longtow(dwLogpixels, szLogpixels);
+    SendMessageW(hDpiEditBox, WM_SETTEXT, 0, (LPARAM) szLogpixels);
+}
+
+static void init_trackbar(HWND hDlg)
+{
+    HWND hTrackBar = GetDlgItem(hDlg, IDC_RES_TRACKBAR);
+    DWORD dwLogpixels;
+
+    dwLogpixels = read_logpixels_reg();
+
+    SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(MINDPI, MAXDPI));
+    SendMessageW(hTrackBar, TBM_SETPOS, TRUE, dwLogpixels);
+}
 
 INT_PTR CALLBACK
 GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
     switch (uMsg) {
 	case WM_INITDIALOG:
+	    init_dpi_editbox(hDlg);
+	    init_trackbar(hDlg);
 	    break;
 
         case WM_SHOWWINDOW:
@@ -290,6 +330,8 @@ GraphDlgProc(HWND hDlg, UINT uMsg, WPARA
 		    break;
 		}
 		case PSN_APPLY: {
+		    int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
+		    set_reg_key_dword(HKEY_LOCAL_MACHINE, logpixels_reg, "LogPixels", i);
                     apply();
 		    SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
 		    break;
@@ -301,6 +343,19 @@ GraphDlgProc(HWND hDlg, UINT uMsg, WPARA
 	    }
 	    break;
 
+	case WM_HSCROLL:
+	    switch (wParam) {
+		default: {
+		    WCHAR buf[MAXBUFLEN];
+		    int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
+		    ZeroMemory(buf, sizeof(WCHAR) * MAXBUFLEN);
+		    longtow(i, buf);
+		    SendMessageW(GetDlgItem(hDlg, IDC_RES_DPIEDIT), WM_SETTEXT, 0, (LPARAM) buf);
+		    break;
+		}
+	    }
+	    break;
+
 	default:
 	    break;
     }
-- 
1.4.1




More information about the wine-patches mailing list