找高手指点如何用c++编写一个挂QQ的小软件,(自娱自乐)
发布网友
发布时间:2024-04-05 19:51
我来回答
共1个回答
热心网友
时间:2024-07-24 16:24
//设置或取消开机启动
void OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
HKEY h_key = HKEY_LOCAL_MACHINE;
HKEY h_result;
CString m_SubKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
RegOpenKey(h_key,m_SubKey,&h_result);
CString m_Appname(_T('0'),MAX_PATH);
if (StartFlag) //设置自动运行
{
GetModuleFileName(NULL,m_Appname.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
if (RegSetValueEx(h_result,_T("DataProcess"),0,REG_SZ,(unsigned char*)m_Appname.GetBuffer(m_Appname.GetLength()),m_Appname.GetLength())==ERROR_SUCCESS)
{
MessageBox(_T("成功设置开机自启动!"),_T("提示"));
StartFlag=false;
SetDlgItemText(IDC_BUTTON4,_T("取消开机自启动"));
}
else
{
MessageBox(_T("设置开机自启动失败!"),_T("提示"));
}
}
else //取消自动运行
{
if (RegDeleteValue(h_result,_T("DataProcess"))==ERROR_SUCCESS)
{
MessageBox(_T("成功取消开机自启动!"),_T("提示"));
StartFlag=true;
SetDlgItemText(IDC_BUTTON4,_T("设置开机自启动"));
}
else
{
MessageBox(_T("取消开机自启动失败!"),_T("提示"));
}
}
RegCloseKey(h_result);
}
隐藏到托盘的实现
void toTray ()
{
NOTIFYICONDATA nid;
nid.cbSize =(DWORD)sizeof(NOTIFYICONDATA);
nid.hWnd =this->m_hWnd ;
nid.uID =IDR_MAINFRAME;
nid.uFlags =NIF_ICON|NIF_MESSAGE|NIF_TIP;
nid.uCallbackMessage =WM_SHOWTASK;
nid.hIcon =LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
lstrcpy(nid.szTip ,_T("DataProcess Project"));
Shell_NotifyIcon(NIM_ADD,&nid); //在托盘区添加图标
ShowWindow(SW_HIDE);//隐藏主窗口
UpdateWindow();
}
//隐藏到托盘的实现
//对托盘图标的操作
LRESULT onShowTask (WPARAM wParam,LPARAM lParam)
{
if(wParam!=IDR_MAINFRAME)
{
return 1;
}
switch(lParam)
{
case WM_RBUTTONUP://右击弹出快捷菜单“关闭”
{
LPPOINT lpoint=new tagPOINT;
::GetCursorPos (lpoint);
CMenu menu;
menu.CreatePopupMenu ();//声明一个弹出式菜单
menu.AppendMenuW (MF_STRING,WM_DESTROY,_T("Close"));//增加菜单项“Close“,点击发送WM_DESTROY给主窗口(已隐藏),结束程序
menu.TrackPopupMenu (TPM_LEFTALIGN,lpoint->x ,lpoint->y ,this);
//资源回收
HMENU hmenu=menu.Detach ();
menu.DestroyMenu ();
delete lpoint;
break;
}
case WM_LBUTTONDBLCLK: //双击左键显示主窗口
{
this->ShowWindow (SW_SHOW);
break;
}
}
return 0;
}
其他的我就不知道了