API函数问题!(50分)

  • 主题发起人 主题发起人 quharry
  • 开始时间 开始时间
Q

quharry

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位大哥知道这个API函数(SetLayeredWindowAttributes)的声明原形,请告知!谢谢!
 
大哥,难道没人懂吗???<br>这是一个使窗体透明的API函数啊,但是我不知道它的声明原形啊!<br>如果分太少了我加分就是了!
 
查MSDN:<br>SetLayeredWindowAttributes<br>The SetLayeredWindowAttributes function sets the opacity and transparency color key of a layered window.<br><br>BOOL SetLayeredWindowAttributes(<br>&nbsp; HWND hwnd, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle to the layered window<br>&nbsp; COLORREF crKey, &nbsp; &nbsp; &nbsp;// specifies the color key<br>&nbsp; BYTE bAlpha, &nbsp; &nbsp; &nbsp; &nbsp; // value for the blend function<br>&nbsp; DWORD dwFlags &nbsp; &nbsp; &nbsp; &nbsp;// action<br>);<br>Parameters<br>hwnd <br>[in] Handle to the layered window. A layered window is created by specifying WS_EX_LAYERED when creating the window with the CreateWindowEx function or by setting WS_EX_LAYERED via SetWindowLong after the window has been created. <br>crKey <br>[in] Pointer to a COLORREF value that specifies the transparency color key to be used when composing the layered window. All pixels painted by the window in this color will be transparent. To generate a COLORREF, use the RGB macro. <br>bAlpha <br>[in] Alpha value used to describe the opacity of the layered window. Similar to the SourceConstantAlpha member of the BLENDFUNCTION structure. When bAlpha is 0, the window is completely transparent. When bAlpha is 255, the window is opaque. <br>dwFlags <br>[in] Specifies an action to take. This parameter can be one or more of the following values. Value Meaning <br>LWA_COLORKEY Use crKey as the transparency color. &nbsp;<br>LWA_ALPHA Use bAlpha to determine the opacity of the layered window.. <br><br>Return Values<br>If the function succeeds, the return value is nonzero.<br><br>If the function fails, the return value is zero. To get extended error information, call GetLastError.
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=618925<br>如何在不没有升级的 DELPHI 5 中用SetLayeredWindowAttributes(); <br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=1687505<br>半透明窗体问题已经解决,但是怎么解释这些代码?求教!
 
我把它包装了一下:<br>//---------------------------------------------------------------------------<br>// Translucency form<br>bool __fastcall SetLayeredWindowAttributesEx(HWND hWnd, unsigned crKey, Byte bAlpha,unsigned dwFlags)<br>{<br>&nbsp; HINSTANCE DLLHandle;<br>&nbsp; LONG gwlStyle;<br>&nbsp; FSetLayeredWindowAttributes proc;<br><br>&nbsp; bool Result = false;<br>&nbsp; DLLHandle = LoadLibrary("user32.dll");<br>&nbsp; if( DLLHandle != NULL )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; proc = (FSetLayeredWindowAttributes)GetProcAddress(DLLHandle,"SetLayeredWindowAttributes");<br>&nbsp; &nbsp; if( proc != NULL )<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; gwlStyle = GetWindowLong(hWnd,GWL_EXSTYLE);<br>&nbsp; &nbsp; &nbsp; gwlStyle = gwlStyle | WS_EX_LAYERED;<br>&nbsp; &nbsp; &nbsp; SetWindowLong(hWnd,GWL_EXSTYLE,gwlStyle);<br>&nbsp; &nbsp; &nbsp; Result = proc(hWnd,crKey,bAlpha,dwFlags);<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; FreeLibrary( DLLHandle );<br>&nbsp; &nbsp; }<br>&nbsp; return Result;<br>}<br><br>//使用:窗体关闭时逐渐透明化<br>//---------------------------------------------------------------------------<br>const int iAlphaBlend = 210;<br>//---------------------------------------------------------------------------<br>void __fastcall TSplashForm::FormClose(TObject *Sender,<br>&nbsp; &nbsp; &nbsp; TCloseAction &amp;Action)<br>{<br>&nbsp; Action = caFree;<br><br>&nbsp; for( int i = iAlphaBlend; i &gt; 10; i -= 40 )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; if( SetLayeredWindowAttributesEx(Handle,0,i,LWA_ALPHA) == false )<br>&nbsp; &nbsp; &nbsp; break;<br><br>&nbsp; &nbsp; Application-&gt;ProcessMessages();<br><br>&nbsp; &nbsp; SleepEx( 10, false );<br>&nbsp; &nbsp; }<br>}
 
接受答案了.
 
后退
顶部