BS_按钮属性与CButton类功能简介
CButton类功能简介
class CButton : public CWnd
{
public:
CButton();
virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID);
HICON SetIcon(HICON hIcon); //需要配合的尺寸
HICON GetIcon() const;
HBITMAP SetBitmap(HBITMAP hBitmap); 位图句柄
HBITMAP GetBitmap() const;
HCURSOR SetCursor(HCURSOR hCursor); 无效成员
HCURSOR GetCursor();
// Attributes
UINT GetState() const;
void SetState(BOOL bHighlight);
int GetCheck() const; //对于单选和复选控件是有效的
void SetCheck(int nCheck);
UINT GetButtonStyle() const;
void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE); 无效函数
// Overridables (for owner draw only)
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); 自绘
// Implementation
public:
virtual ~CButton();
protected:
virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
};
Button Control Styles —BS_按钮属性
CButton类简介:
a)CButton在VC6.0等早期版本,必须设置BS_BITMAP或BS_ICON才能设置图标(文字加图)。
b)近期VS版本即使不设置这两种属性,也直接可以设置文字加图的模式;
c)近期VS版本如果设置以上两种属性,则不显示文字只显示图;
ComboBox 有3种形式,原始组合,下拉代表编辑,下拉不带编辑。
Button有好几种:按钮,(自动)打勾,(自动)单选,分组框
#define BS_PUSHBUTTON 0x00000000L 0代表没有属性(默认就是按钮)
#define BS_DEFPUSHBUTTON 0x00000001L 1代表默认
#define BS_CHECKBOX 0x00000002L 点击之后需要代码来SetCheck才打勾
#define BS_AUTOCHECKBOX 0x00000003L 点击之后直接打勾和去掉打勾(无需代码)
#define BS_RADIOBUTTON 0x00000004L 单选按钮(必须有组)
#define BS_AUTORADIOBUTTON 0x00000009L 自动单选(必须分组)
#define BS_3STATE 0x00000005L
#define BS_AUTO3STATE 0x00000006L
#define BS_GROUPBOX 0x00000007L 分组控件
#define BS_USERBUTTON 0x00000008L
#define BS_PUSHBOX 0x0000000AL
#define BS_OWNERDRAW 0x0000000BL 自绘(做彩色贴图的按钮)
#define BS_TYPEMASK 0x0000000FL
#define BS_LEFTTEXT 0x00000020L
#if(WINVER >= 0x0400)
#define BS_TEXT 0x00000000L 0代表默认是文字
#define BS_ICON 0x00000040L 图标(.ico)
#define BS_BITMAP 0x00000080L 位图(.bmp)
#define BS_LEFT 0x00000100L
#define BS_RIGHT 0x00000200L
#define BS_CENTER 0x00000300L
#define BS_TOP 0x00000400L
#define BS_BOTTOM 0x00000800L
#define BS_VCENTER 0x00000C00L
#define BS_PUSHLIKE 0x00001000L
#define BS_MULTILINE 0x00002000L
#define BS_NOTIFY 0x00004000L
#define BS_FLAT 0x00008000L
#define BS_RIGHTBUTTON BS_LEFTTEXT
#endif /* WINVER >= 0x0400 */
静态文本的穿透属性与显示密码开发
但凡你想接收全面的基础消息(控件内的基础消息),你就得去做一个派生类并且用子类化实现对派生类的消息转移。
1、派生类 CEeyCtrl.h
#pragma once
class CLoginDlg; //提前声明,假包含
class CEyeCtrl : public CWnd
{
DECLARE_DYNAMIC(CEyeCtrl)
CLoginDlg* m_pDlg {}; //引用父类窗口
public:
CEyeCtrl();
virtual ~CEyeCtrl();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};
2.派生类 CEeyCtrl.cpp
#include "pch.h"
#include "CLientXq.h"
#include "CEyeCtrl.h"
#include "CLoginDlg.h"
// CEyeCtrl 消息处理程序
void CEyeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pDlg->OnClickDown();
CWnd::OnLButtonDown(nFlags, point);
}
void CEyeCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
m_pDlg->OnClickUp(); // 别人点击了你, 你告诉你的父亲
CWnd::OnLButtonUp(nFlags, point);
}
3.父窗口 CLoginDlg.h
#pragma once
#include "afxdialogex.h"
#include"CEyeCtrl.h"
class CLoginDlg : public CDialogEx
{
DECLARE_DYNAMIC(CLoginDlg)
CEyeCtrl m_eye;
public:
CLoginDlg(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CLoginDlg();
public:
afx_msg void OnBnClickedOk();
virtual BOOL OnInitDialog();
void OnClickDown();
void OnClickUp(); //用来代替穿透的消息
//afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
};
4.父窗口 CLoginDlg.cpp
BOOL CLoginDlg::OnInitDialog(){
m_eye.m_pDlg = this;
CDialogEx::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
}
void CLoginDlg::OnClickDown() { //父窗口找底下的去干活
auto pEdit = reinterpret_cast<CEdit*>(GetDlgItem(IDC_PASS));
pEdit->SetPasswordChar(0);
pEdit->RedrawWindow();
}
void CLoginDlg::OnClickUp(){
auto pEdit = reinterpret_cast<CEdit*>(GetDlgItem(IDC_PASS));
pEdit->SetPasswordChar(_T('●'));
pEdit->RedrawWindow();
}
CS架构客户端的账号管理功能添加和密码修改(员工)功能开发
CS架构客户端的账号管理功能添加功能
检查用户和刷新功能函数
BOOL CAdminDlg::CheckUser(CString sName,SAdmin& a)
{
int nCmd = AD_CHECK;
_bstr_t bstr = sName;
LPCSTR p = bstr;
m_sock.Send(&nCmd, sizeof(nCmd));
m_sock.Send(p, (int)sizeof(p));
int nCount = 0;
if (m_sock.Receive(&nCount, sizeof(nCount)) != sizeof(nCount))
{
AfxMessageBox(_T("网络中断"));
return FALSE;
}
bool b = nCount > 0;
if(b)
{
if (m_sock.Receive(&a, sizeof(a)) != sizeof(a))
{
AfxMessageBox(_T("网络中断"));
return FALSE;
}
}
return b;
}
void CAdminDlg::Refresh()
{
int nCmd = AD_PRINT;
int nCount = 0;
m_sock.Send(&nCmd, sizeof(nCmd));
if (m_sock.Receive(&nCount, sizeof(nCount))!=sizeof(nCount))
{
AfxMessageBox(_T("网络中断"));
return;
}
SAdmin a;
m_list.DeleteAllItems();
int i = 0;
while (nCount-->0)
{
if (m_sock.Receive(&a, sizeof(a)) != sizeof(a))
{
AfxMessageBox(_T("网络中断"));
break;
}
m_list.InsertItem(i, _bstr_t(a.sName));
m_list.SetItemText(i, 1, _bstr_t(a.sPass));
m_list.SetItemText(i, 2, a.nPrior ? _T("普通") : _T("高级"));
++i;
}
}
添加功能函数体
void CAdminDlg::OnBnClickedAdd(){
SAdmin a;
int nCmd = AD_INPUT;
CString str;
GetDlgItemText(IDC_NAEM, str);
if (CheckUser(str, a))
{
CString str = CString(a.sName) + _T(",") + a.sPass + _T(",") + (a.nPrior ? _T("普通") : _T("高级"));
AfxMessageBox(_T("账号已经存在"));
return;
}
strcpy_s(a.sName, sizeof(a.sName), (_bstr_t)str);
GetDlgItemText(IDC_PASS, str);
strcpy_s(a.sPass, sizeof(a.sPass), (_bstr_t)str);
a.nPrior = m_combox.GetCurSel();
m_sock.Send(&nCmd, sizeof(nCmd));
m_sock.Send(&a, sizeof(a));
Refresh();
}
对应添加功能的服务端代码文章来源:https://www.toymoban.com/news/detail-570969.html
bool CAdmin::Input(CSockLx* pSocka){
SAdmin a;
if (pSocka->Receive(&a, sizeof(a)) != sizeof(a))
return false;
char sSQL[256];
_snprintf(sSQL, sizeof(sSQL), "INSERT INTO t_admin VALUES('%s','%s','%d')", a.sName, a.sPass, a.nPrior);
int n = mysql_query(&m_sql, sSQL);
if (n) {
CManager::PrintError(sSQL);//WriteLog
return false;
}
return true;
}
CS架构客户端的账号管理功能中密码修改(员工)功能开发
BOOL CPassDlg::ChangePass(CString sNew)
{
SAdmin a;
strcpy_s(a.sName, sizeof(a.sName), _bstr_t(theApp.m_sName));
strcpy_s(a.sPass, sizeof(a.sPass), _bstr_t(sNew));
int nCmd = AD_CHPASS;
m_sock.Send(&nCmd, sizeof(nCmd));
m_sock.Send(&a, sizeof(a));
int nRes = 0;
if (m_sock.Receive(&nRes, sizeof(nRes)) != sizeof(nRes))
{
AfxMessageBox(_T("网络中断!"));
return FALSE;
}
if (nRes > 0)
{
AfxMessageBox(CString(a.sName) + _T(" 密码修改成功!"));
theApp.m_sPass = sNew;
}
else
AfxMessageBox(CString(a.sName) + _T(" 密码修改失败!"));
return TRUE;
}
void CPassDlg::OnBnClickedOk()
{
CString sOld, sNew, sConf;
GetDlgItemText(IDC_OLDPASS, sOld);
if (sOld.IsEmpty())
{
AfxMessageBox(_T("旧密码不能为空!"), MB_ICONERROR);
SetFocus();
return;
}
if (sOld != theApp.m_sPass)
{
AfxMessageBox(_T("旧密码错误!"), MB_ICONERROR);
SetFocus();
return;
}
GetDlgItemText(IDC_NEWPASS, sNew);
if (sNew.IsEmpty())
{
AfxMessageBox(_T("新密码不能为空!"), MB_ICONERROR);
GetDlgItem(IDC_NEWPASS)->SetFocus();
return;
}
GetDlgItemText(IDC_CONFPASS, sConf);
if (sConf != sNew)
{
AfxMessageBox(_T("新密码和确认不一致!"), MB_ICONERROR);
GetDlgItem(IDC_CONFPASS)->SetFocus();
return;
}
if (ChangePass(sNew))
{
EndDialog(IDOK);
MessageBox(_T("密码修改成功!"), _T("提示"), MB_ICONINFORMATION);
}
else
MessageBox(_T("密码修改失败!"), _T("提示"), MB_ICONINFORMATION);
//CDialogEx::OnOK();
}
密码修改服务端代码文章来源地址https://www.toymoban.com/news/detail-570969.html
bool CAdmin::ChangePass(CSockLx* pSocka){
SAdmin a;
if(pSocka ->Receive(&a,sizeof(a))<sizeof(a))
return false;
string sSQL = "UPDATE t_admin SET f_pass = '" + string(a.sPass) +
"' WHERE f_name='" + a.sName + "'";
int n = mysql_query(&m_sql, sSQL.c_str());
if (n) {
CManager::PrintError(sSQL.c_str());//WriteLog
return false;
}
n = (int)mysql_affected_rows(&m_sql);
pSocka->Send(&n, sizeof(n));
return true;
}
到了这里,关于MFC第十四天 BS_按钮属性与CButton类功能简介 、静态文本的穿透属性与显示密码开发、CS架构客户端的账号管理功能添加功能开发的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!