27-09-2007, 10:32
|
|
|
|
חבר מתאריך: 09.04.02
הודעות: 8,000
|
|
איך אפשר ליצור חלון שקוף?
קודם כל, נצטרך לייבא פונקציה בשם SetLayeredWindowAttribute מהקובץ user32.dll.
לאחר מכן נוסיף לחלון שלנו את הדגל WS_EX_LAYERED בעזרת הפונקציה SetWindowLong,
ואז פשוט נשתמש בפונקציה שייבאנו בשלב הראשון
קוד:
typedef BOOL (WINAPI * SLWA)(HWND, COLORREF, BYTE, DWORD); // Put this line in the global scope, i.e. above the main() function
SLWA SetLayeredWindowAttributes = 0;
SetLayeredWindowAttributes = (SLWA) GetProcAddress(GetModuleHandle("USER32.DLL"), "SetLayeredWindowAttributes");
if (SetLayeredWindowAttributes == 0)
{
MessageBox(Window, "Couldn't find the 'SetLayeredWindowAttributes' entry point in user32.dll", "Error", MB_OK);
return FALSE;
}
DWORD WindowStyle = GetWindowLong(WindowHandle, GWL_EXSTYLE);
WindowStyle = WindowStyle | WS_EX_LAYERED;
SetWindowLong(WindowHandle, GWL_EXSTYLE, WindowStyle);
SetLayeredWindowAttributes(Window, 0, (255 * OPACITY_PERCENTAGE) / 100, 2);
שימו לב - OPACITY_PERCENTAGE צריך להיות מספר שלם בין 0 ל-100.
בהצלחה
|