建立一个api窗口(20分)

  • 主题发起人 主题发起人 yifeibbs
  • 开始时间 开始时间
Y

yifeibbs

Unregistered / Unconfirmed
GUEST, unregistred user!
用api建立一个简单的窗体,不需要任何其它东西(标签,按钮等等)。<br>不要涉及vcl,使用api函数调用的方式建立!<br>不怕简单,完整源码!
 
HWND CreateWindow(<br>&nbsp; LPCTSTR lpClassName, &nbsp;// registered class name<br>&nbsp; LPCTSTR lpWindowName, // window name<br>&nbsp; DWORD dwStyle, &nbsp; &nbsp; &nbsp; &nbsp;// window style<br>&nbsp; int x, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// horizontal position of window<br>&nbsp; int y, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// vertical position of window<br>&nbsp; int nWidth, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // window width<br>&nbsp; int nHeight, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// window height<br>&nbsp; HWND hWndParent, &nbsp; &nbsp; &nbsp;// handle to parent or owner window<br>&nbsp; HMENU hMenu, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// menu handle or child identifier<br>&nbsp; HINSTANCE hInstance, &nbsp;// handle to application instance<br>&nbsp; LPVOID lpParam &nbsp; &nbsp; &nbsp; &nbsp;// window-creation data<br>);<br>
 
请给一个源码例子。<br>program API;<br>uses<br>&nbsp; SysUtils,windows;<br><br>begin<br>&nbsp; //建立<br>&nbsp; createwindow(pchar('xform'),pchar('xform1'),0,0,0,400,400,0,0,0,0);<br>&nbsp; //显示<br>end.
 
createwindow();不是API呀
 
用createwindowex,需要uses shellapi吧
 
本来记得看过一个例子,名字是世上代码最少的窗口。可惜没记住!<br>我本来也以为建立一个调用api的窗口不是难事,所以只有一点分,没想到竟然没人给个代码看看!<br>请大虾关心关心俺吧!俺加分!
 
下面的工程文件建立一个空白窗体,自己看吧。<br>program Project1;<br>uses<br>&nbsp; windows, messages;<br><br>//消息处理函数<br>function MainWndProc(Wnd: HWND; Msg: UINT; WParam: WPARAM;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LParam: LPARAM): LRESULT; stdcall; export;<br>begin<br>&nbsp; Result := 0;<br>&nbsp; case Msg of<br>&nbsp; &nbsp; WM_DESTROY: PostQuitMessage(0);<br>&nbsp; else<br>&nbsp; &nbsp; &nbsp;result := DefWindowProc( Wnd, Msg, wParam, lParam );<br>&nbsp; end;<br>end;<br><br>var<br>&nbsp; wc: TWndClassA;<br>&nbsp; hWindow: HWND;<br>&nbsp; Msg: TMsg; <br>begin<br>&nbsp;with wc do<br>&nbsp; begin<br>&nbsp; &nbsp; lpszClassName &nbsp; := 'AppClass';<br>&nbsp; &nbsp; lpfnWndProc &nbsp; &nbsp; := @MainWndProc;<br>&nbsp; &nbsp; style &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := CS_VREDRAW or CS_HREDRAW;<br>&nbsp; &nbsp; hInstance &nbsp; &nbsp; &nbsp; := hInstance;<br>&nbsp; &nbsp; hIcon &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; := LoadIcon(0,IDI_APPLICATION);<br>&nbsp; &nbsp; hCursor &nbsp; &nbsp; &nbsp; &nbsp; := LoadCursor(0,IDC_ARROW);<br>&nbsp; &nbsp; hbrBackground &nbsp; := (COLOR_WINDOW+1);<br>&nbsp; &nbsp; lpszMenuName &nbsp; &nbsp;:= nil;<br>&nbsp; &nbsp; cbClsExtra &nbsp; &nbsp; &nbsp;:= 0;<br>&nbsp; &nbsp; cbWndExtra &nbsp; &nbsp; &nbsp;:= 0;<br>&nbsp; end;<br>&nbsp; RegisterClassA(wc); <br>&nbsp; hWindow := CreateWindowEx(WS_EX_CONTROLPARENT or WS_EX_WINDOWEDGE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'AppClass',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'API',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_VISIBLE or WS_CLIPSIBLINGS or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_CLIPCHILDREN or WS_OVERLAPPEDWINDOW,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10,10,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 400,300,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInstance,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil);<br><br>&nbsp; ShowWindow(hWindow,CmdShow);<br>&nbsp; while GetMessage(Msg, 0, 0, 0) do<br>&nbsp; begin<br>&nbsp; &nbsp; TranslateMessage(Msg);<br>&nbsp; &nbsp; DispatchMessage(Msg);<br>&nbsp; end;<br>end.
 
///////////////////////////////////////////////////////////////////////////////<br>// ddex1_api.dpr<br>///////////////////////////////////////////////////////////////////////////////<br>// Delphi conversion of the ddex1 example contained in Microsoft's DirectX sdk.<br>// Based on Eric Unger's conversions of the DirectX headers. They're available<br>// at http://www.delphi-jedi.org. Bug reports to meyerhoff@earthling.net.<br>///////////////////////////////////////////////////////////////////////////////<br>// Description:<br>// Direct Draw example program 1. &nbsp;Creates a Direct Draw object and then a<br>// primary surface with a back buffer. Slowly flips between the primary surface<br>// and the back buffer. Press F12 or Escape to terminate the program.<br>///////////////////////////////////////////////////////////////////////////////<br>program ddex1_api;<br><br>//-----------------------------------------------------------------------------<br>// Include files<br>//-----------------------------------------------------------------------------<br>uses<br>&nbsp; Windows, Messages, DirectDraw, SysUtils;<br><br>{$R *.res}<br><br>const<br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; // Local definitions<br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; NAME &nbsp;: PChar = 'DDExample1';<br>&nbsp; TITLE : PChar = 'Direct Draw Example 1';<br><br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; // Default settings<br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; TIMER_ID &nbsp; = 1;<br>&nbsp; TIMER_RATE = 500;<br><br>var<br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; // Global data<br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; g_pDD &nbsp; &nbsp; &nbsp; &nbsp; : IDirectDraw7; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// DirectDraw object<br>&nbsp; g_pDDSPrimary : IDirectDrawSurface7; &nbsp; &nbsp; &nbsp; &nbsp; // DirectDraw primary surface<br>&nbsp; g_pDDSBack &nbsp; &nbsp;: IDirectDrawSurface7; &nbsp; &nbsp; &nbsp; &nbsp; // DirectDraw back surface<br>&nbsp; g_bActive &nbsp; &nbsp; : Boolean &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = False; // Is application active?<br><br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; // Local data<br>&nbsp; //---------------------------------------------------------------------------<br>&nbsp; szMsg &nbsp; &nbsp; &nbsp;: PChar = 'Page Flipping Test: Press F12 to exit';<br>&nbsp; szFrontMsg : PChar = 'Front buffer (F12 to quit)';<br>&nbsp; szBackMsg &nbsp;: PChar = 'Back buffer (F12 to quit)';<br><br>//-----------------------------------------------------------------------------<br>// Name: ReleaseAllObjects<br>// Desc: Finished with all objects we use; release them<br>//-----------------------------------------------------------------------------<br>procedure ReleaseAllObjects;<br>begin<br>&nbsp; if Assigned(g_pDD) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if Assigned(g_pDDSBack) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_pDDSBack := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if Assigned(g_pDDSPrimary) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_pDDSPrimary := nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; g_pDD := nil;<br>&nbsp; &nbsp; end;<br>end;<br><br>//-----------------------------------------------------------------------------<br>// Name: InitFail<br>// Desc: This function is called if an initialization function fails<br>//-----------------------------------------------------------------------------<br>function InitFail(h_Wnd : HWND; hRet : HRESULT; Text : string) : HRESULT;<br>begin<br>&nbsp; ReleaseAllObjects;<br>&nbsp; MessageBox(h_Wnd, PChar(Text + ': ' + DDErrorString(hRet)), TITLE, MB_OK);<br>&nbsp; DestroyWindow(h_Wnd);<br>&nbsp; Result := hRet;<br>end;<br><br>//-----------------------------------------------------------------------------<br>// Name: UpdateFrame<br>// Desc: Displays the proper text for the page<br>//-----------------------------------------------------------------------------<br>var<br>&nbsp; phase : Boolean = False;<br>&nbsp; <br>procedure UpdateFrame(h_Wnd : HWND);<br>var<br>&nbsp; h_DC &nbsp; &nbsp;: HDC;<br>&nbsp; ddbltfx : TDDBltFx;<br>&nbsp; rc &nbsp; &nbsp; &nbsp;: TRect;<br>&nbsp; size &nbsp; &nbsp;: TSize;<br>begin<br>&nbsp; // Use the blter to do a color fill to clear the back buffer<br>&nbsp; FillChar(ddbltfx, SizeOf(ddbltfx), 0);<br>&nbsp; ddbltfx.dwSize := SizeOf(ddbltfx);<br>&nbsp; ddbltfx.dwFillColor := 0;<br>&nbsp; g_pDDSBack.Blt(nil, nil, nil, DDBLT_COLORFILL or DDBLT_WAIT, @ddbltfx);<br><br>&nbsp; if g_pDDSBack.GetDC(h_DC) = DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SetBkColor(h_DC, RGB(0, 0, 255));<br>&nbsp; &nbsp; &nbsp; SetTextColor(h_DC, RGB(255, 255, 0));<br>&nbsp; &nbsp; &nbsp; if phase then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetClientRect(h_Wnd, rc);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetTextExtentPoint(h_DC, szMsg, StrLen(szMsg), size);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextOut(h_DC, (rc.right - size.cx) div 2, (rc.bottom - size.cy) div 2, szMsg, StrLen(szMsg));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextOut(h_DC, 0, 0, szFrontMsg, StrLen(szFrontMsg));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phase := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextOut(h_DC, 0, 0, szBackMsg, StrLen(szBackMsg));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; phase := True;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; g_pDDSBack.ReleaseDC(h_DC);<br>&nbsp; &nbsp; end;<br>end;<br><br>//-----------------------------------------------------------------------------<br>// Name: WindowProc<br>// Desc: The Main Window Procedure<br>//-----------------------------------------------------------------------------<br>function WindowProc(h_Wnd: HWND; aMSG: Cardinal; wParam: Cardinal; lParam: Integer) : Integer; stdcall;<br>var<br>&nbsp; hRet : HRESULT;<br>begin<br>&nbsp; case aMSG of<br>&nbsp; &nbsp; // Pause if minimized<br>&nbsp; &nbsp; WM_ACTIVATE:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if HIWORD(wParam) = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_bActive := True<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; g_bActive := False;<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; // Clean up and close the app<br>&nbsp; &nbsp; WM_DESTROY:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; ReleaseAllObjects;<br>&nbsp; &nbsp; &nbsp; &nbsp; PostQuitMessage(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; // Handle any non-accelerated key commands<br>&nbsp; &nbsp; WM_KEYDOWN:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; case wParam of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VK_ESCAPE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VK_F12:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PostMessage(h_Wnd, WM_CLOSE, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; // Turn off the cursor since this is a full-screen app<br>&nbsp; &nbsp; WM_SETCURSOR:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; SetCursor(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; // Update and flip surfaces<br>&nbsp; &nbsp; WM_TIMER:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if g_bActive and (TIMER_ID = wParam) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UpdateFrame(h_Wnd);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while True do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hRet := g_pDDSPrimary.Flip(nil, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if hRet = DD_OK then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if hRet = DDERR_SURFACELOST then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hRet := g_pDDSPrimary._Restore;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if hRet &lt;&gt; DDERR_WASSTILLDRAWING then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br><br>&nbsp; Result := DefWindowProc(h_Wnd, aMSG, wParam, lParam);<br>end;<br><br>//-----------------------------------------------------------------------------<br>// Name: InitApp<br>// Desc: Do work required for every instance of the application:<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Create the window, initialize data<br>//-----------------------------------------------------------------------------<br>function InitApp(hInst : THANDLE; nCmdShow : Integer) : HRESULT;<br>var<br>&nbsp; h_Wnd : HWND;<br>&nbsp; wc : WNDCLASS;<br>&nbsp; ddsd : TDDSurfaceDesc2;<br>&nbsp; ddscaps : TDDSCaps2;<br>&nbsp; hRet : HRESULT;<br>&nbsp; pDDTemp : IDirectDraw;<br>begin<br>&nbsp; // Set up and register window class<br>&nbsp; wc.style := CS_HREDRAW or CS_VREDRAW;<br>&nbsp; wc.lpfnWndProc := @WindowProc;<br>&nbsp; wc.cbClsExtra := 0;<br>&nbsp; wc.cbWndExtra := 0;<br>&nbsp; wc.hInstance := hInst;<br>&nbsp; wc.hIcon := LoadIcon(hInst, 'MAINICON');<br>&nbsp; wc.hCursor := LoadCursor(0, IDC_ARROW);<br>&nbsp; wc.hbrBackground := GetStockObject(BLACK_BRUSH);<br>&nbsp; wc.lpszMenuName := NAME;<br>&nbsp; wc.lpszClassName := NAME;<br>&nbsp; RegisterClass(wc);<br><br>&nbsp; // Create a window<br>&nbsp; h_Wnd := CreateWindowEx(WS_EX_TOPMOST,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NAME,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TITLE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_POPUP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetSystemMetrics(SM_CXSCREEN),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetSystemMetrics(SM_CYSCREEN),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInst,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil);<br><br>&nbsp; if h_Wnd = 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := 0;<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; ShowWindow(h_Wnd, nCmdShow);<br>&nbsp; UpdateWindow(h_Wnd);<br>&nbsp; SetFocus(h_Wnd);<br><br>&nbsp; ///////////////////////////////////////////////////////////////////////////<br>&nbsp; // Create the main DirectDraw object<br>&nbsp; ///////////////////////////////////////////////////////////////////////////<br>&nbsp; hRet := DirectDrawCreate(nil, pDDTemp, nil);<br>&nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'DirectDrawCreate FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; hRet := pDDTemp.QueryInterface(IDirectDraw7, g_pDD);<br>&nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'QueryInterface FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; pDDTemp := nil;<br><br>&nbsp; // Get exclusive mode<br>&nbsp; hRet := g_pDD.SetCooperativeLevel(h_Wnd, DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN);<br>&nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'SetCooperativeLevel FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; // Set the video mode to 640x480x8<br>&nbsp; hRet := g_pDD.SetDisplayMode(640, 480, 8, 0, 0);<br>&nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'SetDisplayMode FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; // Create the primary surface with 1 back buffer<br>&nbsp; FillChar(ddsd, SizeOf(ddsd), 0);<br>&nbsp; ddsd.dwSize := SizeOf(ddsd);<br>&nbsp; ddsd.dwFlags := DDSD_CAPS or DDSD_BACKBUFFERCOUNT;<br>&nbsp; ddsd.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE or DDSCAPS_FLIP or DDSCAPS_COMPLEX;<br>&nbsp; ddsd.dwBackBufferCount := 1;<br>&nbsp; hRet := g_pDD.CreateSurface(ddsd, g_pDDSPrimary, nil);<br>&nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'CreateSurface FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; // Get a pointer to the back buffer<br>&nbsp; FillChar(ddscaps, SizeOf(ddscaps), 0);<br>&nbsp; ddscaps.dwCaps := DDSCAPS_BACKBUFFER;<br>&nbsp; hRet := g_pDDSPrimary.GetAttachedSurface(ddscaps, g_pDDSBack);<br>&nbsp; if hRet &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'GetAttachedSurface FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; // Create a timer to flip the pages<br>&nbsp; if TIMER_ID &lt;&gt; SetTimer(h_Wnd, TIMER_ID, TIMER_RATE, nil) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := InitFail(h_Wnd, hRet, 'SetTimer FAILED');<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; Result := DD_OK;<br>end;<br><br>//-----------------------------------------------------------------------------<br>// Name: WinMain<br>// Desc: Initialization, message loop<br>//-----------------------------------------------------------------------------<br>var<br>&nbsp; aMSG : MSG;<br>begin<br>&nbsp; if InitApp(GetModuleHandle(nil), SW_SHOW) &lt;&gt; DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; while GetMessage(aMSG, 0, 0, 0) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; TranslateMessage(aMSG);<br>&nbsp; &nbsp; &nbsp; DispatchMessage(aMSG);<br>&nbsp; &nbsp; end;<br><br>end.<br>
 
上面是一个基本的DirectDraw程序,也很简单吧
 
简单,简单,很简单......<br>从上头到下头,我用鼠标拖滑块,只拖了1分半。
 
结贴要紧
 
后退
顶部