如何运行一个程序,使得它不能使用“窗口”?(100分)

  • 主题发起人 主题发起人 ioi2000
  • 开始时间 开始时间
I

ioi2000

Unregistered / Unconfirmed
GUEST, unregistred user!
如何运行一个程序,使得它不能使用“窗口”?<br>也就是,不准这个程序"画窗口"
 
也就是说用CreateProcess创建一个程序,使得这个程序没有GUI资源
 
program Project1;<br><br>uses<br>&nbsp; Windows;<br>begin<br>&nbsp; MessageBox(0,'你要是不高兴,连我这个对话框也可以不要!','',0);<br>end.<br>
 
dos程序?
 
用API创建简单的窗体,只是引用Windows,Message,如果加入Dialogs程序会增大导380K,如果不引用只有15K。看来编写高质量的程序还是要用API啊,不过也是挺麻烦的。<br>program Project1;<br><br>uses<br>&nbsp; windows,<br>&nbsp; Messages;<br><br>var<br>&nbsp; TheMessage: TMsg;<br><br>function WindowProc(TheWindow: HWND; TheMessage, WParam,LParam: LongInt):LongInt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stdcall;export;<br>begin<br>&nbsp; Case TheMessage of<br>&nbsp; &nbsp; WM_Destroy : begin<br>&nbsp; &nbsp; &nbsp; PostQuitMessage(0);<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; WM_SIZE : begin<br>&nbsp; &nbsp; &nbsp; MessageBox(0,'Size','Form',0);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; Result := DefWindowProc(TheWindow,TheMessage,WParam,LParam);<br>end;<br><br>function RegisterFormClass(FormClassName: Pchar):Boolean;<br>var<br>&nbsp; FormClass : TWndClass;<br>begin<br>&nbsp; FormClass.style := CS_HREDRAW or CS_VREDRAW;<br>&nbsp; FormClass.lpfnWndProc := @WindowProc;<br>&nbsp; FormClass.cbClsExtra := 0;<br>&nbsp; FormClass.cbWndExtra := 0;<br>&nbsp; FormClass.hInstance := HInstance;<br>&nbsp; FormClass.hIcon := 0;<br>&nbsp; FormClass.hCursor := 0;<br>&nbsp; FormClass.hbrBackground := COLOR_WINDOW;<br>&nbsp; FormClass.lpszMenuName := nil;<br>&nbsp; FormClass.lpszClassName := FormClassName;<br><br>&nbsp; Result := windows.RegisterClass(FormClass) &lt;&gt; 0;<br>end;<br><br>function CreateForm(FormClassName : PChar): HWND;<br>begin<br>&nbsp; Result := CreateWindowEx(0,FormClassName,'Form',WS_OVERLAPPEDWINDOW,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cw_usedefault,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cw_usedefault,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cw_usedefault,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cw_usedefault,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HInstance,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil);<br>end;<br><br>procedure ShowForm(aForm: HWND);<br>begin<br>&nbsp; ShowWindow(aForm,SW_SHOWNORMAL);<br>&nbsp; UpdateWindow(aForm);<br>end;<br><br>begin<br>&nbsp; { TODO -oUser -cConsole Main : Insert code here }<br>&nbsp; if not RegisterFormClass('test') then<br>&nbsp; begin<br>&nbsp; &nbsp; MessageBox(0,'Register class failed','Error',0);<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; ShowForm(CreateForm('test'));<br>&nbsp; while GetMessage(TheMessage,0,0,0) do<br>&nbsp; begin<br>&nbsp; &nbsp; TranslateMessage(TheMessage);<br>&nbsp; &nbsp; DispatchMessage(TheMessage);<br>&nbsp; end;<br>end.
 
看这边最后我的代码 http://www.delphibbs.com/delphibbs/dispq.asp?lid=2646908
 
我不是这个意思啊ft<br>譬如我调用一些console程序(用createprocess调用的),这些程序可能会“出错”。<br>这里的“出错”是指系统给出的那种警告对话框(譬如ACCESS_VIOLATION、divide by zero)之类的。我想这些对话框不出现,它出错了就出错了,因为我可以通过最后的推出代码来判断程序是否出错。如果这些对话框出现了,要人为干预(也就是点那个确定)之后才可以继续运行。我的意思就是说有没有办法让这些对话框不出现。
 
用try啊。
 
你可以采用try....except &nbsp; end来处理啊。<br>try<br>createprocess.....<br>..........<br>except<br>end;<br>什么也不做,就可以达到你的要求。
 
我更ft了<br>我是说我用CreateProcess调用了一个其他程序阿,不是说我自己的程序会出错。
 
后退
顶部