Explorar el Código

登录做好了

zhangyang hace 6 años
padre
commit
c5b7d210e7

BIN
bin/Win32/Debug/zhipuzi_pos_windows/db/pos.db


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 42 - 17
bin/Win32/Debug/zhipuzi_pos_windows/skin/login.xml


+ 0 - 1
bin/Win32/Debug/zhipuzi_pos_windows/skin/main.xml

@@ -19,7 +19,6 @@
     				<Control />
     				<Option name="main_waimai" text="外卖" width="64" group="menubar" selected="true" hotimage="tab_back.bmp" selectedimage="headerctrl_down.bmp" selectedhotimage="headerctrl_hot.bmp" />
 					<Option name="main_setting" text="设置" width="64" group="menubar" hotimage="tab_back.bmp" selectedimage="headerctrl_down.bmp" selectedhotimage="headerctrl_hot.bmp" />
-					<Option name="main_contact" text="联系我们" width="64" group="menubar" hotimage="tab_back.bmp" selectedimage="headerctrl_down.bmp" selectedhotimage="headerctrl_hot.bmp" />
     			</HorizontalLayout>
     			<HorizontalLayout width="94" >
     				<Button name="minbtn" maxwidth="26" maxheight="18" normalimage="file='frame_btn_min.bmp' source='0,0,26,18' mask='#FFFF00FF'" hotimage="file='frame_btn_min.bmp' source='26,0,52,18' mask='#FFFF00FF'" pushedimage="file='frame_btn_min.bmp' source='52,0,78,18' mask='#FFFF00FF'"/>

BIN
bin/Win32/Debug/zhipuzi_pos_windows/zhipuzi_pos_windows.exe


BIN
bin/Win32/Debug/zhipuzi_pos_windows_server/zhipuzi_pos_windows_server.exe


+ 13 - 0
lewaimai_dispatch/tool/CSetting.cpp

@@ -8,6 +8,7 @@ std::vector<ChufangPrinter> CSetting::m_chufang_printers;
 std::mutex CSetting::m_mutex;
 std::vector<FoodType> CSetting::m_foodtypes;
 std::map<std::string, std::string> CSetting::m_foodtype_id_name;
+std::map<string, string> CSetting::m_users;
 
 CSetting::CSetting()
 {
@@ -181,6 +182,12 @@ void CSetting::Init()
 		m_paramsMap[setting_is_auto_login] = "1";
 	}
 
+	std::string setting_is_remember_password = "setting_is_remember_password";
+	if (m_paramsMap.find(setting_is_remember_password) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_is_remember_password] = "1";
+	}
+
 	std::string setting_is_close_min = "setting_is_close_min";
 	if (m_paramsMap.find(setting_is_close_min) == m_paramsMap.end())
 	{
@@ -205,4 +212,10 @@ void CSetting::SaveChufangPrinter()
 {
 	CSqlite3 sqllite;
 	sqllite.SaveChufangPrinter(m_chufang_printers);
+}
+
+void CSetting::SaveUsers()
+{
+	CSqlite3 sqllite;
+	sqllite.SaveUsers(m_users);
 }

+ 29 - 0
lewaimai_dispatch/tool/CSetting.h

@@ -38,6 +38,31 @@ public:
 
 	static ChufangPrinter GetChufangPrinter(std::string date);
 
+	static void SetUser(std::string name, std::string password, bool isSave = true)
+	{
+		m_users[name] = password;
+
+		if (isSave)
+		{
+			SaveUsers();
+		}
+	}
+
+	static std::string GetUser(std::string name)
+	{
+		if (m_users.find(name) == m_users.end())
+		{
+			return "";
+		}
+
+		return m_users[name];
+	}
+
+	static std::map<string, string> getUsers()
+	{
+		return m_users;
+	}
+
 	//刚打开程序的时候,根据数据库初始化内存,并且添加默认参数
 	static void Init();
 
@@ -93,6 +118,8 @@ public:
 	 **/
 	static void SaveChufangPrinter();
 
+	static void SaveUsers();
+
 private:
 	static std::map<std::string, std::string> m_paramsMap;
 	static std::vector<ChufangPrinter> m_chufang_printers;
@@ -103,5 +130,7 @@ private:
 
 	//从商品分类的id到name的映射
 	static std::map<std::string, std::string> m_foodtype_id_name;
+
+	static std::map<string, string> m_users;
 };
 

