📄 practicaldlg.cpp
字号:
// PracticalDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Practical.h"
#include "PracticalDlg.h"
#include "CalculatorDlg.h"
#include "ScripDlg.h"
#include "EmployesDlg.h"
#include "ServerDlg.h"
#include "Overtime.h"
#include "ProjectDlg.h"
#include "BallotDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPracticalDlg dialog
CPracticalDlg::CPracticalDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPracticalDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPracticalDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPracticalDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPracticalDlg)
DDX_Control(pDX, IDC_SERVER, m_Server);
DDX_Control(pDX, IDC_PROJECT, m_Project);
DDX_Control(pDX, IDC_OVERTIME, m_Overtime);
DDX_Control(pDX, IDC_EXIT, m_Exit);
DDX_Control(pDX, IDC_EMPLOYES, m_Employes);
DDX_Control(pDX, IDC_BALLOT, m_Ballot);
DDX_Control(pDX, IDC_SLIDER1, m_Slider);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPracticalDlg, CDialog)
//{{AFX_MSG_MAP(CPracticalDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
ON_BN_CLICKED(IDC_EMPLOYES, OnEmployes)
ON_BN_CLICKED(IDC_SERVER, OnServer)
ON_BN_CLICKED(IDC_OVERTIME, OnOvertime)
ON_BN_CLICKED(IDC_PROJECT, OnProject)
ON_BN_CLICKED(IDC_BALLOT, OnBallot)
ON_BN_CLICKED(IDC_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPracticalDlg message handlers
BOOL CPracticalDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CString num;
GetPrivateProfileString("透明度", "数值", "", num.GetBuffer(0),8,"./Client.ini");
//设置窗口扩展风格
SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,
GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE) | 0x80000);
typedef BOOL (WINAPI *FSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
FSetLayeredWindowAttributes SetLayeredWindowAttributes;
HINSTANCE hInst = LoadLibrary("User32.DLL");
SetLayeredWindowAttributes = (FSetLayeredWindowAttributes)
GetProcAddress(hInst,"SetLayeredWindowAttributes");
if(SetLayeredWindowAttributes)
SetLayeredWindowAttributes(GetSafeHwnd(),RGB(0,0,0),90+atoi(num),2);
FreeLibrary(hInst);
m_Slider.SetRange(10,160,TRUE);
m_Slider.SetPos(atoi(num));
//设置窗口显示位置
int x,y;
x = GetSystemMetrics(SM_CXSCREEN);
y = GetSystemMetrics(SM_CYSCREEN);
CRect rect;
GetWindowRect(&rect);
::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_TOPMOST,x-rect.Width(),
0,rect.Width(),rect.Height(),SWP_SHOWWINDOW);
CCalculatorDlg* dlg1 = new CCalculatorDlg;
dlg1->Create(IDD_CALCULATOR_DIALOG,this);
dlg1->ShowWindow(SW_SHOW);
CScripDlg* dlg2 = new CScripDlg;
dlg2->Create(IDD_SCRIP_DIALOG,this);
dlg2->ShowWindow(SW_SHOW);
char server[32];
GetPrivateProfileString("服务器", "机器名", "", server,32,"./Client.ini");
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name=Buffer;
if(Name == server)
{
m_Project.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_PROJECT1))); //设置位图
m_Employes.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_EMPLOYES1))); //设置位图
}
else
{
m_Project.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_PROJECT2))); //设置位图
m_Employes.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_EMPLOYES2))); //设置位图
}
char IsSet[2];
GetPrivateProfileString("是否设置","已设置","default",IsSet,2,"./Client.ini");
CString str = IsSet;
if(str=="1")
{
m_Overtime.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_OVERTIME1))); //设置位图
m_Ballot.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BALLOT1))); //设置位图
}
else
{
m_Project.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_PROJECT2))); //设置位图
m_Overtime.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_OVERTIME2))); //设置位图
m_Employes.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_EMPLOYES2))); //设置位图
m_Ballot.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BALLOT2))); //设置位图
}
m_Server.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_SERVER))); //设置位图
m_Exit.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_EXIT))); //设置位图
SetTimer(1,100,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CPracticalDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CPracticalDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPracticalDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPracticalDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rc;
CRect rect;
GetWindowRect(&rect);
rc.CopyRect(&rect);
CPoint pOint;
GetCursorPos(&pOint);
if(rect.top < 0 && PtInRect(rect,pOint))
{
rect.top = 0;
MoveWindow(rect.left,rect.top,rc.Width(),rc.Height());
}
else if(rect.top > -3 && rect.top < 3 && !PtInRect(rect,pOint))
{
rect.top = 3-rect.Height();
MoveWindow(rect.left,rect.top,rc.Width(),rc.Height());
}
CDialog::OnTimer(nIDEvent);
}
void CPracticalDlg::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//设置窗口扩展风格
SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,
GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE) | 0x80000);
typedef BOOL (WINAPI *FSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
FSetLayeredWindowAttributes SetLayeredWindowAttributes ;
HINSTANCE hInst = LoadLibrary("User32.DLL");
SetLayeredWindowAttributes = (FSetLayeredWindowAttributes)
GetProcAddress(hInst,"SetLayeredWindowAttributes");
if(SetLayeredWindowAttributes)
SetLayeredWindowAttributes(GetSafeHwnd(),RGB(0,0,0),90+m_Slider.GetPos(),2);
FreeLibrary(hInst);
CString num;
num.Format("%d",m_Slider.GetPos());
WritePrivateProfileString("透明度","数值",num,"./Client.ini");
*pResult = 0;
}
void CPracticalDlg::OnEmployes()
{
// TODO: Add your control notification handler code here
char IsSet[2];
GetPrivateProfileString("是否设置","已设置","default",IsSet,2,"./Client.ini");
CString str = IsSet;
if(str=="1")
{
char server[32];
GetPrivateProfileString("服务器", "机器名", "", server,32,"./Client.ini");
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name=Buffer;
if(Name == server)
{
CEmployesDlg dlg;
dlg.DoModal();
}
}
}
void CPracticalDlg::OnServer()
{
// TODO: Add your control notification handler code here
CServerDlg dlg;
dlg.DoModal();
}
void CPracticalDlg::OnOvertime()
{
// TODO: Add your control notification handler code here
char IsSet[2];
GetPrivateProfileString("是否设置","已设置","default",IsSet,2,"./Client.ini");
CString str = IsSet;
if(str=="1")
{
COvertime dlg;
dlg.DoModal();
}
}
void CPracticalDlg::OnProject()
{
// TODO: Add your control notification handler code here
char IsSet[2];
GetPrivateProfileString("是否设置","已设置","default",IsSet,2,"./Client.ini");
CString str = IsSet;
if(str=="1")
{
char server[32];
GetPrivateProfileString("服务器", "机器名", "", server,32,"./Client.ini");
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
char Buffer[MAX_COMPUTERNAME_LENGTH + 1];
GetComputerName(Buffer,&nSize);
CString Name=Buffer;
if(Name == server)
{
CProjectDlg dlg;
dlg.DoModal();
}
}
}
void CPracticalDlg::OnBallot()
{
// TODO: Add your control notification handler code here
char IsSet[2];
GetPrivateProfileString("是否设置","已设置","default",IsSet,2,"./Client.ini");
CString str = IsSet;
if(str=="1")
{
CBallotDlg dlg;
dlg.DoModal();
}
}
void CPracticalDlg::OnExit()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -