一个屏保的程序,请帮帮我!
ghwhz 2003-08-28 02:42:49 我是参考了在网上搜索的一个帖子,但是当执行到GetClientRect(CPWindow,lookrect)这条语句的时候会出现错误,请问为什么,错在哪里?
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR p, int)//“p"是指向命令行参数的指针
{
String StartType;
AnsiString Command=p,temp;
HWND CPWindow =NULL;
if(Command=="")
StartType = "/c";
else
StartType=Command.SubString(1,2);//获取命令行的前两个参数
try
{
Application->Initialize();
if(StartType=="/s")//启动屏保
Application->CreateForm(__classid(TMainForm), &MainForm);
else if(StartType=="/c")//启动设置窗口
Application->CreateForm(__classid(TConfigForm), &ConfigForm);
else if(StartType=="/p")//预览
{
Application->CreateForm(__classid(TPreviewForm), &PreviewForm);
temp=Command.SubString(3,Command.Length()-2);//获取命令行中的屏保预览窗口句柄的字符串形式
CPWindow =(long *)temp.ToInt();//将预览窗口句柄的字符串形式强制转换为长整形指针
RECT *lookrect;//建立一个RECT结构指针
long style=GetWindowLong(Application->MainForm->Handle,GWL_STYLE);//获取MainForm窗口的风格
style=style|WS_CHILD;
SetWindowLong(Application->MainForm->Handle,GWL_STYLE,style);//设置窗口为子窗口
SetParent(Application->MainForm->Handle,CPWindow);//设置屏保预览窗口为FrmControl的父窗口
GetClientRect(CPWindow,lookrect);//获取屏保预览窗口的客户区
SetWindowPos(Application->MainForm->Handle,HWND_TOP,0,0,lookrect->right,lookrect->bottom ,SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);//将FrmControl的窗口覆盖屏保预览窗口的客户区,并显示它
}
else if(StartType=="/a")//启动密码设置窗口
{
temp=Command.SubString(3,Command.Length()-2);
CPWindow =(long *)temp.ToInt();//以下是动态调用mpr.dll里的PwdChangePasswordA函数的过程
typedef UINT(CALLBACK *FUN)(LPSTR,HWND,UINT,UINT);
HINSTANCE hDll=LoadLibrary("mpr.DLL");
FUN myfun;
if(hDll!=NULL)
{
myfun=(FUN)GetProcAddress(hDll,"PwdChangePasswordA");
if(!myfun)FreeLibrary(hDll);
else
myfun("SCRSAVE", CPWindow, 0, 0);//函数的调用
}
}
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}