+ 107 - 0
lewaimai_dispatch/tool/CSqlite3.cpp

@@ -213,6 +213,85 @@ bool CSqlite3::InitConfig()
         }
     }
 
+	sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_user';";
+
+	//读取厨房打印机的参数
+	if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+	{
+		if (sqlite3_step(stmt) == SQLITE_ROW)
+		{
+			int count = sqlite3_column_int(stmt, 0);
+
+			if (count == 0)
+			{
+				//说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
+				sqlite3_finalize(stmt);
+				stmt = NULL;
+
+				sql = "CREATE TABLE pos_user("  \
+					"id         INTEGER          PRIMARY KEY AUTOINCREMENT,"\
+					"username       CHAR(100)        NOT NULL," \
+					"password         CHAR(100)        NOT NULL);";
+
+				if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+				{
+					//执行该语句
+					if (sqlite3_step(stmt) != SQLITE_DONE)
+					{
+						std::string err = sqlite3_errmsg(m_db);
+						LOG_INFO("create table fail: " << err.c_str());
+
+						sqlite3_finalize(stmt);
+						return false;
+					}
+
+					//走到这里就是表创建成功了
+					LOG_INFO("create table success");
+					sqlite3_finalize(stmt);
+				}
+
+				else
+				{
+					LOG_INFO("create table prepare fail: " << sqlite3_errmsg(m_db));
+
+					sqlite3_finalize(stmt);
+
+					return false;
+				}
+			}
+
+			else
+			{
+				//说明已经有这个表了,就不用再创建了
+				sqlite3_finalize(stmt);
+			}
+
+			std::string sql = "SELECT * FROM pos_user;";
+			sqlite3_stmt * stmt = NULL;
+
+			if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
+			{
+				while (sqlite3_step(stmt) == SQLITE_ROW)
+				{
+					std::string username = (char*)sqlite3_column_text(stmt, 1);
+					std::string password = (char*)sqlite3_column_text(stmt, 2);
+
+					//这里仅仅是把数据库内容读到内存,所以之类用false
+					CSetting::SetUser(username, password);
+				}
+
+				sqlite3_finalize(stmt);
+			}
+
+			else
+			{
+				//异常情况
+				sqlite3_finalize(stmt);
+				return false;
+			}
+		}
+	}
+
     return true;
 }
 
@@ -276,3 +355,31 @@ bool CSqlite3::SaveChufangPrinter(std::vector<ChufangPrinter>& printers)
 	LOG_INFO("save params fail");
 	return false;
 }
+
+bool CSqlite3::SaveUsers(std::map<string, string> users)
+{
+	int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
+
+	std::string sql = "delete from pos_user;";
+	result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
+
+	for (std::map<std::string, std::string>::iterator it = users.begin(); it != users.end(); it++)
+	{
+		std::string name = it->first;
+		std::string password = it->second;
+
+		sql = "INSERT INTO pos_user (username, password) VALUES ('" + name + "' ,'" + password + "')";
+		result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
+	}
+
+	result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
+
+	if (result == SQLITE_OK)
+	{
+		LOG_INFO("save params success");
+		return true;
+	}
+
+	LOG_INFO("save params fail");
+	return false;
+}

+ 3 - 0
lewaimai_dispatch/tool/CSqlite3.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <sqlite3/sqlite3.h>
+
 #include "CSetting.h"
 
 class CSqlite3
@@ -16,6 +17,8 @@ public:
 
 	bool SaveChufangPrinter(std::vector<ChufangPrinter>& printers);
 
