commit da595817c04afc3749535467921753696b68f39e
parent aa3c971b78c3cfd4f7cb2ee009b8c6b48cdd353f
Author: cnlohr <lohr85@gmail.com>
Date: Thu, 22 Nov 2018 18:21:18 -0500
Update adding code to remember the last usage
Diffstat:
3 files changed, 52 insertions(+), 14 deletions(-)
diff --git a/cnping.c b/cnping.c
@@ -486,6 +486,35 @@ void DrawFrame( void )
const char * glargv[10];
int glargc = 0;
+int RegString( int write, char * data, DWORD len )
+{
+ HKEY hKey;
+ if( RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\cnping", 0, NULL,
+ REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS)
+ {
+ if( write )
+ {
+ RegSetValueExA( hKey, "history", 0, REG_SZ, data, len );
+ return 0;
+ }
+ else
+ {
+ DWORD type;
+ if( RegGetValueA( hKey, "", "history", 0x02, &type, data, &len ) == ERROR_SUCCESS )
+ {
+ return 0;
+ }
+ return -16;
+ }
+
+ RegCloseKey( hKey );
+ }
+ else
+ {
+ return -15;
+ }
+}
+
INT_PTR CALLBACK TextEntry( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
@@ -494,6 +523,13 @@ INT_PTR CALLBACK TextEntry( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
case WM_INITDIALOG:
SetDlgItemText(hwndDlg, 4, "0.02");
SetDlgItemText(hwndDlg, 5, "0" );
+
+ char data[1024];
+ if( !RegString( 0, data, sizeof( data ) ) )
+ {
+ SetDlgItemText(hwndDlg, 3, data);
+ }
+
return 0;
case WM_COMMAND:
switch( wParam>>24 )
@@ -508,13 +544,15 @@ INT_PTR CALLBACK TextEntry( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
exit( -1 );
}
- char Address[1024]; GetDlgItemText(hwndDlg, 3, Address, sizeof(Address));
- char Period[1024]; GetDlgItemText(hwndDlg, 4, Period, sizeof(Period));
- char Extra[1024]; GetDlgItemText(hwndDlg, 5, Extra, sizeof(Extra));
- char Scaling[1024]; GetDlgItemText(hwndDlg, 6, Scaling, sizeof(Scaling));
+ char Address[128]; GetDlgItemText(hwndDlg, 3, Address, sizeof(Address));
+ char Period[128]; GetDlgItemText(hwndDlg, 4, Period, sizeof(Period));
+ char Extra[128]; GetDlgItemText(hwndDlg, 5, Extra, sizeof(Extra));
+ char Scaling[128]; GetDlgItemText(hwndDlg, 6, Scaling, sizeof(Scaling));
if( strlen( Address ) )
{
+ RegString( 1, Address, strlen( Address ) );
+
glargc = 2;
glargv[1] = strdup( Address );
if( strlen( Period ) )
diff --git a/cnping.exe b/cnping.exe
Binary files differ.
diff --git a/resources.rc b/resources.rc
@@ -3,19 +3,19 @@
#include <windows.h>
LANGUAGE 9, SUBLANG_DEFAULT
-IPDialog DIALOG 10, 10, 300, 100
+IPDialog DIALOG 10, 10, 340, 100
STYLE WS_CAPTION | WS_SYSMENU
CAPTION "cnping"
BEGIN
- LTEXT "Usage: cnping [host] [period] [extra size] [y-axis scaling]", 0, 60, 0, 300, 20, SS_LEFT
- LTEXT "[host] -- domain or IP address of icmp ping, or http://host", 0, 60, 15, 300, 20, SS_LEFT
- LTEXT "[period] -- period in seconds (optional), default is 0.02", 0, 60, 30, 300, 20, SS_LEFT
- LTEXT "[extra size] -- ping packet extra size (above 12), optional, default = 0", 0, 60, 45, 300, 10, SS_LEFT
- LTEXT "[const y-axis scaling] -- use a fixed scaling factor instead of auto scaling", 0, 60, 60, 300, 10, SS_LEFT
- EDITTEXT 3, 1, 15, 58, 12
- EDITTEXT 4, 1, 30, 58, 12
- EDITTEXT 5, 1, 45, 58, 12
- EDITTEXT 6, 1, 60, 58, 12
+ LTEXT "Usage: cnping [host] [period] [extra size] [y-axis scaling]", 0, 90, 0, 300, 20, SS_LEFT
+ LTEXT "[host] -- domain or IP address of icmp ping, or http://host", 0, 90, 15, 300, 20, SS_LEFT
+ LTEXT "[period] -- period in seconds (optional), default is 0.02", 0, 90, 30, 300, 20, SS_LEFT
+ LTEXT "[extra size] -- ping packet extra size (above 12), optional, default = 0", 0, 90, 45, 300, 10, SS_LEFT
+ LTEXT "[const y-axis scaling] -- use a fixed scaling factor instead of auto scaling", 0, 90, 60, 300, 10, SS_LEFT
+ EDITTEXT 3, 1, 15, 88, 12
+ EDITTEXT 4, 1, 30, 88, 12
+ EDITTEXT 5, 1, 45, 88, 12
+ EDITTEXT 6, 1, 60, 88, 12
PUSHBUTTON "&Ping", 7, 25, 80, 100, 10
PUSHBUTTON "&Close", 8, 175, 80, 100, 10
END