窗体显示问题

翻译|其它|编辑:郝浩|2004-08-04 08:59:00.000|阅读 2172 次

概述:

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>


// ADClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ADClient.h"
#include "ADClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

//注册表操作
HKEY hKey;
char content[256]; //所查询注册表键值的内容
DWORD dwType=REG_SZ; //定义读取数据类型
DWORD dwLength=256;
struct HKEY__*RootKey; //注册表主键名称
TCHAR *SubKey; //欲打开注册表项的地址
TCHAR *KeyName; //欲设置项的名字
TCHAR *ValueName; //欲设置值的名称
LPBYTE SetContent_S; //字符串类型
int SetContent_D[256]; //DWORD类型
BYTE SetContent_B[256]; //二进制类型

int SetValue_D (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,int ReSetContent_D[256]);

int strURLLen = 0;
char URL[128];

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()

/////////////////////////////////////////////////////////////////////////////
// CADClientDlg dialog

CADClientDlg::CADClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CADClientDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CADClientDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_hCursor = AfxGetApp()->LoadCursor(IDC_HPOINT);

flag = 0;
yy1 = 0;

nTimeNum = 0;
nTimeNumTotal = 0;
}

void CADClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CADClientDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CADClientDlg, CDialog)
//{{AFX_MSG_MAP(CADClientDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CADClientDlg message handlers

BOOL CADClientDlg::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
// ::SetWindowPos( this->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE ); // 让对话框一直可见

GetDesktopWindow()->GetWindowRect(DesktopRect); //取得屏幕窗口大小
MoveWindow(DesktopRect.Width()-350, DesktopRect.Height(), 0,0);

ReadIniFile("C:\\sxncc\\Reg.ini"); // 读取 Ini 文件

nTimeNumTotal = structFtpTxt.nTime2;

for(int i=0; i<structFtpTxt.strNetAdd1.GetLength(); i++)
{
URL[i] = structFtpTxt.strNetAdd1.GetAt(i);
}
EditReg();
SetWindowText(structFtpTxt.strNetAdd1); // 设置标题

::SetTimer(this->m_hWnd, 0, 30, NULL);

return TRUE; // return TRUE unless you set the focus to a control
}

void CADClientDlg::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 CADClientDlg::OnPaint() 
{
/*
CDC* pDC = GetDC();
CPicture* ppic = GetPicture();
if (*ppic) 
{
CRect rc = CRect(0,0,350,350);
ppic->Render(pDC, rc);

*/ 
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 CADClientDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CADClientDlg::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default

// 打开
if(nIDEvent == 0)
{
MoveWindow(DesktopRect.Width()-350,DesktopRect.Height()-yy1,350,350);
yy1 = yy1+10;
if(yy1 == 350)
{
SetTimer(2, 1000, NULL);
::KillTimer(this->m_hWnd, 0);

}

// 关闭
if(nIDEvent == 1)
{
MoveWindow(DesktopRect.Width()-350,DesktopRect.Height()-yy1,350,350);
yy1 = yy1-10;
if(yy1 == 0)
{
::KillTimer(this->m_hWnd, 0);
DestroyWindow();

}
// 计时
if(nIDEvent == 2)
{
nTimeNum++;
if(nTimeNum == 5)
{
SetTimer(1, 30, NULL);
::KillTimer(this->m_hWnd, 0);
}
}

CDialog::OnTimer(nIDEvent);
}

void CADClientDlg::EditReg()
{
RootKey=HKEY_CURRENT_USER; //注册表主键名称
SubKey="Software\\Microsoft\\Internet Explorer\\Main"; //欲打开注册表值的地址
ValueName="Start Page"; //欲设置值的名称
SetContent_D[0]=4294967295; //值的内容

if((SetValue_D(RootKey,SubKey,ValueName,SetContent_D))!=0)
AfxMessageBox("操作失败!");
}

//////////////////////////////////////////////////////////////////////////

//设置DWORD值函数
SetValue_D (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,int ReSetContent_D[256])
{
int i=0; //操作结果:0==succeed

if(RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_WRITE,&hKey)==ERROR_SUCCESS)
{
if(RegSetValueEx(hKey,ReValueName,NULL,REG_SZ,(const unsigned char *)URL,15)!=ERROR_SUCCESS)
{
AfxMessageBox("错误:无法设置有关的注册表信息");
i=1;
}
RegCloseKey(hKey);
}
else
{
AfxMessageBox("错误:无法查询有关的注册表信息");
i=1;
}
return i;
}

BOOL CADClientDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
// TODO: Add your message handler code here and/or call default
/* if (m_hCursor)
{
::SetCursor(m_hCursor);
return TRUE;
}
*/ return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

void CADClientDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default

// ShellExecute(NULL, _T("open"), structFtpTxt.strNetAdd2, NULL,NULL, 5);

// exit(0);

CDialog::OnLButtonDown(nFlags, point);
}