+	bool SaveUsers(std::map<string, string> users);
+
 	void Close()
 	{
 		if (m_db != NULL)

+ 339 - 2
lewaimai_dispatch/wnd/CLoginWnd.cpp

@@ -1,7 +1,286 @@
 #include "../pch/pch.h"
 #include "CLoginWnd.h"
 
-void CLoginFrameWnd::HandleLogin()
+void CLoginWnd::Init()
+{
+	std::map<string, string> users = CSetting::getUsers();
+
+	CComboUI* pCom = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));
+
+	for (std::map<string, string>::iterator it = users.begin(); it != users.end(); it++)
+	{
+		std::string username = it->first;
+		
+		CListLabelElementUI* elem = new CListLabelElementUI();
+		elem->SetText(CLewaimaiString::UTF8ToUnicode(username).c_str());
+
+		pCom->Add(elem);
+	}
+
+	CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+	CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+
+	if (CSetting::GetParam("setting_is_remember_password") == "1")
+	{
+		pRemember->Selected(true, false);
+	}
+	else
+	{
+		pRemember->Selected(false, false);
+	}
+
+	if (CSetting::GetParam("setting_is_auto_login") == "1")
+	{
+		//自动登录开启了,记住密码一定要开启
+		pAuto->Selected(true, false);
+		pRemember->Selected(true, false);
+	}
+	else
+	{
+		pAuto->Selected(false, false);
+	}
+
+	std::string last_login_username = CSetting::GetParam("last_login_username");
+	std::string password = CSetting::GetUser(last_login_username);
+
+	CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+	CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+
+	pAccountEdit->SetText(CLewaimaiString::UTF8ToUnicode(last_login_username).c_str());
+	pPasswordEdit->SetText(CLewaimaiString::UTF8ToUnicode(password).c_str());
+
+	if (CSetting::GetParam("setting_is_auto_login") == "1")
+	{
+		HandleLogin();
+	}
+}
+
+void CLoginWnd::Notify(TNotifyUI& msg)
+{
+    if(msg.sType == _T("click"))
+    {
+        if(msg.pSender->GetName() == _T("closebtn"))
+        {
+            PostQuitMessage(0);
+            return;
+        }
+        else if(msg.pSender->GetName() == _T("loginBtn"))
+        {
+            HandleLogin();
+            return;
+        }
+		else if (msg.pSender->GetName() == _T("login_auto_login"))
+		{
+			CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+			CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+
+			if (!pAuto->IsSelected())
+			{
+				pRemember->Selected(true, false);
+			}
+		}
+		else if (msg.pSender->GetName() == _T("login_remember_password"))
+		{
+			CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+			CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+
+			if (pRemember->IsSelected())
+			{
+				pAuto->Selected(false, false);
+			}
+		}
+    }
+	else if (msg.sType == _T("itemselect"))
+	{
+		CDuiString name = msg.pSender->GetName();
+
+		if (name == _T("accountcombo"))
+		{
+			CComboUI* pCom = static_cast<CComboUI*>(m_pm.FindControl(_T("accountcombo")));
+
+			std::wstring name = pCom->GetItemAt(pCom->GetCurSel())->GetText();
+			std::string password = CSetting::GetUser(CLewaimaiString::UnicodeToUTF8(name));
+			std::wstring wspassword = CLewaimaiString::UTF8ToUnicode(password);
+
+			CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+			pEdit->SetText(name.c_str());
+
+			CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+			pPassword->SetText(wspassword.c_str());
+		}
+	}
+}
+
+LRESULT CLoginWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
+    styleValue &= ~WS_CAPTION;
+    ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+
+    // 把自己的窗口句柄与窗口绘制管理器挂接在一起
+    m_pm.Init(m_hWnd);
+
+    m_pm.AddPreMessageFilter(this);
+
+    CDialogBuilder builder;
+
+    CControlUI* pRoot = builder.Create(_T("login.xml"), (UINT)0, NULL, &m_pm);
+    ASSERT(pRoot && "Failed to parse XML");
+
+    // 把这些控件绘制到本窗口上
+    m_pm.AttachDialog(pRoot);
+
+    // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
+    m_pm.AddNotifier(this);
+
+    Init();
+
+    return 0;
+}
+
+LRESULT CLoginWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    if(::IsIconic(*this))
+    {
+        bHandled = FALSE;
+    }
+    return (wParam == 0) ? TRUE : FALSE;
+}
+
+LRESULT CLoginWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    return 0;
+}
+
+LRESULT CLoginWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+	//在这里设置焦点才有用
+	CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+	if (pAccountEdit)
+	{
+		pAccountEdit->SetFocus();
+	}
+
+	return 0;
+}
+
+LRESULT CLoginWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    POINT pt;
+    pt.x = GET_X_LPARAM(lParam);
+    pt.y = GET_Y_LPARAM(lParam);
+    ::ScreenToClient(*this, &pt);
+
+    RECT rcClient;
+    ::GetClientRect(*this, &rcClient);
+
+    RECT rcCaption = m_pm.GetCaptionRect();
+    if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
+            && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
+    {
+        CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
+        if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
+        {
+            return HTCAPTION;
+        }
+    }
+
+    return HTCLIENT;
+}
+
+LRESULT CLoginWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    SIZE szRoundCorner = m_pm.GetRoundCorner();
+    if(!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
+    {
+        CDuiRect rcWnd;
+        ::GetWindowRect(*this, &rcWnd);
+        rcWnd.Offset(-rcWnd.left, -rcWnd.top);
+        rcWnd.right++;
+        rcWnd.bottom++;
+        HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
+        ::SetWindowRgn(*this, hRgn, TRUE);
+        ::DeleteObject(hRgn);
+    }
+
+    bHandled = FALSE;
+    return 0;
+}
+
+LRESULT CLoginWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    LRESULT lRes = 0;
+    BOOL bHandled = TRUE;
+    switch(uMsg)
+    {
+    case WM_CREATE:
+        lRes = OnCreate(uMsg, wParam, lParam, bHandled);
+        break;
+    case WM_NCACTIVATE:
+        lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
+        break;
+    case WM_NCCALCSIZE:
+        lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
+        break;
+    case WM_NCPAINT:
+        lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
+        break;
+    case WM_NCHITTEST:
+        lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
+        break;
+    case WM_SIZE:
+        lRes = OnSize(uMsg, wParam, lParam, bHandled);
+        break;
+    default:
+        bHandled = FALSE;
+    }
+    if(bHandled)
+    {
+        return lRes;
+    }
+    if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
+    {
+        return lRes;
+    }
+    return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
+}
+
+LRESULT CLoginWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
+{
+    if(uMsg == WM_KEYDOWN)
+    {
+        if(wParam == VK_RETURN)
+        {
+            CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
+            if(pEdit->GetText().IsEmpty())
+            {
+                pEdit->SetFocus();
+            }
+            else
+            {
+                pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
+                if(pEdit->GetText().IsEmpty())
+                {
+                    pEdit->SetFocus();
+                }
+                else
+                {
+                    this->HandleLogin();
+                }
+            }
+            return true;
+        }
+        else if(wParam == VK_ESCAPE)
+        {
+            PostQuitMessage(0);
+            return true;
+        }
+
+    }
+    return false;
+}
+
+void CLoginWnd::HandleLogin()
 {
     //判断账号密码是否正确
     std::wstring account, password;
@@ -22,6 +301,26 @@ void CLoginFrameWnd::HandleLogin()
     string s_account = CLewaimaiString::UnicodeToUTF8(account);
     string s_password = CLewaimaiString::UnicodeToUTF8(password);
 
+	CLewaimaiString::trim(s_account);
+	CLewaimaiString::trim(s_password);
+
+	CLabelUI* pLoginResultLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("loginresult")));
+	if (s_account.compare("") == 0)
+	{
+		pLoginResultLabel->SetText(std::wstring(_T("用户名不能为空")).c_str());
+		pLoginResultLabel->SetVisible(true);
+
+		return;
+	}
+
+	if (s_password.compare("") == 0)
+	{
+		pLoginResultLabel->SetText(std::wstring(_T("密码不能为空")).c_str());
+		pLoginResultLabel->SetVisible(true);
+
+		return;
+	}
+
     CZhipuziHttpClient::Init(s_account, s_password);
 
     std::string errmsg;
