|
本帖最后由 mbccie 于 2013-3-31 22:28 编辑
我想做一个便签软件,程序嵌入到桌面中,不受最小化所有程序和显示桌面、win+d快捷键的影响。
vb6代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Form_Load()
'SetParent FindWindow("progman", vbNullString), Me.hWnd '嵌入桌面
SetParent Me.hWnd, FindWindow(vbNullString, "Program Manager") '钉在桌面
End Sub
但是vb.net执行就没有这个效果了 。
vb.net
'窗体钉在桌面
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As Long) As Long
Declare Function BringWindowToTop Lib "user32" Alias "BringWindowToTop" (ByVal hwnd As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Sub PinToDesktop(ByVal FormToPin As System.Windows.Forms.Form)
Dim progman As Long
progman = FindWindow("progman", vbNullString)
SetParent(FormToPin.Handle.ToInt64, progman)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'钉在桌面
BringWindowToTop(Me.Handle.ToInt64)
Call PinToDesktop(Me)
End Sub
我是学vb6\vb.net的 c#稍微懂点 http://www.jbxue.com/article/6666.html 以上是从这里找的一些代码转换来的。感谢各位朋友的指导~
我找到了一段c#代码 不过调试中可以打动效果,去debug中执行exe就没用了。
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 qianruzhuomian
{
public partial class Form1 : Form
{
[DllImport("user32")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hDeskTop = FindWindow("Progman", "Program Manager");
SetParent(this.Handle, hDeskTop);
'
SetParent(this.Handle,FindWindow("Progman", "Program Manager"));
Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);
}
}
}
|
|