游戏窗口化的一些问题,高手帮忙看看!(急) ( 积分: 100 )

  • 主题发起人 主题发起人 zxflsx
  • 开始时间 开始时间
Z

zxflsx

Unregistered / Unconfirmed
GUEST, unregistred user!
现在我的代码可以让任何窗口变成800*600的窗口,并可隐藏和显示。但有个问题就是在窗口化后,无法运行其他程序,一但运行,则窗口化的游戏就退出了。(MU登陆器就没事是用VC编的),高手帮解释一下,多多指点!!!!急盼!!!!!!!!!!!!!<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Menus, SUIPopupMenu, CoolTrayIcon, ExtCtrls, jpeg;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;CoolTrayIcon1: TCoolTrayIcon;<br> &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp;Image1: TImage;<br> &nbsp; &nbsp;PopupMenu1: TPopupMenu;<br> &nbsp; &nbsp;N1: TMenuItem;<br> &nbsp; &nbsp;N2: TMenuItem;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp; &nbsp;procedure N1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure N2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;procedure HotKeyDown(var Msg:Tmessage);message WM_HOTKEY;<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;HotKeyid,HotKeyid1,HotKeyid2:Integer;<br> &nbsp;pHwnd:Hwnd;<br> &nbsp;pHmenu:HMENU;<br> &nbsp;style,exstyle:longint;<br> &nbsp;devmode1:DEVMODE;<br> &nbsp;bool:boolean;<br>implementation<br>uses Unit2;<br>{$R *.dfm}<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br><br>begin<br> &nbsp;bool:=false;<br> &nbsp;form1.Hide;<br> &nbsp;//GlobalAddAtom函数得到唯一标识<br> &nbsp;HotKeyid2:=GlobalAddAtom('MyHotKey')-$C00;<br> &nbsp;HotKeyid:=GlobalAddAtom('MyHotKey1')-$C00;<br> &nbsp;//HotKeyId的合法取之范围是0x0000到0xBFFF之间, GlobalAddAtom函数得到的值<br> &nbsp;//在0xC000到0xFFFF之间,所以减掉0xC000来满足调用要求。<br> &nbsp;RegisterHotKey(Handle,HotKeyid,0,VK_F11);<br> &nbsp;RegisterHotKey(Handle,HotKeyid1,0,VK_F9);<br> &nbsp;//热键的辅助按键包括Mod_Ctrl 、Mod_Alt、Mod_Shift,对于Windows兼容键盘还支持Windows<br> &nbsp;//键,即其键面上有Windows标志的那个键,其值为Mod_win。<br> &nbsp;//上面 的代码注册了一个热键:ALT+F8。当然如果你希望象TAKEIT那样,只用F8, 就这么写:<br> &nbsp;//RegisterHotKey(Handle, hotkeyid, 0, VK_F8);<br><br>end;<br>//按下定义的全局热键所响应的代码<br>procedure TForm1.HotKeyDown(var Msg:Tmessage);<br>begin<br> &nbsp;if (Msg.LParamLo=0) and (Msg.LParamHi=VK_F11) then<br> &nbsp;begin<br> &nbsp; &nbsp; pHwnd:=GetForegroundWindow(); //得到在屏幕上最前端的窗口的句柄;也可以用其他API函数指定某个特定窗口<br> &nbsp; &nbsp; //以下是把定义把屏幕变更为1024*768,32位色彩,刷新率为75赫兹<br> &nbsp; &nbsp; if EnumDisplaySettings(0,0,devmode1) then<br> &nbsp; begin<br> &nbsp; &nbsp; devmode1.dmPelsWidth:=1024;<br> &nbsp; devmode1.dmPelsHeight:=768;<br> &nbsp; &nbsp; devmode1.dmBitsPerPel:=32;<br> &nbsp; devmode1.dmDisplayFrequency:=75;<br> ChangeDisplaySettings(devmode1,0);<br> &nbsp;end;<br> &nbsp;pHmenu:=CreateMenu();<br> &nbsp;SetMenu(pHwnd,pHmenu);<br> &nbsp;//得到窗口原来的属性<br> &nbsp;style:=GetWindowLong(pHwnd,GWL_STYLE);<br> &nbsp;//定义新属性<br> &nbsp;style:=WS_OVERLAPPEDWINDOW or WS_VISIBLE ;<br> &nbsp;//更改窗口属性<br> &nbsp;SetWindowLong(pHwnd,GWL_STYLE,style);<br> &nbsp;//得到窗口扩展属性<br> &nbsp;exstyle:=GetWindowLong(pHwnd,GWL_EXSTYLE);<br> &nbsp;//定义新扩展属性<br> exstyle:=WS_EX_APPWINDOW or WS_EX_WINDOWEDGE;<br> &nbsp;//更改窗口扩展属性<br> SetWindowLong(pHwnd,GWL_EXSTYLE,exstyle);<br> &nbsp;//更改的屏幕以屏幕的0,0为坐标,大小为800*600<br> &nbsp;SetWindowPos(pHwnd,HWND_NOTOPMOST,0,0,800,600,SWP_SHOWWINDOW);<br> &nbsp; ShowWindow(pHwnd,SW_SHOWNORMAL);<br> &nbsp;end;<br><br>if (Msg.LParamLo=0) and (Msg.LParamHi=VK_F9) then<br> &nbsp; &nbsp;if bool=false then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; ShowWindow(pHwnd,SW_HIDE); //隐藏窗口<br> &nbsp; &nbsp; &nbsp; bool:=true;<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; //if (Msg.LParamLo=0) or (Msg.LParamHi=VK_F9) then<br> &nbsp; &nbsp; &nbsp; ShowWindow(pHwnd,SW_RESTORE); //恢复窗口<br> &nbsp; &nbsp; &nbsp; bool:=false;<br> &nbsp; &nbsp; &nbsp;end;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp; &nbsp;UnRegisterHotKey(handle,HotKeyid); &nbsp;//注销热键<br>end;<br><br>procedure TForm1.N1Click(Sender: TObject);<br>begin<br> &nbsp;UnRegisterHotKey(handle,HotKeyid);<br> &nbsp;form1.Close;<br>end;<br><br>procedure TForm1.N2Click(Sender: TObject);<br>begin<br> &nbsp;form2.show;<br>end;<br><br>end.
 
