最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c# winform窗口一直置頂顯示在桌面最上方或最底層的方法

 更新時(shí)間:2013年01月25日 14:24:38   投稿:whsnow  
winform窗口一直置頂顯示在桌面最上方,這樣的功能真的很實(shí)用的,很多的軟件窗口都有這樣的功能,本文也來(lái)實(shí)現(xiàn)一個(gè),感興趣的你千萬(wàn)不要錯(cuò)過(guò)了,希望本文對(duì)你有所幫助

一、

在最前面:
using System.Runtime.InteropServices;
在定義部分引入下面兩個(gè)函數(shù):
[DllImport( "user32 ")]
private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport( "user32 ")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
在窗體On_Load事件中添加(Santos的代碼):
IntPtr hDeskTop=FindWindow( "Progman ", "Program Manager ");
SetParent(this.Handle,hDeskTop);
另一個(gè)方法可以修改桌面壁紙實(shí)現(xiàn)
經(jīng)測(cè)試,win2000--win2003 、xp下嵌入桌面,不支持vista和win7以上系統(tǒng)

二、

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 
namespace ShowInDesk 
{ 
publicpartialclass Form1 : Form 
{ 
IntPtr hDesktop; 
publicconstint GW_CHILD =5; 
public Form1() 
{ 
InitializeComponent(); 
this.hDesktop = GetDesktopHandle(DesktopLayer.Progman); 
EmbedDesktop(this, this.Handle, this.hDesktop); 
isMouseDown =false; 
} 
public IntPtr GetDesktopHandle(DesktopLayer layer) { //hWnd = new HandleRef(); 
HandleRef hWnd; 
IntPtr hDesktop =new IntPtr(); 
switch (layer) 
{ 
case DesktopLayer.Progman: 
hDesktop = Win32Support.FindWindow("Progman", null);//第一層桌面 
break; 
case DesktopLayer.SHELLDLL: 
hDesktop = Win32Support.FindWindow("Progman", null);//第一層桌面 
hWnd =new HandleRef(this, hDesktop); 
hDesktop = Win32Support.GetWindow(hWnd, GW_CHILD);//第2層桌面 
break; 
case DesktopLayer.FolderView: 
hDesktop = Win32Support.FindWindow("Progman", null);//第一層桌面 
hWnd =new HandleRef(this, hDesktop); 
hDesktop = Win32Support.GetWindow(hWnd, GW_CHILD);//第2層桌面 
hWnd =new HandleRef(this, hDesktop); 
hDesktop = Win32Support.GetWindow(hWnd, GW_CHILD);//第3層桌面 
break; 
} 
return hDesktop; 
} 
publicvoid EmbedDesktop(Object embeddedWindow, IntPtr childWindow, IntPtr parentWindow) 
{ 
Form window = (Form)embeddedWindow; 
HandleRef HWND_BOTTOM =new HandleRef(embeddedWindow, new IntPtr(1)); 
constint SWP_FRAMECHANGED =0x0020;//發(fā)送窗口大小改變消息 
Win32Support.SetParent(childWindow, parentWindow); 
Win32Support.SetWindowPos(new HandleRef(window, childWindow), HWND_BOTTOM, 300, 300, window.Width, window.Height, SWP_FRAMECHANGED); 
} 
} 
} 

2、

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Runtime.InteropServices; 
namespace ShowInDesk 
{ 
class Win32Support 
{ 
[DllImport("user32.dll", CharSet = CharSet.Auto)] 
publicstaticextern IntPtr FindWindow(string className, string windowName); 
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling =true)] 
publicstaticextern IntPtr GetWindow(HandleRef hWnd, int nCmd); 
[DllImport("user32.dll")] 
publicstaticextern IntPtr SetParent(IntPtr child, IntPtr parent); 
[DllImport("user32.dll", EntryPoint ="GetDCEx", CharSet = CharSet.Auto, ExactSpelling =true)] 
publicstaticextern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags); 
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling =true)] 
publicstaticexternbool SetWindowPos(HandleRef hWnd, HandleRef hWndInsertAfter, int x, int y, int cx, int cy, int flags); 
[DllImport("user32.dll")] 
publicstaticexternint ReleaseDC(IntPtr window, IntPtr handle); 
} 
} 

3、

namespace ShowInDesk 
{ 
publicenum DesktopLayer 
{ 
Progman =0, 
SHELLDLL =1, 
FolderView =2 
} 
} 

三、
入桌面窗口最底層,并提供詳細(xì)的實(shí)現(xiàn)代碼供參考。
此類將窗體永遠(yuǎn)置于窗口最底層。
首先, 調(diào)用一些User32.dll的WinAPI函數(shù)。

internal class User32 
{ 
public const int SE_SHUTDOWN_PRIVILEGE =0x13; 
[DllImport("user32.dll")] 
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 
[DllImport("user32.dll")] 
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 
[DllImport("user32.dll")] 
public static externbool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, 
int cy, uint uFlags); 
} 