@@ -29,6 +328,44 @@ void CLoginFrameWnd::HandleLogin()
 
     if(res)
     {
+		CCheckBoxUI* pAuto = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_auto_login")));
+		CCheckBoxUI* pRemember = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("login_remember_password")));
+
+		if (pAuto->IsSelected())
+		{
+			CSetting::SetParam("setting_is_auto_login", "1", false);
+			CSetting::SetParam("setting_is_remember_password", "1", false);
+
+			//相当于开启自动登录,默认就是开启了记住密码了
+			CSetting::SetUser(s_account, s_password, true);
+		}
+		else
+		{
+			CSetting::SetParam("setting_is_auto_login", "0", false);
+
+			if (pRemember->IsSelected())
+			{
+				CSetting::SetParam("setting_is_remember_password", "1", false);
+			}
+			else
+			{
+				CSetting::SetParam("setting_is_remember_password", "0", false);
+			}
+
+
+			if (pRemember->IsSelected())
+			{
+				CSetting::SetUser(s_account, s_password, true);
+			}
+			else
+			{
+				CSetting::SetUser(s_account, "", true);
+			}
+		}		
+
+		//在这里设置完参数后,统一保存到数据库
+		CSetting::SetParam("last_login_username", s_account, true);
+
         CMainWnd* pFrame = new CMainWnd();
         if(pFrame == NULL)
         {
@@ -36,7 +373,7 @@ void CLoginFrameWnd::HandleLogin()
         }
 
         pFrame->SetIcon(IDI_ICON_DUILIB);
