http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3456|回复: 2

[其他] 想实现 程序嵌入桌面,不受最小化影响

[复制链接]
发表于 2013-3-31 22:12:17 | 显示全部楼层 |阅读模式
本帖最后由 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);  

        }
    }
}



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-3-31 22:26:49 | 显示全部楼层
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);  


        }
    }
}
发表于 2013-4-1 10:27:18 | 显示全部楼层
这种效果我还真没写过,先帮你顶一下帖子,楼主先Baidu下,有时间了研究研究
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-3 16:27

© 2014-2021

快速回复 返回顶部 返回列表