Skip to content

Commit

Permalink
+ basic HighDPI support (don't create list views dynamically anymore)
Browse files Browse the repository at this point in the history
* small tab-order fix for SNTP dialog
* some code improvements to timer.c
  • Loading branch information
White-Tiger committed Oct 14, 2014
1 parent 3fc33af commit 17d8d04
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 119 deletions.
51 changes: 25 additions & 26 deletions Source/Clock/PageMouse.c
Expand Up @@ -5,7 +5,7 @@
#include "tclock.h"
#include <ShlObj.h>//SHBrowseForFolder

static void OnInit(HWND hDlg,HWND* hList);
static void OnInit(HWND hDlg);
static void OnApply(HWND hDlg);
static void OnDestroy();
static void OnSansho(HWND hDlg, WORD id);
Expand Down Expand Up @@ -64,8 +64,9 @@ static void SendPSChanged(HWND hDlg){

//========================================================================================
//------------------------------------------------------+++--> Update UI, listview control:
static void UpdateUIList(HWND hDlg, HWND hList, int selButton, int selClick) //---+++-->
static void UpdateUIList(HWND hDlg, int selButton, int selClick) //---+++-->
{
HWND hList=GetDlgItem(hDlg,IDC_LIST);
LVITEM lvItem; // ListView item Mouse Buttons:
int button; // mouse button 0=>Left, 1=>Right, 2=>Middle,
int click; // click count 3=>XButton 1, 4=>XButton 2
Expand Down Expand Up @@ -133,7 +134,7 @@ static void UpdateUIList(HWND hDlg, HWND hList, int selButton, int selClick) /
}
//====================================================================================================
//----------------------------------------------+++--> Update UI controls: combo boxes and radiobutton:
static void UpdateUIControls(HWND hDlg, HWND hList, int button, int click, int type) //-------+++-->
static void UpdateUIControls(HWND hDlg, int button, int click, int type) //-------+++-->
{
int func;
if(m_bTransition) return;
Expand Down Expand Up @@ -166,7 +167,7 @@ static void UpdateUIControls(HWND hDlg, HWND hList, int button, int click, int t
}
}
if(type!=2)
UpdateUIList(hDlg,hList,button,click); // little recursion here, will call UpdateUIControls later on selection change
UpdateUIList(hDlg,button,click); // little recursion here, will call UpdateUIControls later on selection change
EnableDlgItem(hDlg,IDC_MOUSEFILE,(func==MOUSEFUNC_CLIPBOARD));
EnableDlgItem(hDlg,IDC_LABMOUSEFILE,(func==MOUSEFUNC_CLIPBOARD));
if(func==MOUSEFUNC_CLIPBOARD){
Expand All @@ -180,10 +181,9 @@ static void UpdateUIControls(HWND hDlg, HWND hList, int button, int click, int t
//-------------------------------------------+++--> Dialog Procedure for Mouse Tab Dialog Messages:
INT_PTR CALLBACK PageMouseProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) //-----+++-->
{
static HWND g_hList=NULL;
switch(message){
case WM_INITDIALOG:{
OnInit(hDlg,&g_hList);
OnInit(hDlg);
return TRUE;}
case WM_DESTROY:
OnDestroy(hDlg);
Expand All @@ -199,7 +199,7 @@ INT_PTR CALLBACK PageMouseProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
for(iter=IDC_LABDROPFILESAPP; iter<=IDC_DROPFILESAPPSANSHO; ++iter)
EnableDlgItem(hDlg,iter,(sel>=2 && sel<=4));
if(!m_bTransition){
UpdateUIControls(hDlg,g_hList,-1,-1,0);
UpdateUIControls(hDlg,-1,-1,0);
g_bApplyClock=1;
SendPSChanged(hDlg);
}
Expand All @@ -213,13 +213,13 @@ INT_PTR CALLBACK PageMouseProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
/// button
}else if(id == IDC_MOUSEBUTTON && code == CBN_SELCHANGE){
int button=(int)CBGetCurSel(hDlg,IDC_MOUSEBUTTON);
UpdateUIControls(hDlg,g_hList,button,-1,0);
UpdateUIControls(hDlg,button,-1,0);
/// clicks
}else if(id >= IDC_RADSINGLE && id <= IDC_RADDOUBLE){
UpdateUIControls(hDlg,g_hList,-1,id-IDC_RADSINGLE,0);
UpdateUIControls(hDlg,-1,id-IDC_RADSINGLE,0);
/// Mouse Function
}else if(id == IDC_MOUSEFUNC && code == CBN_SELCHANGE){
UpdateUIControls(hDlg,g_hList,-1,-1,1);
UpdateUIControls(hDlg,-1,-1,1);
SendPSChanged(hDlg);
/// Mouse Function - File
}else if(id == IDC_MOUSEFILE && code==EN_CHANGE){
Expand Down Expand Up @@ -263,6 +263,7 @@ INT_PTR CALLBACK PageMouseProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
break;
case LVN_ITEMCHANGED:
if(itm->uNewState&LVIS_SELECTED){
HWND hList=GetDlgItem(hDlg,IDC_LIST);
char szButtonBuf[TNY_BUFF];
char szClickBuf[TNY_BUFF];
char* szButton;
Expand All @@ -274,16 +275,16 @@ INT_PTR CALLBACK PageMouseProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
lvItem.cchTextMax=TNY_BUFF;
lvItem.iSubItem=0;
lvItem.pszText=szButtonBuf;
ListView_GetItem(g_hList,&lvItem);
ListView_GetItem(hList,&lvItem);
szButton=lvItem.pszText;
lvItem.iSubItem=1;
lvItem.pszText=szClickBuf;
ListView_GetItem(g_hList,&lvItem);
ListView_GetItem(hList,&lvItem);
for(button=0; button<m_mouseButtonCount; ++button){
if(strcmp(m_mouseButton[button],szButton)) continue;
for(click=0; click<m_mouseClickCount; ++click){
if(strcmp(m_mouseClick[click],lvItem.pszText)) continue;
UpdateUIControls(hDlg,g_hList,button,click,2);
UpdateUIControls(hDlg,button,click,2);
button=m_mouseButtonCount;
break;
}
Expand All @@ -297,8 +298,9 @@ INT_PTR CALLBACK PageMouseProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
}
//================================================================================================
//------------------------//----------------------------++--> Initialize Mouse Tab Dialog Controls:
void OnInit(HWND hDlg,HWND* hList) //-----------------------------------------------------+++-->
void OnInit(HWND hDlg) //-----------------------------------------------------+++-->
{
HWND hList=GetDlgItem(hDlg,IDC_LIST);
char entry[3+4];
char buf[LRG_BUFF];
int button, click;
Expand Down Expand Up @@ -342,40 +344,37 @@ void OnInit(HWND hDlg,HWND* hList) //-----------------------------------------
if(!*buf) memcpy(buf,"\"T-Clock\" LDATE",16);
SetDlgItemText(hDlg,IDC_TOOLTIP,buf);
/// setup list view
*hList = CreateWindow(WC_LISTVIEW, NULL, WS_CHILD|WS_VSCROLL|
LVS_NOSORTHEADER|LVS_REPORT|LVS_SINGLESEL, 17, 117, 430, 160, hDlg, 0, 0, NULL);
ListView_SetExtendedListViewStyle(*hList,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_DOUBLEBUFFER);
SetXPWindowTheme(*hList,L"Explorer",NULL);
SetWindowLongPtr(*hList,GWLP_ID,IDC_LIST);
ListView_SetExtendedListViewStyle(hList,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_DOUBLEBUFFER);
SetXPWindowTheme(hList,L"Explorer",NULL);

lvCol.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvCol.iSubItem=0;
lvCol.pszText="Button";
lvCol.fmt=LVCFMT_CENTER;
lvCol.cx=60;
ListView_InsertColumn(*hList,lvCol.iSubItem,&lvCol);
ListView_InsertColumn(hList,lvCol.iSubItem,&lvCol);

++lvCol.iSubItem;
lvCol.pszText="Click Type";
lvCol.fmt=LVCFMT_CENTER;
lvCol.cx=70;
ListView_InsertColumn(*hList,lvCol.iSubItem,&lvCol);
ListView_InsertColumn(hList,lvCol.iSubItem,&lvCol);

++lvCol.iSubItem;
lvCol.pszText="Action";
lvCol.fmt=LVCFMT_LEFT;
lvCol.cx=160;
ListView_InsertColumn(*hList,lvCol.iSubItem,&lvCol);
ListView_InsertColumn(hList,lvCol.iSubItem,&lvCol);

++lvCol.iSubItem;
lvCol.pszText="Other";
lvCol.fmt=LVCFMT_LEFT;
lvCol.cx=140;
ListView_InsertColumn(*hList,lvCol.iSubItem,&lvCol);
ShowWindow(*hList,SW_SHOW);
lvCol.cx=151;
ListView_InsertColumn(hList,lvCol.iSubItem,&lvCol);
ShowWindow(hList,SW_SHOW);
m_bTransition=0; // end transition
/// select first mouse setup and UpdateMouseClickList
UpdateUIControls(hDlg,*hList,0,-1,0); // pre-select first mouse button
UpdateUIControls(hDlg,0,-1,0); // pre-select first mouse button
}
//================================================================================================
//-------------------------//-------------------------+++--> Apply (Settings) Button Event Handler:
Expand Down
36 changes: 13 additions & 23 deletions Source/Clock/SNTP.c
Expand Up @@ -28,7 +28,7 @@ typedef struct { // Close Socket on Request TimeOut Structure

extern hotkey_t* tchk;

HWND hLogView;
static HWND m_dlg;
static BOOL bSaveLog;
static BOOL bMessage;
static BOOL bGUI = FALSE;
Expand Down Expand Up @@ -77,7 +77,7 @@ void Log(const char* msg) //--------------------------------------------------
lvItem.iSubItem = 0; // Hold These at Zero So the File Loads Backwards
lvItem.iItem = 0; //-----+++--> Which Puts the Most Recent Info on Top.
lvItem.pszText = s;
ListView_InsertItem(hLogView, &lvItem);
ListView_InsertItem(GetDlgItem(m_dlg,IDC_LIST), &lvItem);
}

if(bMessage) {
Expand Down Expand Up @@ -491,10 +491,11 @@ void OnInit(HWND hDlg) //-----------------------------------------------------
LVCOLUMN lvCol;
LVITEM lvItem;
int i, count;
HWND hList=GetDlgItem(hDlg,IDC_LIST);

m_dlg=hDlg;
// Get the List of Configured Time Servers:
//======================================//==========================================
GetMyRegStr(subkey, "Server", server, 80, "");

count = GetMyRegLong(subkey, "ServerNum", 0);
for(i = 1; i <= count; i++) {
char s[MAX_BUFF], entry[TNY_BUFF];
Expand All @@ -503,7 +504,6 @@ void OnInit(HWND hDlg) //-----------------------------------------------------
GetMyRegStr(subkey, entry, s, 80, "");
if(s[0]) CBAddString(hDlg, IDCBX_NTPSERVER, s);
}

if(server[0]) {
i = (int)CBFindStringExact(hDlg, IDCBX_NTPSERVER, server);
if(i == LB_ERR) {
Expand All @@ -512,7 +512,6 @@ void OnInit(HWND hDlg) //-----------------------------------------------------
}
CBSetCurSel(hDlg, IDCBX_NTPSERVER, i);
}

if(!g_hIconDel) {
g_hIconDel = LoadImage((HANDLE)GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_DEL),
Expand All @@ -523,19 +522,16 @@ void OnInit(HWND hDlg) //-----------------------------------------------------
IMAGE_ICON, (LPARAM)g_hIconDel);

// Get the Sync Sound File:
//======================================================//==========================
GetMyRegStr(subkey, "Sound", szFile, MAX_BUFF, "");
SetDlgItemText(hDlg, IDCE_SYNCSOUND, szFile);

// Get the Confirmation Options:
//=================================================//===============================
bSaveLog = GetMyRegLongEx(subkey, "SaveLog", 0);
CheckDlgButton(hDlg, IDCBX_SNTPLOG, bSaveLog);
bMessage = GetMyRegLongEx(subkey, "MessageBox", 0);
CheckDlgButton(hDlg, IDCBX_SNTPMESSAGE, bMessage);

// Load & Display the Configured Synchronization HotKey:
//=========================//=======================================================

tchk = (hotkey_t*)malloc(sizeof(hotkey_t));
tchk[0].bValid = GetMyRegLongEx("HotKeys\\HK5", "bValid", 0);
GetMyRegStrEx("HotKeys\\HK5", "szText", tchk[0].szText, TNY_BUFF, "None");
Expand All @@ -547,27 +543,21 @@ void OnInit(HWND hDlg) //-----------------------------------------------------
// Subclass the Edit Controls
OldEditClassProc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(GetDlgItem(hDlg, IDCE_SYNCHOTKEY), GWLP_WNDPROC);
SetWindowLongPtr(GetDlgItem(hDlg, IDCE_SYNCHOTKEY), GWLP_WNDPROC, (LONG_PTR)SubClassEditProc);
//-+> Create & Show the Log File ListView Control:
//===============================//=================================================
hLogView = CreateWindow(WC_LISTVIEW, NULL, WS_CHILD|WS_VSCROLL|LVS_REPORT|
LVS_NOSORTHEADER|LVS_SINGLESEL, 19, 188, 428, 89, hDlg, 0, 0, NULL);
ListView_SetExtendedListViewStyle(hLogView, LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_DOUBLEBUFFER);
SetXPWindowTheme(hLogView,L"Explorer",NULL);

ShowWindow(hLogView, SW_SHOW); // Populate Its Column:
//==========================================================//======================

// init listview
ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_DOUBLEBUFFER);
SetXPWindowTheme(hList,L"Explorer",NULL);

lvCol.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvCol.cx = 280; //-+-// Set Column Width in Pixels
lvCol.iSubItem = 0; // This is the First & Only Column
lvCol.pszText = "Synchronization History"; // Header Text
ListView_InsertColumn(hLogView, 0, &lvCol);
ListView_InsertColumn(hList, 0, &lvCol);

// Test For: SE_SYSTEMTIME_NAME Priviledge Before Enabling Sync Now Button:
//======//==========================================================================
EnableDlgItem(hDlg, IDCB_SYNCNOW, GetSetTimePermissions());

// Load the Time Synchronization Log File:
//=======================================//=========================================
strcpy(szFile, g_mydir);
add_title(szFile, "SNTP.log");

Expand All @@ -584,7 +574,7 @@ void OnInit(HWND hDlg) //-----------------------------------------------------
if(fgets(szLine, MAX_BUFF, stReport)) {
szLine[strcspn(szLine, "\n")] = '\0'; // Remove the Newline Character
lvItem.pszText = szLine;
ListView_InsertItem(hLogView, &lvItem);
ListView_InsertItem(hList, &lvItem);
} else {
fclose(stReport);
return; // Remember: Any Code Placed Below Here Will FAIL
Expand Down
24 changes: 13 additions & 11 deletions Source/Clock/tClock.rc
Expand Up @@ -267,7 +267,7 @@ BEGIN
CONTROL "Second",IDC_SECOND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,106,109,38,11
CONTROL "Show Internet Time (.beats)",IDC_INTERNETTIME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,164,109,105,11
CONTROL "12H",IDC_12HOUR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,24,128,48,11
RTEXT "AM Symbol:",IDC_LABAMSYMBOL,85,130,38,12
RTEXT "AM Symbol:",IDC_LABAMSYMBOL,83,130,40,12
COMBOBOX IDC_AMSYMBOL,128,128,35,50,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
RTEXT "PM Symbol:",IDC_LABPMSYMBOL,182,130,38,12
COMBOBOX IDC_PMSYMBOL,226,128,35,50,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
Expand Down Expand Up @@ -295,7 +295,7 @@ BEGIN
RTEXT "Format", IDC_LABMOUSEFILE, 141, 48, 27, 10, SS_RIGHT
EDITTEXT IDC_MOUSEFILE, 174, 46, 111, 12, ES_AUTOHSCROLL
GROUPBOX "Currently Configured Mouse Options:", IDC_STATIC, 6, 62, 298, 113
// IDC_LIST
CONTROL "",IDC_LIST,WC_LISTVIEW,WS_TABSTOP|LVS_ALIGNLEFT|LVS_NOSORTHEADER|LVS_SINGLESEL|LVS_REPORT, 8,71,294,103
AUTOCHECKBOX "Mouse-Over Tooltip Text:", IDCB_TOOLTIP, 6, 184, 92, 8
EDITTEXT IDC_TOOLTIP, 102, 182, 202, 12, ES_AUTOHSCROLL
END
Expand All @@ -312,7 +312,7 @@ BEGIN
CONTROL "Network Drive(s)",IDC_QMEN_NET,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,37,69,11
CONTROL "Display Properties",IDC_QMEN_DISPLAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,225,37,72,11
GROUPBOX "Custom Quicky Items (double click item to edit)",IDC_QMEN_GROUP2,6,62,298,132
CONTROL "",IDC_QMEN_LIST,WC_LISTVIEW,WS_TABSTOP|LVS_ALIGNLEFT|LVS_SINGLESEL|LVS_REPORT, 7,72,295,122
CONTROL "",IDC_QMEN_LIST,WC_LISTVIEW,WS_TABSTOP|LVS_ALIGNLEFT|LVS_NOSORTHEADER|LVS_SINGLESEL|LVS_REPORT, 7,72,295,122
END

IDD_QUICKY_ADD DIALOGEX 0, 0, 310, 200
Expand Down Expand Up @@ -458,6 +458,7 @@ STYLE DS_SHELLFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VIS
CAPTION "Timer Watch"
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "",IDC_LIST,WC_LISTVIEW,WS_TABSTOP|LVS_ALIGNLEFT|LVS_NOSORTHEADER|LVS_SINGLESEL|LVS_REPORT, 0,0,186,93
END

IDD_SNTPCONFIG DIALOGEX 0, 0, 310, 200
Expand All @@ -467,21 +468,22 @@ FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "OK",IDOK,68,179,50,14
PUSHBUTTON "Cancel",IDCANCEL,210,179,50,14
COMBOBOX IDCBX_NTPSERVER,90,14,85,120,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Synchronization Source",IDC_STATIC,7,3,296,32
RTEXT "Time Server:",IDC_STATIC,44,15,42,8
PUSHBUTTON "Sync Now",IDCB_SYNCNOW,210,14,50,13,WS_DISABLED
COMBOBOX IDCBX_NTPSERVER,90,14,85,120,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "X",IDCB_DELSERVER,184,14,15,13,BS_ICON
GROUPBOX "Time Synchronization Activity Log",IDC_STATIC,7,107,296,68
PUSHBUTTON "Sync Now",IDCB_SYNCNOW,210,14,50,13,WS_DISABLED
GROUPBOX "Confirmation Options",IDC_STATIC,7,38,296,33
GROUPBOX "Synchronization Source",IDC_STATIC,7,3,296,32
GROUPBOX "Synchronize Now HotKey",IDC_STATIC,7,74,296,31
EDITTEXT IDCE_SYNCSOUND,192,50,85,12,ES_AUTOHSCROLL
RTEXT "Sound:",IDC_STATIC,165,52,24,8
PUSHBUTTON "...",IDCB_SYNCSOUNDBROWSE,281,50,14,12
CONTROL "Save Log",IDCBX_SNTPLOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,27,50,45,11
CONTROL "MessageBox",IDCBX_SNTPMESSAGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,92,50,56,11
RTEXT "Sound:",IDC_STATIC,165,52,24,8
EDITTEXT IDCE_SYNCSOUND,192,50,85,12,ES_AUTOHSCROLL
PUSHBUTTON "...",IDCB_SYNCSOUNDBROWSE,281,50,14,12
GROUPBOX "Synchronize Now HotKey",IDC_STATIC,7,74,296,31
EDITTEXT IDCE_SYNCHOTKEY,29,85,172,12,ES_AUTOHSCROLL
PUSHBUTTON "Reset",IDCB_HK_SNTP,210,85,50,12
GROUPBOX "Time Synchronization Activity Log",IDC_STATIC,7,107,296,68
CONTROL "",IDC_LIST,WC_LISTVIEW,WS_TABSTOP|LVS_ALIGNLEFT|LVS_NOSORTHEADER|LVS_SINGLESEL|LVS_REPORT, 11,115,288,57
END

IDD_ALARMMSG DIALOGEX 0, 0, 255, 168
Expand Down
1 change: 0 additions & 1 deletion Source/Clock/tclock.h
Expand Up @@ -144,7 +144,6 @@ void CancelAllTimersOnStartUp();
void EndAllTimers();
void DialogTimer();
void OnTimerTimer(HWND hwnd);
int GetTimerInfo(char* dst, int num, BOOL bNameOnly);

// StopWatch.c
BOOL IsDialogStopWatchMessage(HWND hwnd, MSG* msg);
Expand Down

0 comments on commit 17d8d04

Please sign in to comment.