Unity 實現無邊框視窗,四邊陰影。

2021-09-19 13:51:20 字數 3673 閱讀 2769

1、整合win函式,定義介面

using unityengine;

using system.runtime.interopservices;

using system;

//設定當前視窗的顯示狀態

[dllimport("user32.dll")]

public static extern bool showwindow(system.intptr hwnd, int ncmdshow);

//獲取當前啟用視窗

[dllimport("user32.dll", entrypoint = "getforegroundwindow")]

public static extern system.intptr getforegroundwindow();

//設定視窗邊框

[dllimport("user32.dll")]

public static extern intptr setwindowlong(intptr hwnd, int _nindex, int dwnewlong);

//設定視窗位置,大小

[dllimport("user32.dll")]

public static extern bool setwindowpos(intptr hwnd, int hwndafter, int x, int y, int cx, int cy, uint uflags);

public const int cs_dropshadow = 0x20000;

public const int spi_setdropshadow = 0x1025;

public const int gcl_style = -26;

[dllimport("user32.dll", charset = charset.auto)]

public static extern int setclasslong(intptr hwnd, int nindex, int dwnewlong);

[dllimport("user32.dll", charset = charset.auto)]

public static extern int getclasslong(intptr hwnd, int nindex);

[dllimport("user32.dll", charset = charset.auto)]

public static extern int systemparametersinfo(int uaction, int uparam, bool lpvparam, int fuwinini);

[dllimport("gdi32.dll", entrypoint = "createroundrectrgn")]

private static extern intptr createroundrectrgn

( int nleftrect, // x-coordinate of upper-left corner

int ntoprect, // y-coordinate of upper-left corner

int nrightrect, // x-coordinate of lower-right corner

int nbottomrect, // y-coordinate of lower-right corner

int nwidthellipse, // height of ellipse

int nheightellipse // width of ellipse

);[dllimport("dwmapi.dll")]

public static extern int dwmextendframeintoclientarea(intptr hwnd, ref margins pmarinset);

[dllimport("dwmapi.dll")]

public static extern int dwmsetwindowattribute(intptr hwnd, int attr, ref int attrvalue, int attrsize);

[dllimport("dwmapi.dll")]

public static extern int dwmiscompositionenabled(ref int pfenabled);

private bool m_aeroenabled; // variables for box shadow

public struct margins // struct for box shadow

2、設定視窗無邊框
intptr hwnd = getforegroundwindow() ;

//計算視窗顯示位置

float windowwidth = 1024;

float windowheight = 768;

float posx = (screen.currentresolution.width - windowwidth) / 2;

float posy = (screen.currentresolution.height - windowheight) / 2;

rect rect = new rect(posx, posy, windowwidth, windowheight);

//設定視窗樣式

long wndstyle = 0;

wndstyle |= windowsmessage.ws_popup;

wndstyle &= ~windowsmessage.ws_caption;

setwindowlong(hwnd , gwl_style, ws_popup);

setwindowpos(hwnd , 0, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height, swp_showwindow);

3、呼叫系統函式,設定視窗陰影(只能設定右下陰影)
windowstools.systemparametersinfo(windowstools.spi_setdropshadow, 0, true, 0); // - 開啟陰影效果

windowstools.setclasslong(hwnd , windowstools.gcl_style,

windowstools.getclasslong(hwnd , windowstools.gcl_style) | windowstools.cs_dropshadow);

4、判斷window是否是處於aero模式
private bool checkaeroenabled()

return false;

}

5、繼承win訊息,新增四邊陰影
_aeroenabled = checkaeroenabled();

protected override void wndproc(ref message m)

; dwmextendframeintoclientarea(this.handle, ref margins);

}break;

default:

break;

}base.wndproc(ref m);

}

邊框css四邊怎麼加

css設定邊框四邊的方法 1 使用border bottom屬性設定下邊框 2 使用border left屬性設定左邊框 3 使用border right屬性設定右邊框 4 使用border top屬性設定上邊框。本教程操作環境 windows7系統 css3版本,dell g3電腦。相關推薦 cs...

Qt實現 可移動的無邊框視窗

日常開發中,因為需要自定義標題欄來實現更好的效果,所以經常需要隱藏視窗自帶的標題欄。在qt中,通過setwindowflags qt framelesswindowhint 函式對當前視窗設定無邊框,但是這樣存在乙個問題,就是視窗無法被滑鼠拖動了,所以這時候就需要重寫一下事件,來實現視窗的移動。先看...

c 無邊框視窗的入門級拖動實現

實現了視窗的移動,下一步研究通過選單拖動視窗 視窗無任何控制項 以下為form1.cs中的全部 多出的部分為新增部分 自行尋找 using system using system.collections.generic using system.componentmodel using system...