现在我的代码可以让任何窗口变成800*600的窗口,并可隐藏和显示。但有个问题就是在窗口化后,无法运行其他程序,一但运行,则窗口化的游戏就退出了。(MU登陆器就没事是用VC编的),高手帮解释一下,多多指点!!!!急盼!!!!!!!!!!!!!<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Menus, SUIPopupMenu, CoolTrayIcon, ExtCtrls, jpeg;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;CoolTrayIcon1: TCoolTrayIcon;<br> &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp;Image1: TImage;<br> &nbsp; &nbsp;PopupMenu1: TPopupMenu;<br> &nbsp; &nbsp;N1: TMenuItem;<br> &nbsp; &nbsp;N2: TMenuItem;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp; &nbsp;procedure N1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure N2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;procedure HotKeyDown(var Msg:Tmessage);message WM_HOTKEY;<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;HotKeyid,HotKeyid1,HotKeyid2:Integer;<br> &nbsp;pHwnd:Hwnd;<br> &nbsp;pHmenu:HMENU;<br> &nbsp;style,exstyle:longint;<br> &nbsp;devmode1:DEVMODE;<br> &nbsp;bool:boolean;<br>implementation<br>uses Unit2;<br>{$R *.dfm}<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br><br>begin<br> &nbsp;bool:=false;<br> &nbsp;form1.Hide;<br> &nbsp;//GlobalAddAtom函数得到唯一标识<br> &nbsp;HotKeyid2:=GlobalAddAtom('MyHotKey')-$C00;<br> &nbsp;HotKeyid:=GlobalAddAtom('MyHotKey1')-$C00;<br> &nbsp;//HotKeyId的合法取之范围是0x0000到0xBFFF之间, GlobalAddAtom函数得到的值<br> &nbsp;//在0xC000到0xFFFF之间,所以减掉0xC000来满足调用要求。<br> &nbsp;RegisterHotKey(Handle,HotKeyid,0,VK_F11);<br> &nbsp;RegisterHotKey(Handle,HotKeyid1,0,VK_F9);<br> &nbsp;//热键的辅助按键包括Mod_Ctrl 、Mod_Alt、Mod_Shift,对于Windows兼容键盘还支持Windows<br> &nbsp;//键,即其键面上有Windows标志的那个键,其值为Mod_win。<br> &nbsp;//上面 的代码注册了一个热键:ALT+F8。当然如果你希望象TAKEIT那样,只用F8, 就这么写:<br> &nbsp;//RegisterHotKey(Handle, hotkeyid, 0, VK_F8);<br><br>end;<br>//按下定义的全局热键所响应的代码<br>procedure TForm1.HotKeyDown(var Msg:Tmessage);<br>begin<br> &nbsp;if (Msg.LParamLo=0) and (Msg.LParamHi=VK_F11) then<br> &nbsp;begin<br> &nbsp; &nbsp; pHwnd:=GetForegroundWindow(); //得到在屏幕上最前端的窗口的句柄;也可以用其他API函数指定某个特定窗口<br> &nbsp; &nbsp; //以下是把定义把屏幕变更为1024*768,32位色彩,刷新率为75赫兹<br> &nbsp; &nbsp; if EnumDisplaySettings(0,0,devmode1) then<br> &nbsp; begin<br> &nbsp; &nbsp; devmode1.dmPelsWidth:=1024;<br> &nbsp; devmode1.dmPelsHeight:=768;<br> &nbsp; &nbsp; devmode1.dmBitsPerPel:=32;<br> &nbsp; devmode1.dmDisplayFrequency:=75;<br> ChangeDisplaySettings(devmode1,0);<br> &nbsp;end;<br> &nbsp;pHmenu:=CreateMenu();<br> &nbsp;SetMenu(pHwnd,pHmenu);<br> &nbsp;//得到窗口原来的属性<br> &nbsp;style:=GetWindowLong(pHwnd,GWL_STYLE);<br> &nbsp;//定义新属性<br> &nbsp;style:=WS_OVERLAPPEDWINDOW or WS_VISIBLE ;<br> &nbsp;//更改窗口属性<br> &nbsp;SetWindowLong(pHwnd,GWL_STYLE,style);<br> &nbsp;//得到窗口扩展属性<br> &nbsp;exstyle:=GetWindowLong(pHwnd,GWL_EXSTYLE);<br> &nbsp;//定义新扩展属性<br> exstyle:=WS_EX_APPWINDOW or WS_EX_WINDOWEDGE;<br> &nbsp;//更改窗口扩展属性<br> SetWindowLong(pHwnd,GWL_EXSTYLE,exstyle);<br> &nbsp;//更改的屏幕以屏幕的0,0为坐标,大小为800*600<br> &nbsp;SetWindowPos(pHwnd,HWND_NOTOPMOST,0,0,800,600,SWP_SHOWWINDOW);<br> &nbsp; ShowWindow(pHwnd,SW_SHOWNORMAL);<br> &nbsp;end;<br><br>if (Msg.LParamLo=0) and (Msg.LParamHi=VK_F9) then<br> &nbsp; &nbsp;if bool=false then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; ShowWindow(pHwnd,SW_HIDE); //隐藏窗口<br> &nbsp; &nbsp; &nbsp; bool:=true;<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; begin<br> &nbsp; &nbsp; //if (Msg.LParamLo=0) or (Msg.LParamHi=VK_F9) then<br> &nbsp; &nbsp; &nbsp; ShowWindow(pHwnd,SW_RESTORE); //恢复窗口<br> &nbsp; &nbsp; &nbsp; bool:=false;<br> &nbsp; &nbsp; &nbsp;end;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp; &nbsp;UnRegisterHotKey(handle,HotKeyid); &nbsp;//注销热键<br>end;<br><br>procedure TForm1.N1Click(Sender: TObject);<br>begin<br> &nbsp;UnRegisterHotKey(handle,HotKeyid);<br> &nbsp;form1.Close;<br>end;<br><br>procedure TForm1.N2Click(Sender: TObject);<br>begin<br> &nbsp;form2.show;<br>end;<br><br>end.
 
多数游戏是directx结构的吧。directx是和硬件密切相关的,比如像素格式,比如surface格式,你指定的屏幕格式,未必就和游戏的设定一致,所以必然的有许多游戏会异常退出。
 
楼上,能不能在说的具体点或介绍点书!?
 
注释一下:一般网络的3D游戏用到DX编程,DX的函数可以控制显示,使程序独占显示设备,不能运行其他程序。我想知道有什么方法可以象GETWINDOWLONG()函数一样得到自己想要的窗口信息。我不知道如何引入和调用DX的函数。
 
后退
顶部