暴米花 发表于 2006-12-12 11:05:00

在全屏游戏中弹出非模态对话框的资料

<strong><br/><br/></strong>DirectDraw&nbsp;7.0<br/>Displaying&nbsp;a&nbsp;Window&nbsp;in&nbsp;Full-Screen&nbsp;Mode<br/>&nbsp;<br/>The&nbsp;information&nbsp;in&nbsp;this&nbsp;topic&nbsp;pertains&nbsp;only&nbsp;to&nbsp;applications&nbsp;written&nbsp;in&nbsp;C++.&nbsp;<br/>&nbsp;<br/>In&nbsp;full-screen&nbsp;mode,&nbsp;DirectDraw&nbsp;has&nbsp;exclusive&nbsp;control&nbsp;over&nbsp;the&nbsp;display.&nbsp;As&nbsp;a&nbsp;result,&nbsp;dialog&nbsp;boxes&nbsp;and&nbsp;other&nbsp;windows&nbsp;created&nbsp;through&nbsp;GDI&nbsp;are&nbsp;not&nbsp;normally&nbsp;visible.&nbsp;However,&nbsp;by&nbsp;using&nbsp;special&nbsp;techniques&nbsp;you&nbsp;can&nbsp;incorporate&nbsp;a&nbsp;Windows&nbsp;dialog&nbsp;box,&nbsp;HTML&nbsp;Help,&nbsp;or&nbsp;any&nbsp;other&nbsp;kind&nbsp;of&nbsp;window&nbsp;in&nbsp;your&nbsp;application. <p></p><p>The&nbsp;FSWindow&nbsp;Sample&nbsp;illustrates&nbsp;how&nbsp;a&nbsp;dialog&nbsp;box&nbsp;can&nbsp;be&nbsp;displayed&nbsp;and&nbsp;updated&nbsp;in&nbsp;a&nbsp;full-screen&nbsp;application,&nbsp;and&nbsp;how&nbsp;mouse&nbsp;clicks&nbsp;and&nbsp;keystrokes&nbsp;work&nbsp;just&nbsp;as&nbsp;if&nbsp;the&nbsp;dialog&nbsp;box&nbsp;were&nbsp;being&nbsp;displayed&nbsp;by&nbsp;GDI.</p><p>In&nbsp;FSWindow,&nbsp;the&nbsp;dialog&nbsp;box&nbsp;is&nbsp;created&nbsp;and&nbsp;"shown"&nbsp;as&nbsp;an&nbsp;ordinary&nbsp;dialog&nbsp;window:</p><p>hWndDlg&nbsp;=&nbsp;CreateDialog(g_hInstance,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MAKEINTRESOURCE(IDD_DIALOG_SAMPLE),<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hWnd,&nbsp;(DLGPROC)&nbsp;SampleDlgProc);<br/>ShowWindow(hWndDlg,&nbsp;SW_SHOWNORMAL);</p><p>Of&nbsp;course,&nbsp;at&nbsp;this&nbsp;point&nbsp;the&nbsp;dialog&nbsp;box&nbsp;is&nbsp;shown&nbsp;only&nbsp;on&nbsp;the&nbsp;hidden&nbsp;GDI&nbsp;surface.&nbsp;It&nbsp;does&nbsp;not&nbsp;appear&nbsp;on&nbsp;the&nbsp;primary&nbsp;surface,&nbsp;which&nbsp;is&nbsp;controlled&nbsp;by&nbsp;DirectDraw.&nbsp;</p><p>If&nbsp;the&nbsp;hardware&nbsp;capabilities&nbsp;include&nbsp;DDCAPS2_CANRENDERWINDOWED&nbsp;(see&nbsp;DDCAPS),&nbsp;displaying&nbsp;and&nbsp;updating&nbsp;the&nbsp;dialog&nbsp;box&nbsp;is&nbsp;easy.&nbsp;The&nbsp;application&nbsp;simply&nbsp;calls&nbsp;the&nbsp;IDirectDraw7::FlipToGDISurface&nbsp;method,&nbsp;which&nbsp;makes&nbsp;the&nbsp;GDI&nbsp;surface&nbsp;the&nbsp;primary&nbsp;surface.&nbsp;From&nbsp;now&nbsp;on,&nbsp;all&nbsp;updates&nbsp;to&nbsp;the&nbsp;dialog&nbsp;box&nbsp;will&nbsp;be&nbsp;displayed&nbsp;automatically,&nbsp;because&nbsp;GDI&nbsp;is&nbsp;now&nbsp;rendering&nbsp;directly&nbsp;to&nbsp;the&nbsp;front&nbsp;buffer.&nbsp;The&nbsp;application&nbsp;continues&nbsp;rendering&nbsp;to&nbsp;the&nbsp;back&nbsp;buffer,&nbsp;and&nbsp;on&nbsp;each&nbsp;pass&nbsp;through&nbsp;the&nbsp;rendering&nbsp;loop&nbsp;the&nbsp;contents&nbsp;of&nbsp;the&nbsp;back&nbsp;buffer&nbsp;are&nbsp;blitted&nbsp;to&nbsp;the&nbsp;front&nbsp;buffer&nbsp;by&nbsp;DirectDraw.&nbsp;The&nbsp;dialog&nbsp;box&nbsp;is&nbsp;not&nbsp;overwritten&nbsp;because&nbsp;the&nbsp;front&nbsp;buffer&nbsp;is&nbsp;clipped&nbsp;to&nbsp;the&nbsp;application&nbsp;window,&nbsp;and&nbsp;the&nbsp;dialog&nbsp;box&nbsp;is&nbsp;obscuring&nbsp;part&nbsp;of&nbsp;that&nbsp;window.</p><p>The&nbsp;following&nbsp;code,&nbsp;from&nbsp;the&nbsp;FSWindow_Init&nbsp;function,&nbsp;creates&nbsp;the&nbsp;clipper,&nbsp;associates&nbsp;it&nbsp;with&nbsp;the&nbsp;application&nbsp;window,&nbsp;and&nbsp;brings&nbsp;the&nbsp;GDI&nbsp;surface&nbsp;to&nbsp;the&nbsp;front:</p><p>if&nbsp;(ddObject-&gt;CreateClipper(0,&nbsp;&amp;ddClipper,&nbsp;NULL)&nbsp;==&nbsp;DD_OK)<br/>&nbsp;&nbsp;&nbsp;&nbsp;ddClipper-&gt;SetHWnd(0,&nbsp;hwndAppWindow);<br/>ddObject-&gt;FlipToGDISurface();</p><p>Then,&nbsp;in&nbsp;the&nbsp;FSWindow_Update&nbsp;function,&nbsp;the&nbsp;following&nbsp;code&nbsp;blits&nbsp;the&nbsp;rendered&nbsp;contents&nbsp;of&nbsp;the&nbsp;back&nbsp;buffer&nbsp;to&nbsp;the&nbsp;clipping&nbsp;region:</p><p>ddFrontBuffer-&gt;SetClipper(ddClipper);<br/>ddFrontBuffer-&gt;Blt(NULL,&nbsp;ddBackBuffer,&nbsp;NULL,&nbsp;DDBLT_WAIT,&nbsp;NULL);</p><p>Note&nbsp;that&nbsp;because&nbsp;the&nbsp;GDI&nbsp;surface&nbsp;is&nbsp;the&nbsp;primary&nbsp;surface,&nbsp;Windows&nbsp;continues&nbsp;displaying&nbsp;the&nbsp;mouse&nbsp;cursor.&nbsp;(This&nbsp;would&nbsp;not&nbsp;be&nbsp;the&nbsp;case,&nbsp;however,&nbsp;if&nbsp;the&nbsp;application&nbsp;were&nbsp;using&nbsp;DirectInput&nbsp;with&nbsp;the&nbsp;mouse&nbsp;device&nbsp;at&nbsp;the&nbsp;exclusive&nbsp;cooperative&nbsp;level.)</p><p>For&nbsp;hardware&nbsp;that&nbsp;does&nbsp;not&nbsp;have&nbsp;the&nbsp;DDCAPS2_CANRENDERWINDOWED&nbsp;capability,&nbsp;the&nbsp;process&nbsp;of&nbsp;displaying&nbsp;and&nbsp;updating&nbsp;a&nbsp;window&nbsp;in&nbsp;full-screen&nbsp;mode&nbsp;is&nbsp;somewhat&nbsp;more&nbsp;complicated.&nbsp;In&nbsp;this&nbsp;case,&nbsp;the&nbsp;application&nbsp;is&nbsp;responsible&nbsp;for&nbsp;obtaining&nbsp;the&nbsp;image&nbsp;of&nbsp;the&nbsp;window&nbsp;created&nbsp;by&nbsp;GDI&nbsp;and&nbsp;blitting&nbsp;it&nbsp;to&nbsp;the&nbsp;back&nbsp;buffer&nbsp;after&nbsp;the&nbsp;full-screen&nbsp;rendering&nbsp;has&nbsp;been&nbsp;done.&nbsp;The&nbsp;entire&nbsp;back&nbsp;buffer&nbsp;is&nbsp;then&nbsp;flipped&nbsp;to&nbsp;the&nbsp;front&nbsp;in&nbsp;the&nbsp;usual&nbsp;way.</p><p>The&nbsp;FSWindow&nbsp;sample&nbsp;provides&nbsp;two&nbsp;different&nbsp;methods&nbsp;for&nbsp;accessing&nbsp;the&nbsp;display&nbsp;memory&nbsp;of&nbsp;the&nbsp;window,&nbsp;depending&nbsp;on&nbsp;whether&nbsp;the&nbsp;content&nbsp;is&nbsp;static&nbsp;or&nbsp;dynamic.&nbsp;The&nbsp;method&nbsp;for&nbsp;static&nbsp;content&nbsp;is&nbsp;faster&nbsp;because&nbsp;it&nbsp;involves&nbsp;blitting&nbsp;from&nbsp;a&nbsp;memory&nbsp;device&nbsp;context&nbsp;rather&nbsp;than&nbsp;a&nbsp;screen&nbsp;device&nbsp;context.&nbsp;This&nbsp;method&nbsp;should&nbsp;be&nbsp;used&nbsp;for&nbsp;windows&nbsp;that&nbsp;do&nbsp;not&nbsp;change,&nbsp;such&nbsp;as&nbsp;informational&nbsp;dialog&nbsp;boxes.&nbsp;(Remember,&nbsp;though,&nbsp;that&nbsp;unless&nbsp;you&nbsp;manually&nbsp;update&nbsp;the&nbsp;bitmap&nbsp;in&nbsp;response&nbsp;to&nbsp;events,&nbsp;even&nbsp;basic&nbsp;animation&nbsp;such&nbsp;as&nbsp;a&nbsp;button&nbsp;press&nbsp;will&nbsp;not&nbsp;be&nbsp;visible&nbsp;to&nbsp;the&nbsp;user.)</p><p>If&nbsp;the&nbsp;content&nbsp;is&nbsp;static,&nbsp;FSWindow&nbsp;calls&nbsp;the&nbsp;CreateBMPFromWindow&nbsp;function&nbsp;when&nbsp;the&nbsp;window&nbsp;is&nbsp;initialized.&nbsp;This&nbsp;function&nbsp;creates&nbsp;a&nbsp;bitmap&nbsp;and&nbsp;blits&nbsp;the&nbsp;contents&nbsp;of&nbsp;the&nbsp;window&nbsp;into&nbsp;it.&nbsp;The&nbsp;bitmap&nbsp;handle&nbsp;is&nbsp;stored&nbsp;in&nbsp;the&nbsp;global&nbsp;variable&nbsp;hwndFSWindowBMP.&nbsp;Whenever&nbsp;the&nbsp;primary&nbsp;surface&nbsp;is&nbsp;about&nbsp;to&nbsp;be&nbsp;updated,&nbsp;this&nbsp;bitmap&nbsp;is&nbsp;blitted&nbsp;to&nbsp;the&nbsp;back&nbsp;buffer,&nbsp;as&nbsp;follows:</p><p>if&nbsp;(FSWindow_IsStatic)<br/>{<br/>&nbsp;&nbsp;&nbsp;&nbsp;hdcMemory&nbsp;=&nbsp;CreateCompatibleDC(NULL);<br/>&nbsp;&nbsp;&nbsp;&nbsp;SelectObject(hdcMemory,&nbsp;hwndFSWindowBMP);<br/>&nbsp;&nbsp;&nbsp;&nbsp;BitBlt(hdcBackBuffer,&nbsp;x,&nbsp;y,&nbsp;cx,&nbsp;cy,&nbsp;hdcMemory,&nbsp;0,&nbsp;0,&nbsp;SRCCOPY);<br/>&nbsp;&nbsp;&nbsp;&nbsp;DeleteDC(hdcMemory);<br/>}</p><p>If,&nbsp;on&nbsp;the&nbsp;other&nbsp;hand,&nbsp;the&nbsp;content&nbsp;of&nbsp;the&nbsp;window&nbsp;is&nbsp;dynamic,&nbsp;the&nbsp;following&nbsp;code&nbsp;is&nbsp;executed.&nbsp;It&nbsp;blits&nbsp;the&nbsp;image&nbsp;directly&nbsp;from&nbsp;the&nbsp;GDI&nbsp;surface&nbsp;(represented&nbsp;by&nbsp;the&nbsp;hdcScreen&nbsp;device&nbsp;context)&nbsp;to&nbsp;the&nbsp;back&nbsp;buffer.</p><p>BitBlt(hdcBackBuffer,&nbsp;x,&nbsp;y,&nbsp;cx,&nbsp;cy,&nbsp;hdcScreen,&nbsp;x,&nbsp;y,&nbsp;SRCCOPY);</p><p>The&nbsp;coordinates&nbsp;represent&nbsp;the&nbsp;position&nbsp;and&nbsp;dimensions&nbsp;of&nbsp;the&nbsp;window&nbsp;on&nbsp;the&nbsp;GDI&nbsp;surface,&nbsp;as&nbsp;retrieved&nbsp;through&nbsp;a&nbsp;call&nbsp;to&nbsp;GetWindowRect.</p><p>When&nbsp;the&nbsp;FSWindow&nbsp;application&nbsp;is&nbsp;running&nbsp;on&nbsp;hardware&nbsp;that&nbsp;does&nbsp;not&nbsp;have&nbsp;the&nbsp;DDCAPS2_CANRENDERWINDOWED&nbsp;capability,&nbsp;it&nbsp;does&nbsp;not&nbsp;use&nbsp;the&nbsp;GDI&nbsp;surface,&nbsp;so&nbsp;Windows&nbsp;cannot&nbsp;display&nbsp;the&nbsp;mouse&nbsp;cursor.&nbsp;The&nbsp;application&nbsp;takes&nbsp;over&nbsp;this&nbsp;task&nbsp;by&nbsp;obtaining&nbsp;information&nbsp;about&nbsp;the&nbsp;cursor&nbsp;and&nbsp;displaying&nbsp;it&nbsp;on&nbsp;the&nbsp;back&nbsp;buffer&nbsp;just&nbsp;before&nbsp;the&nbsp;flip.<br/>有谁有FSWINDOW的原代码的朋友请寄我一份,我实在找不到DIRECTX7.0完整的SDK了<br/>Email:tangfang2001@sina.com&nbsp;</p>
页: [1]
查看完整版本: 在全屏游戏中弹出非模态对话框的资料