VC雕虫小技集(三)
1,固定窗口大小,最大值为(600,400),最小值也为(600,400).
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
lpMMI->ptMaxTrackSize.x = 600;
lpMMI->ptMaxTrackSize.y = 400;
lpMMI->ptMinTrackSize.x = 600;
lpMMI->ptMinTrackSize.y = 400;
CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
2,关闭对话框和窗口:
其实,一般窗口的销毁可以用DestoryWindow(),对话框的销毁可以用EndDialiog().
EndDialog(IDOK);
DoModal()的返回值为IDOK,但不会执行用户定义的OnOK.
只要发送WM_CLOSE消息,就会有响应的函数处理的。
SendMessage(WM_CLOSE);
PostMessage(WM_CLOSE);
void CTestDialog::OnButton1()
{
GetParent()->DestroyWindow();
}
窗口和对话框一起关
PostMessage(WM_QUIT);
SendMessage(WM_QUIT);//不行
无模式对话框用DestroyWindow();
用EndDialog
你再打开原对话框就有问题
3,全局变量的使用:
C***App中定义一个CString
使用时
void CDlgDlg::OnButton2()
{
((CDlgApp*)AfxGetApp())->str = "test";
}
不要忘记了包含文件
4,如何让dos程序开机自动运行并且不显示
自动运行好解决,写注册表run值,
vc+windows2000
把main改为winmain
5,清除自动密码历史记录
浏览器中:
工具->Internet选项->内容->点"自动完成(U)"按钮->清除密码
http://tzsvc.xiloo.com/skill/sys/clear.htm
SHDeleteKey(HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Internet Explorer\\IntelliForms"));
6,执行一个可执行程序
方法一:
ShellExecute(this->GetSafeHwnd(),"Open","f:\\he.txt",NULL,NULL,SW_SHOWNORMAL );
方法二:
PROCESS_INFORMATION pi;
STARTUPINFO si;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
BOOL bres = CreateProcess(NULL,"test a.txt b.txt",NULL,NULL,false,
NORMAL_PRIORITY_CLASS,
NULL,NULL,&si,&pi);
if(bres==false)
{
AfxMessageBox("CreateProcess failed");
}
else
{
CloseHandle(pi.hThread);
DWORD dwret=WaitForSingleObject(pi.hProcess, 1000*30);
switch(dwret)
{
case WAIT_OBJECT_0:
DWORD dwexitcode;
bres = GetExitCodeProcess(pi.hProcess,&dwexitcode);
TCHAR exitmsgbuf[1024];
if(bres)
{
wsprintf(exitmsgbuf,"exit code:%d",dwexitcode);
}
else
wsprintf(exitmsgbuf,"exit code failed to return");
AfxMessageBox(exitmsgbuf);
break;
default:
AfxMessageBox("exit for other reason");,