然后, 在WinForm里面:

public MainForm()
{
InitializeComponent();
try
{
if (Environment.OSVersion.Version.Major <6)
{
base.SendToBack();
IntPtr hWndNewParent = User32.FindWindow("Progman", null);
User32.SetParent(base.Handle, hWndNewParent);
}
else
{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
catch (ApplicationException exx)
{
MessageBox.Show(this, exx.Message, "Pin to Desktop");
}
}
private void MainForm_Activated(object sender, EventArgs e)
{
if (Environment.OSVersion.Version.Major >=6)
{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
if (Environment.OSVersion.Version.Major >=6)
{
User32.SetWindowPos(base.Handle, 1, 0, 0, 0, 0, User32.SE_SHUTDOWN_PRIVILEGE);
}
}


以上介紹的就是C#如何讓W(xué)inForm嵌入桌面窗口最底層,希望對(duì)你有所幫助。

相關(guān)文章

  • C#實(shí)現(xiàn)打印與打印預(yù)覽功能的思路及代碼

    C#實(shí)現(xiàn)打印與打印預(yù)覽功能的思路及代碼

    這篇文章主要介紹了C#實(shí)現(xiàn)打印與打印預(yù)覽功能的思路及代碼,有需要的朋友可以參考一下
    2013-12-12
  • 深入分析C# 線程同步

    深入分析C# 線程同步

    這篇文章主要介紹了C# 線程同步的的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • c# openxml 刪除xlsx、xls的外鏈?zhǔn)纠a

    c# openxml 刪除xlsx、xls的外鏈?zhǔn)纠a

    要?jiǎng)h除一個(gè) Excel 文件(.xlsx)中的外部鏈接(external links),你可以使用 OpenXML SDK,本文演示如何使用 OpenXML SDK 刪除外部鏈接,感興趣的朋友一起看看吧
    2024-01-01
  • C#實(shí)現(xiàn)將一個(gè)矩陣分解為對(duì)稱矩陣與反稱矩陣之和的方法

    C#實(shí)現(xiàn)將一個(gè)矩陣分解為對(duì)稱矩陣與反稱矩陣之和的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)將一個(gè)矩陣分解為對(duì)稱矩陣與反稱矩陣之和的方法,較為詳細(xì)的分析了矩陣分解運(yùn)算的原理與C#實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2015-08-08
  • C# Fiddler插件實(shí)現(xiàn)網(wǎng)站離線瀏覽功能

    C# Fiddler插件實(shí)現(xiàn)網(wǎng)站離線瀏覽功能

    本文主要介紹了C# Fiddler插件實(shí)現(xiàn)網(wǎng)站離線瀏覽功能的原理與方法。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • C# goto語(yǔ)句的具體使用

    C# goto語(yǔ)句的具體使用

    # goto 語(yǔ)句用于直接在一個(gè)程序中轉(zhuǎn)到程序中的標(biāo)簽指定的位置,標(biāo)簽實(shí)際上由標(biāo)識(shí)符加上冒號(hào)構(gòu)成。本文主要介紹了C# goto語(yǔ)句的具體使用,感興趣的可以了解一下
    2021-06-06
  • C# [ImportDll()] 知識(shí)小結(jié)

    C# [ImportDll()] 知識(shí)小結(jié)

    今天小編就為大家分享一篇關(guān)于C# [ImportDll()] 知識(shí)小結(jié),小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-01-01
  • 詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式

    詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式

    本篇文章主要介紹了詳解三種C#實(shí)現(xiàn)數(shù)組反轉(zhuǎn)方式,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-04-04
  • 如何用C#驗(yàn)證IP是否為局域網(wǎng)地址

    如何用C#驗(yàn)證IP是否為局域網(wǎng)地址

    這篇文章主要介紹了如何用C#驗(yàn)證IP是否為局域網(wǎng)地址,文中講解非常細(xì)致,代碼幫助大家更好的參考和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • C#如何添加PPT背景

    C#如何添加PPT背景

    這篇文章主要為大家詳細(xì)介紹了C#如何添加PPT背景,添加純色背景、漸變色背景、圖片背景等,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-07-07

最新評(píng)論

玛曲县| 桐乡市| 洪雅县| 临洮县| 资中县| 南澳县| 贞丰县| 延长县| 比如县| 新营市| 达拉特旗| 尉氏县| 米脂县| 瓮安县| 扶绥县| 池州市| 丽江市| 肇东市| 肥乡县| 江山市| 宕昌县| 理塘县| 昂仁县| 泗阳县| 宁城县| 建昌县| 彝良县| 色达县| 江安县| 新晃| 蕲春县| 西安市| 桃江县| 西充县| 宜昌市| 彰化县| 旬邑县| 桑植县| 泉州市| 寿光市| 廉江市|