-        pFrame->Create(NULL, _T("游戏中心"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 738);
+        pFrame->Create(NULL, _T("智铺子收银软件"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 768);
         pFrame->CenterWindow();
 
         ::ShowWindow(*pFrame, SW_SHOWMAXIMIZED);

+ 12 - 181
lewaimai_dispatch/wnd/CLoginWnd.h

@@ -3,10 +3,10 @@
 #include "../pch/pch.h"
 #include "CMainWnd.h"
 
-class CLoginFrameWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
+class CLoginWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
 {
 public:
-    CLoginFrameWnd()
+    CLoginWnd()
     {
 
     }
@@ -27,194 +27,25 @@ public:
         delete this;
     };
 
-    void Init()
-    {
-        CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-        if(pAccountEdit)
-        {
-            pAccountEdit->SetText(_T(""));
-        }
-        pAccountEdit->SetFocus();
-    }
-
-    void Notify(TNotifyUI& msg)
-    {
-        if(msg.sType == _T("click"))
-        {
-            if(msg.pSender->GetName() == _T("closebtn"))
-            {
-                PostQuitMessage(0);
-                return;
-            }
-            else if(msg.pSender->GetName() == _T("loginBtn"))
-            {
-                HandleLogin();
-                return;
-            }
-        }
-    }
-
-    LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
-        styleValue &= ~WS_CAPTION;
-        ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+	void Init();
 
-        // 把自己的窗口句柄与窗口绘制管理器挂接在一起
-        m_pm.Init(m_hWnd);
+	void Notify(TNotifyUI& msg);
 
-        m_pm.AddPreMessageFilter(this);
-
-        CDialogBuilder builder;
-
-        CControlUI* pRoot = builder.Create(_T("login.xml"), (UINT)0, NULL, &m_pm);
-        ASSERT(pRoot && "Failed to parse XML");
-
-        // 把这些控件绘制到本窗口上
-        m_pm.AttachDialog(pRoot);
-
-        // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
-        m_pm.AddNotifier(this);
-
-        Init();
-
-        return 0;
-    }
+	LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        if(::IsIconic(*this))
-        {
-            bHandled = FALSE;
-        }
-        return (wParam == 0) ? TRUE : FALSE;
-    }
+	LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        return 0;
-    }
+	LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        return 0;
-    }
+	LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        POINT pt;
-        pt.x = GET_X_LPARAM(lParam);
-        pt.y = GET_Y_LPARAM(lParam);
-        ::ScreenToClient(*this, &pt);
-
-        RECT rcClient;
-        ::GetClientRect(*this, &rcClient);
-
-        RECT rcCaption = m_pm.GetCaptionRect();
-        if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
-                && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
-        {
-            CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
-            if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
-            {
-                return HTCAPTION;
-            }
-        }
-
-        return HTCLIENT;
-    }
+	LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
-    {
-        SIZE szRoundCorner = m_pm.GetRoundCorner();
-        if(!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
-        {
-            CDuiRect rcWnd;
-            ::GetWindowRect(*this, &rcWnd);
-            rcWnd.Offset(-rcWnd.left, -rcWnd.top);
-            rcWnd.right++;
-            rcWnd.bottom++;
-            HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
-            ::SetWindowRgn(*this, hRgn, TRUE);
-            ::DeleteObject(hRgn);
-        }
-
-        bHandled = FALSE;
-        return 0;
-    }
+	LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
 
-    LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
-    {
-        LRESULT lRes = 0;
-        BOOL bHandled = TRUE;
-        switch(uMsg)
-        {
-        case WM_CREATE:
-            lRes = OnCreate(uMsg, wParam, lParam, bHandled);
-            break;
-        case WM_NCACTIVATE:
-            lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
-            break;
-        case WM_NCCALCSIZE:
-            lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
-            break;
-        case WM_NCPAINT:
-            lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
-            break;
-        case WM_NCHITTEST:
-            lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
-            break;
-        case WM_SIZE:
-            lRes = OnSize(uMsg, wParam, lParam, bHandled);
-            break;
-        default:
-            bHandled = FALSE;
-        }
-        if(bHandled)
-        {
-            return lRes;
-        }
-        if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
-        {
-            return lRes;
-        }
-        return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
-    }
+	LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-    LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
-    {
-        if(uMsg == WM_KEYDOWN)
-        {
-            if(wParam == VK_RETURN)
-            {
-                CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
-                if(pEdit->GetText().IsEmpty())
-                {
-                    pEdit->SetFocus();
-                }
-                else
-                {
-                    pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
-                    if(pEdit->GetText().IsEmpty())
-                    {
-                        pEdit->SetFocus();
-                    }
-                    else
-                    {
-                        this->HandleLogin();
-                    }
-                }
-                return true;
-            }
-            else if(wParam == VK_ESCAPE)
-            {
-                PostQuitMessage(0);
-                return true;
-            }
-
-        }
-        return false;
-    }
+	LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
 
     void HandleLogin();
 

+ 13 - 13
lewaimai_dispatch/wnd/CMainWnd.cpp

@@ -80,14 +80,14 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
 {
     if(msg.pSender == m_pCloseBtn)
     {
-		if (CSetting::GetParam("setting_is_close_min") == "1")
-		{
-			AddTrayIcon();
-		}
-		else
-		{
-			PostQuitMessage(0); 
-		}
+        if(CSetting::GetParam("setting_is_close_min") == "1")
+        {
+            AddTrayIcon();
+        }
+        else
+        {
+            PostQuitMessage(0);
+        }
 
         return;
     }
@@ -899,9 +899,9 @@ LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
     case WM_SYSCOMMAND:
         lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
         break;
-	case  WM_SHOWTASK:
-		lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
-		break;
+    case  WM_SHOWTASK:
+        lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
+        break;
 
     default:
         bHandled = FALSE;
@@ -1118,8 +1118,8 @@ LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
         Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
         //显示主窗口
         ShowWindow(SW_SHOWNORMAL);
-		//窗口最大化
-		SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
+        //窗口最大化
+        SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
     }
     //如果在图标中单击右键则弹出声明式菜单
     if(lParam == WM_RBUTTONDOWN)

+ 10 - 19
lewaimai_dispatch/zhipuzi_pos_windows.cpp

@@ -13,9 +13,9 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
     log.Init();
 
     //读取sqlite里面的设置信息
-	CSqlite3 sqllite;
-	sqllite.InitConfig();
-	sqllite.Close();
+    CSqlite3 sqllite;
+    sqllite.InitConfig();
+    sqllite.Close();
 
     //由这个对象来处理消息推送的接收,以及消息的处理
     CMessagePush push;
@@ -36,25 +36,16 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
         return 0;
     }
 
-    CMainWnd* pFrame = new CMainWnd();
-    if(pFrame == NULL)
+    //先显示登录窗口
+    CLoginWnd* pLogin = new CLoginWnd();
+    if(pLogin == NULL)
     {
         return 0;
     }
-
-    pFrame->SetIcon(IDI_ICON_DUILIB);
-    pFrame->Create(NULL, _T("游戏中心"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 738);
-    pFrame->CenterWindow();
-
-    ::ShowWindow(*pFrame, SW_SHOWMAXIMIZED);
-
-    /*
-    	CLoginFrameWnd* pLoginFrame = new CLoginFrameWnd();
-    	if (pLoginFrame == NULL) { return 0; }
-    	pLoginFrame->Create(NULL, _T(""), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
-    	pLoginFrame->SetIcon(IDI_ICON_DUILIB);
-    	pLoginFrame->CenterWindow();
-    	pLoginFrame->ShowModal();*/
+    pLogin->Create(NULL, _T("智铺子收银软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
+    pLogin->SetIcon(IDI_ICON_DUILIB);
+    pLogin->CenterWindow();
+    pLogin->ShowModal();
 
     CPaintManagerUI::MessageLoop();