My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// E-Book Copier
// Copyright (C) 2009 Chuan-Gen Fan
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Project: http://code.google.com/p/ebookcopier/
// Contact Author:
// website: http://chuangen.name/
// e-mail/msn: chuangen@live.cn

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;
using System.Drawing.Imaging;

namespace EbookCopier
{
/// <summary>
/// <para>透明窗体。你可以通过SetBitmap设置要显示的图像。</para>
/// <para>
/// 在将要设置的快捷菜单中,如果包含一项(可以是子菜单)Text 为 ReplaceMenuText,
/// 则该项将被默认的工具菜单代替。否则,将添加到菜单的末尾。
/// </para>
/// </summary>
internal partial class AlphaForm : Ref.PerPixelAlphaForm
{
/// <summary>
/// 初始化类 <see cref="AlphaForm"/> 的新实例。
/// </summary>
public AlphaForm()
:base()
{
this.TopMost = true;
this.ShowInTaskbar = false;
}


#region 鼠标穿透

private const uint WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int LWA_ALPHA = 0x2;

[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);

[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);

[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, int bAlpha, int dwFlags);


private bool clickThroughEnable = false;
/// <summary>
/// 获取或设置一个值,指示窗体是否有鼠标穿透功能。
/// </summary>
/// <value>如果该实例can penetrate,为<c>true</c>;否则为<c>false</c>。</value>
public bool ClickThroughEnable
{
get { return clickThroughEnable; }
set
{
clickThroughEnable = value;

if (clickThroughEnable)
{//使窗口有鼠标穿透功能
uint intExTemp = GetWindowLong(this.Handle, GWL_EXSTYLE);
uint oldGWLEx = SetWindowLong(this.Handle, GWL_EXSTYLE, intExTemp | WS_EX_TRANSPARENT | WS_EX_LAYERED);
}
else
{//使窗体恢复正常
this.FormBorderStyle = FormBorderStyle.None;
}
}
}
#endregion

/// <summary>
/// 使窗口具有 WS_EX_LAYERED 扩展样式。
/// CreateParams.ExStyle |= 0x00080000; // This form has to have the WS_EX_LAYERED extended style
/// </summary>
public static void SetAlphaStyle(Form form, bool isAlpha)
{
if (isAlpha)
{
uint intExTemp = GetWindowLong(form.Handle, GWL_EXSTYLE);
uint oldGWLEx = SetWindowLong(form.Handle, GWL_EXSTYLE, intExTemp | WS_EX_LAYERED);
//SetLayeredWindowAttributes(form.Handle, 0, 100, LWA_ALPHA);
}
else
{//使窗体恢复正常
form.FormBorderStyle = FormBorderStyle.None;
}
}
}
}

Change log

r2 by chuangen on Mar 11, 2009   Diff
ebookcopier v1.0.3357.8997

为准备将项目开源,我做了些修改,主要包括:
1. 代码书写规范;
2. 补充必要的注释;
3. 审查版权问题,对引用的别人代码做了版权说明。
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 4331 bytes, 115 lines
Powered by Google Project Hosting