summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-04-17 00:34:01 +0000
committerIan C <ianc@noddybox.co.uk>2005-04-17 00:34:01 +0000
commit7740ebb87b8aa440f10095a77fea5d781844dd97 (patch)
tree29c43f23bcb957d3177db1282d8db5e44b79dee9
parentba88028c9e6f7a2da0b9bc31e86ca9633613745e (diff)
Added Registry class and default message box titles
-rw-r--r--src/GNUmakefile5
-rw-r--r--src/common.cpp26
-rw-r--r--src/test/w32dtst.cpp46
-rw-r--r--src/w32dlib/base.h2
-rw-r--r--src/w32dlib/common.h30
-rw-r--r--src/w32dlib/w32dlib.h1
6 files changed, 95 insertions, 15 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile
index e0ff4ae..88fc7a0 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -18,7 +18,7 @@
#
# -------------------------------------------------------------------------
#
-# $Id: GNUmakefile,v 1.10 2005-04-15 23:56:34 ianc Exp $
+# $Id: GNUmakefile,v 1.11 2005-04-17 00:34:01 ianc Exp $
#
@@ -67,7 +67,8 @@ SOURCES = autocheck.cpp \
window.cpp \
combobox.cpp \
datax.cpp \
- radiobutton.cpp
+ radiobutton.cpp \
+ registry.cpp
HEADERS = w32dlib/*.h
diff --git a/src/common.cpp b/src/common.cpp
index 9bc1b80..59c7695 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -25,6 +25,10 @@
namespace W32DLib
{
+static const char *def_msg="Message";
+static const char *def_err="Error";
+static const char *def_qry="Error";
+
// ------------------------------------------------------------
//
void Common::Initialise()
@@ -36,9 +40,19 @@ void Common::Initialise()
// ------------------------------------------------------------
//
+void Common::MessageTitle(const char *title)
+{
+ def_msg=title;
+ def_err=title;
+ def_qry=title;
+}
+
+
+// ------------------------------------------------------------
+//
void Common::Message(HWND parent, const char *title, const char *msg)
{
- ::MessageBox(parent,msg,title ? title:"Message",MB_ICONINFORMATION|MB_OK);
+ ::MessageBox(parent,msg,title ? title:def_msg,MB_ICONINFORMATION|MB_OK);
}
@@ -46,7 +60,7 @@ void Common::Message(HWND parent, const char *title, const char *msg)
//
void Common::Message(HWND parent, const char *title, const std::string& msg)
{
- ::MessageBox(parent,msg.c_str(),title ? title:"Message",
+ ::MessageBox(parent,msg.c_str(),title ? title:def_msg,
MB_ICONINFORMATION|MB_OK);
}
@@ -55,7 +69,7 @@ void Common::Message(HWND parent, const char *title, const std::string& msg)
//
void Common::Error(HWND parent, const char *title, const char *msg)
{
- ::MessageBox(parent,msg,title ? title:"Error",MB_ICONSTOP|MB_OK);
+ ::MessageBox(parent,msg,title ? title:def_err,MB_ICONSTOP|MB_OK);
}
@@ -63,7 +77,7 @@ void Common::Error(HWND parent, const char *title, const char *msg)
//
void Common::Error(HWND parent, const char *title, const std::string& msg)
{
- ::MessageBox(parent,msg.c_str(),title ? title:"Error",MB_ICONSTOP|MB_OK);
+ ::MessageBox(parent,msg.c_str(),title ? title:def_err,MB_ICONSTOP|MB_OK);
}
@@ -71,7 +85,7 @@ void Common::Error(HWND parent, const char *title, const std::string& msg)
//
bool Common::Query(HWND parent, const char *title, const char *msg)
{
- return ::MessageBox(parent,msg,title ? title:"Question",
+ return ::MessageBox(parent,msg,title ? title:def_qry,
MB_ICONQUESTION|MB_YESNO)==IDOK;
}
@@ -80,7 +94,7 @@ bool Common::Query(HWND parent, const char *title, const char *msg)
//
bool Common::Query(HWND parent, const char *title, const std::string& msg)
{
- return ::MessageBox(parent,msg.c_str(),title ? title:"Question",
+ return ::MessageBox(parent,msg.c_str(),title ? title:def_qry,
MB_ICONQUESTION|MB_YESNO)==IDOK;
}
diff --git a/src/test/w32dtst.cpp b/src/test/w32dtst.cpp
index 6d579cc..bc5e6a6 100644
--- a/src/test/w32dtst.cpp
+++ b/src/test/w32dtst.cpp
@@ -334,6 +334,40 @@ private:
}
};
+static void ReadInt(const char *mode, W32DLib::Registry& r, const char *name)
+{
+ unsigned i;
+ bool res=r.Read(name,i);
+
+ std::cout << "ReadInt(mode=" << mode
+ << ") res=" << res << " val=" << i << std::endl;
+}
+
+static void ReadStr(const char *mode, W32DLib::Registry& r, const char *name)
+{
+ std::string i;
+ bool res=r.Read(name,i);
+
+ std::cout << "ReadStr(mode=" << mode
+ << ") res=" << res << " val=" << i << std::endl;
+}
+
+static void WriteInt(const char *mode, W32DLib::Registry& r, const char *name)
+{
+ unsigned i=666;
+ bool res=r.Write(name,i);
+
+ std::cout << "WriteInt(mode=" << mode << ") res=" << res << std::endl;
+}
+
+static void WriteStr(const char *mode, W32DLib::Registry& r, const char *name)
+{
+ std::string i("Hello World");
+ bool res=r.Write(name,i);
+
+ std::cout << "WriteInt(mode=" << mode << ") res=" << res << std::endl;
+}
+
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
@@ -348,6 +382,18 @@ int WINAPI WinMain (HINSTANCE hInstance,
std::cout << "DATAX_TEST enabled" << std::endl;
#endif
+ W32DLib::Registry rw(HKEY_CURRENT_USER,"Software\\Noddybox\\w32dlibtest",false);
+ W32DLib::Registry rd(HKEY_CURRENT_USER,"Software\\Noddybox\\w32dlibtest");
+
+ ReadInt("rw",rw,"int");
+ ReadStr("rw",rw,"str");
+ ReadInt("ro",rd,"int");
+ ReadStr("ro",rd,"str");
+ WriteInt("rw",rw,"int");
+ WriteStr("rw",rw,"str");
+ WriteInt("ro",rd,"int");
+ WriteStr("ro",rd,"str");
+
i=t.ShowModal(hInstance,NULL);
if (i==IDOK)
diff --git a/src/w32dlib/base.h b/src/w32dlib/base.h
index 639c368..fb0af32 100644
--- a/src/w32dlib/base.h
+++ b/src/w32dlib/base.h
@@ -32,7 +32,7 @@
#include <sstream>
#endif
-/// \brief W32DLib Implements a simple wrapper around common Windows
+/// \brief W32DLib Implements a simple wrapper around some common Windows
/// dialog functionality.
///
namespace W32DLib
diff --git a/src/w32dlib/common.h b/src/w32dlib/common.h
index 7f49c08..de5364f 100644
--- a/src/w32dlib/common.h
+++ b/src/w32dlib/common.h
@@ -40,10 +40,23 @@ namespace W32DLib
static void Initialise();
+ /// \brief Sets the default titles for message boxes.
+ ///
+ /// All MessageBox type calls provide a default title if non is
+ /// provided. Using this you can set the default title to an
+ /// application specific one.
+ ///
+ /// \param title The default title. This pointer must remain valid
+ /// throughout the life of the application.
+ ///
+ static void MessageTitle(const char *title);
+
+
/// \brief Displays a message box.
///
/// \param parent Parent window (NULL for none)
- /// \param title The title to display (NULL for default "Message")
+ /// \param title The title to display. NULL for default ("Message") or
+ /// to use the default supplied to MessageTitle().
/// \param msg The message to display.
///
static void Message(HWND parent, const char *title,
@@ -53,7 +66,8 @@ namespace W32DLib
/// \brief Displays a message box.
///
/// \param parent Parent window (NULL for none)
- /// \param title The title to display (NULL for default "Message")
+ /// \param title The title to display. NULL for default ("Message") or
+ /// to use the default supplied to MessageTitle().
/// \param msg The message to display.
///
static void Message(HWND parent, const char *title,
@@ -63,7 +77,8 @@ namespace W32DLib
/// \brief Displays an error message box.
///
/// \param parent Parent window (NULL for none)
- /// \param title The title to display (NULL for default "Error")
+ /// \param title The title to display. NULL for default ("Error") or
+ /// to use the default supplied to MessageTitle().
/// \param msg The error message to display.
///
static void Error(HWND parent, const char *title,
@@ -73,7 +88,8 @@ namespace W32DLib
/// \brief Displays an error message box.
///
/// \param parent Parent window (NULL for none)
- /// \param title The title to display (NULL for default "Error")
+ /// \param title The title to display. NULL for default ("Error") or
+ /// to use the default supplied to MessageTitle().
/// \param msg The error message to display.
///
static void Error(HWND parent, const char *title,
@@ -83,7 +99,8 @@ namespace W32DLib
/// \brief Displays a Yes/No message box.
///
/// \param parent Parent window (NULL for none)
- /// \param title The title to display (NULL for default "Question")
+ /// \param title The title to display. NULL for default ("Question") or
+ /// to use the default supplied to MessageTitle().
/// \param msg The message to display.
/// \return True if the user selects Yes.
///
@@ -94,7 +111,8 @@ namespace W32DLib
/// \brief Displays a Yes/No message box.
///
/// \param parent Parent window (NULL for none)
- /// \param title The title to display (NULL for default "Question")
+ /// \param title The title to display. NULL for default ("Question") or
+ /// to use the default supplied to MessageTitle().
/// \param msg The message to display.
/// \return True if the user selects Yes.
///
diff --git a/src/w32dlib/w32dlib.h b/src/w32dlib/w32dlib.h
index 41d53d0..47f0de2 100644
--- a/src/w32dlib/w32dlib.h
+++ b/src/w32dlib/w32dlib.h
@@ -33,6 +33,7 @@
#include <w32dlib/common.h>
#include <w32dlib/combobox.h>
#include <w32dlib/radiobutton.h>
+#include <w32dlib/registry.h>
#endif // W32DLIB_H