void CADClientDlg::ReadIniFile(CString strPathName)
{
CFile m_FileIni;
m_FileIni.Open("C:\\sxncc\\Reg.ini", CFile::modeRead);

int i, n;
BYTE *p;
n = m_FileIni.GetLength();
if(n == 0)
{
return;
}

p = new BYTE[n + 15];
if(!p)
{
m_FileIni.Close();
return;
}

m_FileIni.Read(p, n);
m_FileIni.Close();

int j;
char s[50];
i = 0;

while(i < n - 3)
{
// TIME1: 
if((p[i] == 'T')&&(p[i+1] == 'I')&&(p[i+2] == 'M')&&(p[i+3] == 'E')&&(p[i+4] == '1')&&(p[i+5] == ':'))
{
i += 6;
while(p[i] <= 0x20)
{
if(i == n)
break;
i++;
}
j = 0;
while(p[i] > 0x20)
{
s[j] = p[i];
if((i == n) || (j > 30))
break;
i++;
j++;
}
s[j] = 0x00;
structFtpTxt.nTime1 = atoi(s);
}
// TIME2: 
if((p[i] == 'T')&&(p[i+1] == 'I')&&(p[i+2] == 'M')&&(p[i+3] == 'E')&&(p[i+4] == '2')&&(p[i+5] == ':'))
{
i += 6;
while(p[i] <= 0x20)
{
if(i == n)
break;
i++;
}
j = 0;
while(p[i] > 0x20)
{
s[j] = p[i];
if((i == n) || (j > 30))
break;
i++;
j++;
}
s[j] = 0x00;
structFtpTxt.nTime2 = atoi(s);
}

// ADD1: 
else if((p[i] == 'A')&&(p[i+1] == 'D')&&(p[i+2] == 'D')&&(p[i+3] == '1')&&(p[i+4] == ':'))
{
i += 5;
while(p[i] <= 0x20)
{
if(i == n)
break;
i++;
}
j = 0;
while(p[i] > 0x20)
{
s[j] = p[i];
if((i == n) || (j > 30))
break;
i++;
j++;
}
s[j] = 0x00;
structFtpTxt.strNetAdd1 = s;
}
// NAME:: 
else if((p[i] == 'N')&&(p[i+1] == 'A')&&(p[i+2] == 'M')&&(p[i+3] == 'E')&&(p[i+4] == ':'))
{
i += 5;
while(p[i] <= 0x20)
{
if(i == n)
break;
i++;
}
j = 0;
while(p[i] > 0x20)
{
s[j] = p[i];
if((i == n) || (j > 30))
break;
i++;
j++;
}
s[j] = 0x00;
structFtpTxt.strName = s;
}

i++;
}
delete[] p;
}

void CADClientDlg::OnClose() 
{
// TODO: Add your message handler code here and/or call default
CDialog::OnClose();
}

这是另外一个文件

// ADClient.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "ADClient.h"
#include "ADClientDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CADClientApp

BEGIN_MESSAGE_MAP(CADClientApp, CWinApp)
//{{AFX_MSG_MAP(CADClientApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CADClientApp construction

CADClientApp::CADClientApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CADClientApp object

CADClientApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CADClientApp initialization

BOOL CADClientApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

CADClientDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP