CString strAppName = _T("AppName"); // 应用程序名
CString strAppPath = _T("c://AppName.exe"); // 应用程序存储路径
CString strRegPath = _T("Software//Microsoft//Windows//CurrentVersion//Run");
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegPath, 0, KEY_WRITE, &hKey);
RegDeleteValue(hKey, strAppName);
RegSetValueEx(hKey, strAppName, 0, REG_SZ, (unsigned char*)strAppPath.GetBuffer(0), strAppPath.GetLength());
CString strAppPath = _T("c://AppName.exe"); // 应用程序存储路径
CString strRegPath = _T("Software//Microsoft//Windows//CurrentVersion//Run");
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, strRegPath, 0, KEY_WRITE, &hKey);
RegDeleteValue(hKey, strAppName);
RegSetValueEx(hKey, strAppName, 0, REG_SZ, (unsigned char*)strAppPath.GetBuffer(0), strAppPath.GetLength());
以上程序适用于Windows NT/2000/XP。
如果想要在启动时同时隐藏窗体,可以捕获WM_WINDOWPOSCHANGING消息:
void CMainFrame::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
if (m_bAutoHide == FALSE)
{
CDialog::OnWindowPosChanging(lpwndpos); // 显示
}
else
{
if (lpwndpos->flags & SWP_SHOWWINDOW) // 隐藏
{
lpwndpos->flags &= ~SWP_SHOWWINDOW;
PostMessage(WM_WINDOWPOSCHANGING, 0, (LPARAM)lpwndpos);
ShowWindow(SW_HIDE);
m_bAutoHide = FALSE;
}
else
{
CDialog::OnWindowPosChanging(lpwndpos); // 显示
}
}
}
{
if (m_bAutoHide == FALSE)
{
CDialog::OnWindowPosChanging(lpwndpos); // 显示
}
else
{
if (lpwndpos->flags & SWP_SHOWWINDOW) // 隐藏
{
lpwndpos->flags &= ~SWP_SHOWWINDOW;
PostMessage(WM_WINDOWPOSCHANGING, 0, (LPARAM)lpwndpos);
ShowWindow(SW_HIDE);
m_bAutoHide = FALSE;
}
else
{
CDialog::OnWindowPosChanging(lpwndpos); // 显示
}
}
}
其中的m_bAutoHide是BOOL型成员变量,用于记录是否在启动时隐藏窗体。
本文介绍了一个适用于Windows NT/2000/XP的程序,它能在启动时自动运行,并在启动过程中自动隐藏窗体。通过捕获WM_WINDOWPOSCHANGING消息,利用BOOL型变量m_bAutoHide来记录启动时是否隐藏窗体。
159

被折叠的 条评论
为什么被折叠?



