Ran JetBrains rider and edited slightly to allow HID to be used on linux
This commit is contained in:
parent
a21a89f051
commit
2d636f50b7
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/.idea.CC-Functions/.idea/workspace.xml
|
4
.idea/.idea.CC-Functions/.idea/encodings.xml
Normal file
4
.idea/.idea.CC-Functions/.idea/encodings.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
8
.idea/.idea.CC-Functions/.idea/indexLayout.xml
Normal file
8
.idea/.idea.CC-Functions/.idea/indexLayout.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ContentModelUserStore">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
19
.idea/.idea.CC-Functions/.idea/markdown-navigator-enh.xml
Normal file
19
.idea/.idea.CC-Functions/.idea/markdown-navigator-enh.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MarkdownNavigatorHistory">
|
||||||
|
<PasteImageHistory checkeredTransparentBackground="false" filename="image" directory="" onPasteImageTargetRef="3" onPasteLinkText="0" onPasteImageElement="1" onPasteLinkElement="1" onPasteReferenceElement="2" cornerRadius="20" borderColor="0" transparentColor="16777215" borderWidth="1" trimTop="0" trimBottom="0" trimLeft="0" trimRight="0" transparent="false" roundCorners="false" showPreview="true" bordered="false" scaled="false" cropped="false" hideInapplicableOperations="false" preserveLinkFormat="false" scale="50" scalingInterpolation="1" transparentTolerance="0" saveAsDefaultOnOK="false" linkFormat="0" addHighlights="false" showHighlightCoordinates="true" showHighlights="false" mouseSelectionAddsHighlight="false" outerFilled="false" outerFillColor="0" outerFillTransparent="true" outerFillAlpha="30">
|
||||||
|
<highlightList />
|
||||||
|
<directories />
|
||||||
|
<filenames />
|
||||||
|
</PasteImageHistory>
|
||||||
|
<CopyImageHistory checkeredTransparentBackground="false" filename="image" directory="" onPasteImageTargetRef="3" onPasteLinkText="0" onPasteImageElement="1" onPasteLinkElement="1" onPasteReferenceElement="2" cornerRadius="20" borderColor="0" transparentColor="16777215" borderWidth="1" trimTop="0" trimBottom="0" trimLeft="0" trimRight="0" transparent="false" roundCorners="false" showPreview="true" bordered="false" scaled="false" cropped="false" hideInapplicableOperations="false" preserveLinkFormat="false" scale="50" scalingInterpolation="1" transparentTolerance="0" saveAsDefaultOnOK="false" linkFormat="0" addHighlights="false" showHighlightCoordinates="true" showHighlights="false" mouseSelectionAddsHighlight="false" outerFilled="false" outerFillColor="0" outerFillTransparent="true" outerFillAlpha="30">
|
||||||
|
<highlightList />
|
||||||
|
<directories />
|
||||||
|
<filenames />
|
||||||
|
</CopyImageHistory>
|
||||||
|
<PasteLinkHistory onPasteImageTargetRef="3" onPasteTargetRef="1" onPasteLinkText="0" onPasteImageElement="1" onPasteLinkElement="1" onPasteWikiElement="2" onPasteReferenceElement="2" hideInapplicableOperations="false" preserveLinkFormat="false" useHeadingForLinkText="false" linkFormat="0" saveAsDefaultOnOK="false" />
|
||||||
|
<TableToJsonHistory>
|
||||||
|
<entries />
|
||||||
|
</TableToJsonHistory>
|
||||||
|
</component>
|
||||||
|
</project>
|
96
.idea/.idea.CC-Functions/.idea/markdown-navigator.xml
Normal file
96
.idea/.idea.CC-Functions/.idea/markdown-navigator.xml
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="FlexmarkProjectSettings">
|
||||||
|
<FlexmarkHtmlSettings flexmarkSpecExampleRendering="0" flexmarkSpecExampleRenderHtml="false">
|
||||||
|
<flexmarkSectionLanguages>
|
||||||
|
<option name="1" value="Markdown" />
|
||||||
|
<option name="2" value="HTML" />
|
||||||
|
<option name="3" value="flexmark-ast:1" />
|
||||||
|
</flexmarkSectionLanguages>
|
||||||
|
</FlexmarkHtmlSettings>
|
||||||
|
</component>
|
||||||
|
<component name="MarkdownProjectSettings">
|
||||||
|
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" synchronizePreviewPosition="true" highlightPreviewType="LINE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="true" showSelectionInPreview="true" lastLayoutSetsDefault="false">
|
||||||
|
<PanelProvider>
|
||||||
|
<provider providerId="com.vladsch.idea.multimarkdown.editor.swing.html.panel" providerName="Default - Swing" />
|
||||||
|
</PanelProvider>
|
||||||
|
</PreviewSettings>
|
||||||
|
<ParserSettings gitHubSyntaxChange="false" emojiShortcuts="0" emojiImages="0">
|
||||||
|
<PegdownExtensions>
|
||||||
|
<option name="ABBREVIATIONS" value="false" />
|
||||||
|
<option name="ANCHORLINKS" value="false" />
|
||||||
|
<option name="ASIDE" value="false" />
|
||||||
|
<option name="ATXHEADERSPACE" value="false" />
|
||||||
|
<option name="AUTOLINKS" value="false" />
|
||||||
|
<option name="DEFINITIONS" value="false" />
|
||||||
|
<option name="DEFINITION_BREAK_DOUBLE_BLANK_LINE" value="false" />
|
||||||
|
<option name="EXTANCHORLINKS" value="false" />
|
||||||
|
<option name="EXTANCHORLINKS_WRAP" value="false" />
|
||||||
|
<option name="FENCED_CODE_BLOCKS" value="false" />
|
||||||
|
<option name="FOOTNOTES" value="false" />
|
||||||
|
<option name="HARDWRAPS" value="false" />
|
||||||
|
<option name="HTML_DEEP_PARSER" value="false" />
|
||||||
|
<option name="INSERTED" value="false" />
|
||||||
|
<option name="INTELLIJ_DUMMY_IDENTIFIER" value="false" />
|
||||||
|
<option name="MULTI_LINE_IMAGE_URLS" value="false" />
|
||||||
|
<option name="QUOTES" value="false" />
|
||||||
|
<option name="RELAXEDHRULES" value="false" />
|
||||||
|
<option name="SMARTS" value="false" />
|
||||||
|
<option name="STRIKETHROUGH" value="false" />
|
||||||
|
<option name="SUBSCRIPT" value="false" />
|
||||||
|
<option name="SUPERSCRIPT" value="false" />
|
||||||
|
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
|
||||||
|
<option name="SUPPRESS_INLINE_HTML" value="false" />
|
||||||
|
<option name="TABLES" value="false" />
|
||||||
|
<option name="TASKLISTITEMS" value="false" />
|
||||||
|
<option name="TOC" value="false" />
|
||||||
|
<option name="WIKILINKS" value="false" />
|
||||||
|
</PegdownExtensions>
|
||||||
|
<ParserOptions>
|
||||||
|
<option name="ADMONITION_EXT" value="false" />
|
||||||
|
<option name="ATTRIBUTES_EXT" value="false" />
|
||||||
|
<option name="COMMONMARK_LISTS" value="false" />
|
||||||
|
<option name="DUMMY" value="false" />
|
||||||
|
<option name="EMOJI_SHORTCUTS" value="false" />
|
||||||
|
<option name="ENUMERATED_REFERENCES_EXT" value="false" />
|
||||||
|
<option name="FLEXMARK_FRONT_MATTER" value="false" />
|
||||||
|
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
|
||||||
|
<option name="GFM_TABLE_RENDERING" value="false" />
|
||||||
|
<option name="GITBOOK_URL_ENCODING" value="false" />
|
||||||
|
<option name="GITHUB_LISTS" value="false" />
|
||||||
|
<option name="GITHUB_WIKI_LINKS" value="false" />
|
||||||
|
<option name="GITLAB_EXT" value="false" />
|
||||||
|
<option name="GITLAB_MATH_EXT" value="false" />
|
||||||
|
<option name="GITLAB_MERMAID_EXT" value="false" />
|
||||||
|
<option name="HEADER_ID_NON_ASCII_TO_LOWERCASE" value="false" />
|
||||||
|
<option name="HEADER_ID_NO_DUPED_DASHES" value="false" />
|
||||||
|
<option name="JEKYLL_FRONT_MATTER" value="false" />
|
||||||
|
<option name="MACROS_EXT" value="false" />
|
||||||
|
<option name="NO_TEXT_ATTRIBUTES" value="false" />
|
||||||
|
<option name="PARSE_HTML_ANCHOR_ID" value="false" />
|
||||||
|
<option name="PLANTUML_FENCED_CODE" value="false" />
|
||||||
|
<option name="PRODUCTION_SPEC_PARSER" value="false" />
|
||||||
|
<option name="PUML_FENCED_CODE" value="false" />
|
||||||
|
<option name="SIM_TOC_BLANK_LINE_SPACER" value="false" />
|
||||||
|
<option name="SPACE_IN_LINK_URLS" value="false" />
|
||||||
|
</ParserOptions>
|
||||||
|
</ParserSettings>
|
||||||
|
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" addPageHeader="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" plantUmlConversion="0">
|
||||||
|
<GeneratorProvider>
|
||||||
|
<provider providerId="com.vladsch.idea.multimarkdown.editor.text.html.generator" providerName="Unmodified HTML Generator" />
|
||||||
|
</GeneratorProvider>
|
||||||
|
<headerTop />
|
||||||
|
<headerBottom />
|
||||||
|
<bodyTop />
|
||||||
|
<bodyBottom />
|
||||||
|
</HtmlSettings>
|
||||||
|
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
|
||||||
|
<StylesheetProvider>
|
||||||
|
<provider providerId="com.vladsch.idea.multimarkdown.editor.text.html.css" providerName="No Stylesheet" />
|
||||||
|
</StylesheetProvider>
|
||||||
|
<ScriptProviders />
|
||||||
|
<cssText />
|
||||||
|
<cssUriHistory />
|
||||||
|
</CssSettings>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RiderProjectSettingsUpdater">
|
||||||
|
<option name="vcsConfiguration" value="1" />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/.idea.CC-Functions/.idea/vcs.xml
Normal file
6
.idea/.idea.CC-Functions/.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -7,81 +7,74 @@ using System.Windows.Forms;
|
|||||||
namespace GradeCalc
|
namespace GradeCalc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Custom column type dedicated to the DataGridViewNumericUpDownCell cell type.
|
/// Custom column type dedicated to the DataGridViewNumericUpDownCell cell type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataGridViewNumericUpDownColumn : DataGridViewColumn
|
public class DataGridViewNumericUpDownColumn : DataGridViewColumn
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for the DataGridViewNumericUpDownColumn class.
|
/// Constructor for the DataGridViewNumericUpDownColumn class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DataGridViewNumericUpDownColumn() : base(new DataGridViewNumericUpDownCell())
|
public DataGridViewNumericUpDownColumn() : base(new DataGridViewNumericUpDownCell())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the implicit cell that gets cloned when adding rows to the grid.
|
/// Represents the implicit cell that gets cloned when adding rows to the grid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[
|
[Browsable(false)]
|
||||||
Browsable(false),
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
||||||
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
|
|
||||||
]
|
|
||||||
public override DataGridViewCell CellTemplate
|
public override DataGridViewCell CellTemplate
|
||||||
{
|
{
|
||||||
get {
|
get => base.CellTemplate;
|
||||||
return base.CellTemplate;
|
set
|
||||||
}
|
{
|
||||||
set {
|
var dataGridViewNumericUpDownCell = value as DataGridViewNumericUpDownCell;
|
||||||
DataGridViewNumericUpDownCell dataGridViewNumericUpDownCell = value as DataGridViewNumericUpDownCell;
|
|
||||||
if (value != null && dataGridViewNumericUpDownCell == null)
|
if (value != null && dataGridViewNumericUpDownCell == null)
|
||||||
{
|
throw new InvalidCastException(
|
||||||
throw new InvalidCastException("Value provided for CellTemplate must be of type DataGridViewNumericUpDownElements.DataGridViewNumericUpDownCell or derive from it.");
|
"Value provided for CellTemplate must be of type DataGridViewNumericUpDownElements.DataGridViewNumericUpDownCell or derive from it.");
|
||||||
}
|
|
||||||
base.CellTemplate = value;
|
base.CellTemplate = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replicates the DecimalPlaces property of the DataGridViewNumericUpDownCell cell type.
|
/// Replicates the DecimalPlaces property of the DataGridViewNumericUpDownCell cell type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[
|
[Category("Appearance")]
|
||||||
Category("Appearance"),
|
[DefaultValue(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultDecimalPlaces)]
|
||||||
DefaultValue(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultDecimalPlaces),
|
[Description("Indicates the number of decimal places to display.")]
|
||||||
Description("Indicates the number of decimal places to display.")
|
|
||||||
]
|
|
||||||
public int DecimalPlaces
|
public int DecimalPlaces
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
if (NumericUpDownCellTemplate == null)
|
if (NumericUpDownCellTemplate == null)
|
||||||
{
|
throw new InvalidOperationException(
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
}
|
|
||||||
return NumericUpDownCellTemplate.DecimalPlaces;
|
return NumericUpDownCellTemplate.DecimalPlaces;
|
||||||
}
|
}
|
||||||
set {
|
set
|
||||||
|
{
|
||||||
if (NumericUpDownCellTemplate == null)
|
if (NumericUpDownCellTemplate == null)
|
||||||
{
|
throw new InvalidOperationException(
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
}
|
|
||||||
// Update the template cell so that subsequent cloned cells use the new value.
|
// Update the template cell so that subsequent cloned cells use the new value.
|
||||||
NumericUpDownCellTemplate.DecimalPlaces = value;
|
NumericUpDownCellTemplate.DecimalPlaces = value;
|
||||||
if (DataGridView != null)
|
if (DataGridView != null)
|
||||||
{
|
{
|
||||||
// Update all the existing DataGridViewNumericUpDownCell cells in the column accordingly.
|
// Update all the existing DataGridViewNumericUpDownCell cells in the column accordingly.
|
||||||
DataGridViewRowCollection dataGridViewRows = DataGridView.Rows;
|
var dataGridViewRows = DataGridView.Rows;
|
||||||
int rowCount = dataGridViewRows.Count;
|
var rowCount = dataGridViewRows.Count;
|
||||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
||||||
{
|
{
|
||||||
// Be careful not to unshare rows unnecessarily.
|
// Be careful not to unshare rows unnecessarily.
|
||||||
// This could have severe performance repercussions.
|
// This could have severe performance repercussions.
|
||||||
DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
var dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
||||||
DataGridViewNumericUpDownCell dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
var dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
||||||
if (dataGridViewCell != null)
|
if (dataGridViewCell != null)
|
||||||
{
|
|
||||||
// Call the internal SetDecimalPlaces method instead of the property to avoid invalidation
|
// Call the internal SetDecimalPlaces method instead of the property to avoid invalidation
|
||||||
// of each cell. The whole column is invalidated later in a single operation for better performance.
|
// of each cell. The whole column is invalidated later in a single operation for better performance.
|
||||||
dataGridViewCell.SetDecimalPlaces(rowIndex, value);
|
dataGridViewCell.SetDecimalPlaces(rowIndex, value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataGridView.InvalidateColumn(Index);
|
DataGridView.InvalidateColumn(Index);
|
||||||
// TODO: Call the grid's autosizing methods to autosize the column, rows, column headers / row headers as needed.
|
// TODO: Call the grid's autosizing methods to autosize the column, rows, column headers / row headers as needed.
|
||||||
}
|
}
|
||||||
@ -89,144 +82,176 @@ namespace GradeCalc
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replicates the Increment property of the DataGridViewNumericUpDownCell cell type.
|
/// Replicates the Increment property of the DataGridViewNumericUpDownCell cell type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[
|
[Category("Data")]
|
||||||
Category("Data"),
|
[Description("Indicates the amount to increment or decrement on each button click.")]
|
||||||
Description("Indicates the amount to increment or decrement on each button click.")
|
|
||||||
]
|
|
||||||
public decimal Increment
|
public decimal Increment
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
if (NumericUpDownCellTemplate == null)
|
if (NumericUpDownCellTemplate == null)
|
||||||
{
|
throw new InvalidOperationException(
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
}
|
|
||||||
return NumericUpDownCellTemplate.Increment;
|
return NumericUpDownCellTemplate.Increment;
|
||||||
}
|
}
|
||||||
set {
|
set
|
||||||
|
{
|
||||||
if (NumericUpDownCellTemplate == null)
|
if (NumericUpDownCellTemplate == null)
|
||||||
{
|
throw new InvalidOperationException(
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
}
|
|
||||||
NumericUpDownCellTemplate.Increment = value;
|
NumericUpDownCellTemplate.Increment = value;
|
||||||
if (DataGridView != null)
|
if (DataGridView != null)
|
||||||
{
|
{
|
||||||
DataGridViewRowCollection dataGridViewRows = DataGridView.Rows;
|
var dataGridViewRows = DataGridView.Rows;
|
||||||
int rowCount = dataGridViewRows.Count;
|
var rowCount = dataGridViewRows.Count;
|
||||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
||||||
{
|
{
|
||||||
DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
var dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
||||||
DataGridViewNumericUpDownCell dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
var dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
||||||
if (dataGridViewCell != null)
|
if (dataGridViewCell != null) dataGridViewCell.SetIncrement(rowIndex, value);
|
||||||
{
|
|
||||||
dataGridViewCell.SetIncrement(rowIndex, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replicates the Maximum property of the DataGridViewNumericUpDownCell cell type.
|
||||||
|
/// </summary>
|
||||||
|
[Category("Data")]
|
||||||
|
[Description("Indicates the maximum value for the numeric up-down cells.")]
|
||||||
|
[RefreshProperties(RefreshProperties.All)]
|
||||||
|
public decimal Maximum
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (NumericUpDownCellTemplate == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
|
return NumericUpDownCellTemplate.Maximum;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (NumericUpDownCellTemplate == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
|
NumericUpDownCellTemplate.Maximum = value;
|
||||||
|
if (DataGridView != null)
|
||||||
|
{
|
||||||
|
var dataGridViewRows = DataGridView.Rows;
|
||||||
|
var rowCount = dataGridViewRows.Count;
|
||||||
|
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
||||||
|
{
|
||||||
|
var dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
||||||
|
var dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
||||||
|
if (dataGridViewCell != null) dataGridViewCell.SetMaximum(rowIndex, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataGridView.InvalidateColumn(Index);
|
||||||
|
// TODO: This column and/or grid rows may need to be autosized depending on their
|
||||||
|
// autosize settings. Call the autosizing methods to autosize the column, rows,
|
||||||
|
// column headers / row headers as needed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replicates the Minimum property of the DataGridViewNumericUpDownCell cell type.
|
||||||
|
/// </summary>
|
||||||
|
[Category("Data")]
|
||||||
|
[Description("Indicates the minimum value for the numeric up-down cells.")]
|
||||||
|
[RefreshProperties(RefreshProperties.All)]
|
||||||
|
public decimal Minimum
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (NumericUpDownCellTemplate == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
|
return NumericUpDownCellTemplate.Minimum;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (NumericUpDownCellTemplate == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
|
NumericUpDownCellTemplate.Minimum = value;
|
||||||
|
if (DataGridView != null)
|
||||||
|
{
|
||||||
|
var dataGridViewRows = DataGridView.Rows;
|
||||||
|
var rowCount = dataGridViewRows.Count;
|
||||||
|
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
||||||
|
{
|
||||||
|
var dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
||||||
|
var dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
||||||
|
if (dataGridViewCell != null) dataGridViewCell.SetMinimum(rowIndex, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataGridView.InvalidateColumn(Index);
|
||||||
|
// TODO: This column and/or grid rows may need to be autosized depending on their
|
||||||
|
// autosize settings. Call the autosizing methods to autosize the column, rows,
|
||||||
|
// column headers / row headers as needed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replicates the ThousandsSeparator property of the DataGridViewNumericUpDownCell cell type.
|
||||||
|
/// </summary>
|
||||||
|
[Category("Data")]
|
||||||
|
[DefaultValue(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultThousandsSeparator)]
|
||||||
|
[Description("Indicates whether the thousands separator will be inserted between every three decimal digits.")]
|
||||||
|
public bool ThousandsSeparator
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (NumericUpDownCellTemplate == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
|
return NumericUpDownCellTemplate.ThousandsSeparator;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (NumericUpDownCellTemplate == null)
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
||||||
|
NumericUpDownCellTemplate.ThousandsSeparator = value;
|
||||||
|
if (DataGridView != null)
|
||||||
|
{
|
||||||
|
var dataGridViewRows = DataGridView.Rows;
|
||||||
|
var rowCount = dataGridViewRows.Count;
|
||||||
|
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
||||||
|
{
|
||||||
|
var dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
||||||
|
var dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
||||||
|
if (dataGridViewCell != null) dataGridViewCell.SetThousandsSeparator(rowIndex, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
DataGridView.InvalidateColumn(Index);
|
||||||
|
// TODO: This column and/or grid rows may need to be autosized depending on their
|
||||||
|
// autosize settings. Call the autosizing methods to autosize the column, rows,
|
||||||
|
// column headers / row headers as needed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Small utility function that returns the template cell as a DataGridViewNumericUpDownCell
|
||||||
|
/// </summary>
|
||||||
|
private DataGridViewNumericUpDownCell NumericUpDownCellTemplate => (DataGridViewNumericUpDownCell) CellTemplate;
|
||||||
|
|
||||||
/// Indicates whether the Increment property should be persisted.
|
/// Indicates whether the Increment property should be persisted.
|
||||||
private bool ShouldSerializeIncrement()
|
private bool ShouldSerializeIncrement()
|
||||||
{
|
{
|
||||||
return !Increment.Equals(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultIncrement);
|
return !Increment.Equals(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultIncrement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Replicates the Maximum property of the DataGridViewNumericUpDownCell cell type.
|
|
||||||
/// </summary>
|
|
||||||
[
|
|
||||||
Category("Data"),
|
|
||||||
Description("Indicates the maximum value for the numeric up-down cells."),
|
|
||||||
RefreshProperties(RefreshProperties.All)
|
|
||||||
]
|
|
||||||
public decimal Maximum
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
if (NumericUpDownCellTemplate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
|
||||||
}
|
|
||||||
return NumericUpDownCellTemplate.Maximum;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
if (NumericUpDownCellTemplate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
|
||||||
}
|
|
||||||
NumericUpDownCellTemplate.Maximum = value;
|
|
||||||
if (DataGridView != null)
|
|
||||||
{
|
|
||||||
DataGridViewRowCollection dataGridViewRows = DataGridView.Rows;
|
|
||||||
int rowCount = dataGridViewRows.Count;
|
|
||||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
|
||||||
{
|
|
||||||
DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
|
||||||
DataGridViewNumericUpDownCell dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
|
||||||
if (dataGridViewCell != null)
|
|
||||||
{
|
|
||||||
dataGridViewCell.SetMaximum(rowIndex, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DataGridView.InvalidateColumn(Index);
|
|
||||||
// TODO: This column and/or grid rows may need to be autosized depending on their
|
|
||||||
// autosize settings. Call the autosizing methods to autosize the column, rows,
|
|
||||||
// column headers / row headers as needed.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Indicates whether the Maximum property should be persisted.
|
/// Indicates whether the Maximum property should be persisted.
|
||||||
private bool ShouldSerializeMaximum()
|
private bool ShouldSerializeMaximum()
|
||||||
{
|
{
|
||||||
return !Maximum.Equals(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultMaximum);
|
return !Maximum.Equals(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultMaximum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Replicates the Minimum property of the DataGridViewNumericUpDownCell cell type.
|
|
||||||
/// </summary>
|
|
||||||
[
|
|
||||||
Category("Data"),
|
|
||||||
Description("Indicates the minimum value for the numeric up-down cells."),
|
|
||||||
RefreshProperties(RefreshProperties.All)
|
|
||||||
]
|
|
||||||
public decimal Minimum
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
if (NumericUpDownCellTemplate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
|
||||||
}
|
|
||||||
return NumericUpDownCellTemplate.Minimum;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
if (NumericUpDownCellTemplate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
|
||||||
}
|
|
||||||
NumericUpDownCellTemplate.Minimum = value;
|
|
||||||
if (DataGridView != null)
|
|
||||||
{
|
|
||||||
DataGridViewRowCollection dataGridViewRows = DataGridView.Rows;
|
|
||||||
int rowCount = dataGridViewRows.Count;
|
|
||||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
|
||||||
{
|
|
||||||
DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
|
||||||
DataGridViewNumericUpDownCell dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
|
||||||
if (dataGridViewCell != null)
|
|
||||||
{
|
|
||||||
dataGridViewCell.SetMinimum(rowIndex, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DataGridView.InvalidateColumn(Index);
|
|
||||||
// TODO: This column and/or grid rows may need to be autosized depending on their
|
|
||||||
// autosize settings. Call the autosizing methods to autosize the column, rows,
|
|
||||||
// column headers / row headers as needed.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Indicates whether the Maximum property should be persisted.
|
/// Indicates whether the Maximum property should be persisted.
|
||||||
private bool ShouldSerializeMinimum()
|
private bool ShouldSerializeMinimum()
|
||||||
{
|
{
|
||||||
@ -234,65 +259,11 @@ namespace GradeCalc
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replicates the ThousandsSeparator property of the DataGridViewNumericUpDownCell cell type.
|
/// Returns a standard compact string representation of the column.
|
||||||
/// </summary>
|
|
||||||
[
|
|
||||||
Category("Data"),
|
|
||||||
DefaultValue(DataGridViewNumericUpDownCell.DATAGRIDVIEWNUMERICUPDOWNCELL_defaultThousandsSeparator),
|
|
||||||
Description("Indicates whether the thousands separator will be inserted between every three decimal digits.")
|
|
||||||
]
|
|
||||||
public bool ThousandsSeparator
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
if (NumericUpDownCellTemplate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
|
||||||
}
|
|
||||||
return NumericUpDownCellTemplate.ThousandsSeparator;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
if (NumericUpDownCellTemplate == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Operation cannot be completed because this DataGridViewColumn does not have a CellTemplate.");
|
|
||||||
}
|
|
||||||
NumericUpDownCellTemplate.ThousandsSeparator = value;
|
|
||||||
if (DataGridView != null)
|
|
||||||
{
|
|
||||||
DataGridViewRowCollection dataGridViewRows = DataGridView.Rows;
|
|
||||||
int rowCount = dataGridViewRows.Count;
|
|
||||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
|
|
||||||
{
|
|
||||||
DataGridViewRow dataGridViewRow = dataGridViewRows.SharedRow(rowIndex);
|
|
||||||
DataGridViewNumericUpDownCell dataGridViewCell = dataGridViewRow.Cells[Index] as DataGridViewNumericUpDownCell;
|
|
||||||
if (dataGridViewCell != null)
|
|
||||||
{
|
|
||||||
dataGridViewCell.SetThousandsSeparator(rowIndex, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DataGridView.InvalidateColumn(Index);
|
|
||||||
// TODO: This column and/or grid rows may need to be autosized depending on their
|
|
||||||
// autosize settings. Call the autosizing methods to autosize the column, rows,
|
|
||||||
// column headers / row headers as needed.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Small utility function that returns the template cell as a DataGridViewNumericUpDownCell
|
|
||||||
/// </summary>
|
|
||||||
private DataGridViewNumericUpDownCell NumericUpDownCellTemplate
|
|
||||||
{
|
|
||||||
get {
|
|
||||||
return (DataGridViewNumericUpDownCell)CellTemplate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a standard compact string representation of the column.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder(100);
|
var sb = new StringBuilder(100);
|
||||||
sb.Append("DataGridViewNumericUpDownColumn { Name=");
|
sb.Append("DataGridViewNumericUpDownColumn { Name=");
|
||||||
sb.Append(Name);
|
sb.Append(Name);
|
||||||
sb.Append(", Index=");
|
sb.Append(", Index=");
|
||||||
|
85
Misc/HID.cs
85
Misc/HID.cs
@ -1,4 +1,6 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -27,47 +29,80 @@ Win32_NetworkAdapterConfiguration:MACAddress:IPEnabled";
|
|||||||
|
|
||||||
public static byte[] Value
|
public static byte[] Value
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
if (_fingerPrint == null)
|
if (_fingerPrint == null)
|
||||||
{
|
{
|
||||||
string fingerprint_tmp = "";
|
var fingerprint_tmp = "";
|
||||||
HIDClasses.Split('\r').Select(s =>
|
if (Type.GetType("Mono.Runtime") == null)
|
||||||
{
|
{
|
||||||
if (s.StartsWith("\n"))
|
HIDClasses.Split('\r').Select(s =>
|
||||||
s = s.Remove(0, 1);
|
|
||||||
return s.Split(':');
|
|
||||||
}).ToList().ForEach(s =>
|
|
||||||
{
|
|
||||||
using (ManagementClass mc = new ManagementClass(s[0]))
|
|
||||||
using (ManagementObjectCollection moc = mc.GetInstances())
|
|
||||||
{
|
{
|
||||||
ManagementBaseObject[] array = moc.OfType<ManagementBaseObject>().ToArray();
|
if (s.StartsWith("\n"))
|
||||||
for (int j = 0; j < array.Length; j++)
|
s = s.Remove(0, 1);
|
||||||
|
return s.Split(':');
|
||||||
|
}).ToList().ForEach(s =>
|
||||||
|
{
|
||||||
|
using (var mc = new ManagementClass(s[0]))
|
||||||
|
using (var moc = mc.GetInstances())
|
||||||
{
|
{
|
||||||
if ((s.Length > 2) && array[j][s[2]].ToString() != "True") continue;
|
var array = moc.OfType<ManagementBaseObject>().ToArray();
|
||||||
try
|
for (var j = 0; j < array.Length; j++)
|
||||||
{
|
|
||||||
fingerprint_tmp += array[j][s[1]].ToString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
|
if (s.Length > 2 && array[j][s[2]].ToString() != "True") continue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fingerprint_tmp += array[j][s[1]].ToString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
else //Linux implementation. This will not work if you are using Mono on windows or do not have uname and lscpu available
|
||||||
|
{
|
||||||
|
var p = new Process
|
||||||
|
{
|
||||||
|
StartInfo =
|
||||||
|
{
|
||||||
|
UseShellExecute = false,
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
FileName = "uname",
|
||||||
|
Arguments = "-nmpio"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
p.Start();
|
||||||
|
fingerprint_tmp = p.StandardOutput.ReadToEnd();
|
||||||
|
p.WaitForExit();
|
||||||
|
p.StartInfo.FileName = "lscpu";
|
||||||
|
p.StartInfo.Arguments = "";
|
||||||
|
p.Start();
|
||||||
|
fingerprint_tmp += p.StandardOutput.ReadToEnd();
|
||||||
|
p.WaitForExit();
|
||||||
|
}
|
||||||
|
|
||||||
using (MD5 sec = new MD5CryptoServiceProvider())
|
using (MD5 sec = new MD5CryptoServiceProvider())
|
||||||
{
|
{
|
||||||
byte[] bt = Encoding.ASCII.GetBytes(fingerprint_tmp);
|
var bt = Encoding.ASCII.GetBytes(fingerprint_tmp);
|
||||||
_fingerPrint = sec.ComputeHash(bt);
|
_fingerPrint = sec.ComputeHash(bt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _fingerPrint;
|
return _fingerPrint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] EncryptLocal(byte[] unencrypted) => ProtectedData.Protect(unencrypted, Value, DataProtectionScope.CurrentUser);
|
public static byte[] EncryptLocal(byte[] unencrypted)
|
||||||
|
{
|
||||||
|
return ProtectedData.Protect(unencrypted, Value, DataProtectionScope.CurrentUser);
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] DecryptLocal(byte[] encrypted) => ProtectedData.Unprotect(encrypted, Value, DataProtectionScope.CurrentUser);
|
public static byte[] DecryptLocal(byte[] encrypted)
|
||||||
|
{
|
||||||
|
return ProtectedData.Unprotect(encrypted, Value, DataProtectionScope.CurrentUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,7 +5,9 @@ using System.Runtime.InteropServices;
|
|||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("CC-Functions.W32")]
|
[assembly: AssemblyTitle("CC-Functions.W32")]
|
||||||
[assembly: AssemblyDescription("Random pieces of code used across my projects. I do NOT recommend using this in your own project!")]
|
[assembly:
|
||||||
|
AssemblyDescription(
|
||||||
|
"Random pieces of code used across my projects. I do NOT recommend using this in your own project!")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("CC24")]
|
[assembly: AssemblyCompany("CC24")]
|
||||||
[assembly: AssemblyProduct("CC-Functions")]
|
[assembly: AssemblyProduct("CC-Functions")]
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
using CC_Functions.Misc;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using CC_Functions.Misc;
|
||||||
using static CC_Functions.W32.Power;
|
using static CC_Functions.W32.Power;
|
||||||
|
|
||||||
namespace CC_Functions.W32.Test
|
namespace CC_Functions.W32.Test
|
||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
private MouseHook mHook;
|
|
||||||
private KeyboardHook kHook;
|
|
||||||
public static Wnd32 tmpWnd;
|
public static Wnd32 tmpWnd;
|
||||||
public static Form1 mainF;
|
public static Form1 mainF;
|
||||||
public static Form frm;
|
public static Form frm;
|
||||||
public static Label lab;
|
public static Label lab;
|
||||||
|
private readonly KeyboardHook kHook;
|
||||||
|
private Point locDelB;
|
||||||
|
private readonly MouseHook mHook;
|
||||||
|
|
||||||
|
private bool moving;
|
||||||
|
private DateTime mST;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
@ -42,27 +46,49 @@ namespace CC_Functions.W32.Test
|
|||||||
box.DataSource = Enum.GetNames(enumT);
|
box.DataSource = Enum.GetNames(enumT);
|
||||||
var tmp = Enum.GetValues(enumT);
|
var tmp = Enum.GetValues(enumT);
|
||||||
box.Tag = new object[tmp.Length];
|
box.Tag = new object[tmp.Length];
|
||||||
int i = 0;
|
var i = 0;
|
||||||
foreach (object o in tmp)
|
foreach (var o in tmp)
|
||||||
{
|
{
|
||||||
((object[])box.Tag)[i] = o;
|
((object[]) box.Tag)[i] = o;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object get_box_value(ComboBox box) => ((object[])box.Tag)[box.SelectedIndex];
|
public object get_box_value(ComboBox box)
|
||||||
|
{
|
||||||
|
return ((object[]) box.Tag)[box.SelectedIndex];
|
||||||
|
}
|
||||||
|
|
||||||
private void Power_execute_Click(object sender, EventArgs e) => RaiseEvent((ShutdownMode)get_box_value(power_mode_box), (ShutdownReason)get_box_value(power_reason_box), (ShutdownMod)get_box_value(power_mod_box));
|
private void Power_execute_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
RaiseEvent((ShutdownMode) get_box_value(power_mode_box), (ShutdownReason) get_box_value(power_reason_box),
|
||||||
|
(ShutdownMod) get_box_value(power_mod_box));
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_select_self_Click(object sender, EventArgs e) => tmpWnd = Wnd32.fromForm(this);
|
private void Wnd_select_self_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd = Wnd32.fromForm(this);
|
||||||
|
}
|
||||||
|
|
||||||
private void wnd_select_list_Click(object sender, EventArgs e) => tmpWnd = SelectBox.Show(Wnd32.getVisible(), "Please select a window") ?? tmpWnd;
|
private void wnd_select_list_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd = SelectBox.Show(Wnd32.getVisible(), "Please select a window") ?? tmpWnd;
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_select_title_button_Click(object sender, EventArgs e) => tmpWnd = Wnd32.fromMetadata(null, wnd_select_title_box.Text);
|
private void Wnd_select_title_button_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd = Wnd32.fromMetadata(null, wnd_select_title_box.Text);
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_selet_class_button_Click(object sender, EventArgs e) => tmpWnd = Wnd32.fromMetadata(wnd_select_class_box.Text, null);
|
private void Wnd_selet_class_button_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd = Wnd32.fromMetadata(wnd_select_class_box.Text);
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_action_title_set_Click(object sender, EventArgs e) => tmpWnd.title = wnd_select_title_box.Text;
|
private void Wnd_action_title_set_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.title = wnd_select_title_box.Text;
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_action_title_get_Click(object sender, EventArgs e)
|
private void Wnd_action_title_get_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -70,26 +96,76 @@ namespace CC_Functions.W32.Test
|
|||||||
tmpWnd = Wnd32.fromForm(this);
|
tmpWnd = Wnd32.fromForm(this);
|
||||||
wnd_select_title_box.Text = tmpWnd.title;
|
wnd_select_title_box.Text = tmpWnd.title;
|
||||||
wnd_action_enabled.Checked = tmpWnd.enabled;
|
wnd_action_enabled.Checked = tmpWnd.enabled;
|
||||||
wnd_select_selected.Text = "Selected: " + tmpWnd.hWnd.ToString();
|
wnd_select_selected.Text = "Selected: " + tmpWnd.hWnd;
|
||||||
wnd_action_style.SelectedIndex = (int)tmpWnd.state;
|
wnd_action_style.SelectedIndex = (int) tmpWnd.state;
|
||||||
wnd_select_class_box.Text = tmpWnd.className;
|
wnd_select_class_box.Text = tmpWnd.className;
|
||||||
wnd_action_visible.Checked = tmpWnd.shown;
|
wnd_action_visible.Checked = tmpWnd.shown;
|
||||||
try { wnd_action_icon.BackgroundImage = tmpWnd.icon.ToBitmap(); } catch { wnd_action_icon.BackgroundImage = null; }
|
try
|
||||||
try { wnd_action_pos_x_bar.Value = tmpWnd.position.X; } catch { }
|
{
|
||||||
try { wnd_action_pos_y_bar.Value = tmpWnd.position.Y; } catch { }
|
wnd_action_icon.BackgroundImage = tmpWnd.icon.ToBitmap();
|
||||||
try { wnd_action_pos_w_bar.Value = tmpWnd.position.Width; } catch { }
|
}
|
||||||
try { wnd_action_pos_h_bar.Value = tmpWnd.position.Height; } catch { }
|
catch
|
||||||
|
{
|
||||||
|
wnd_action_icon.BackgroundImage = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wnd_action_pos_x_bar.Value = tmpWnd.position.X;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wnd_action_pos_y_bar.Value = tmpWnd.position.Y;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wnd_action_pos_w_bar.Value = tmpWnd.position.Width;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wnd_action_pos_h_bar.Value = tmpWnd.position.Height;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Wnd_action_enabled_CheckedChanged(object sender, EventArgs e) => tmpWnd.enabled = wnd_action_enabled.Checked;
|
private void Wnd_action_enabled_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.enabled = wnd_action_enabled.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_action_visible_CheckedChanged(object sender, EventArgs e) => tmpWnd.shown = wnd_action_visible.Checked;
|
private void Wnd_action_visible_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.shown = wnd_action_visible.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_action_front_Click(object sender, EventArgs e) => tmpWnd.isForeground = true;
|
private void Wnd_action_front_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.isForeground = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_action_overlay_Click(object sender, EventArgs e) => tmpWnd.MakeOverlay();
|
private void Wnd_action_overlay_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.MakeOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_action_destroy_Click(object sender, EventArgs e) => tmpWnd.Destroy();
|
private void Wnd_action_destroy_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
private void Wnd_select_mouse_Click(object sender, EventArgs e)
|
private void Wnd_select_mouse_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -113,7 +189,7 @@ namespace CC_Functions.W32.Test
|
|||||||
{
|
{
|
||||||
frm.Hide();
|
frm.Hide();
|
||||||
frm.WindowState = FormWindowState.Minimized;
|
frm.WindowState = FormWindowState.Minimized;
|
||||||
Wnd32 tmp = Wnd32.fromPoint(MousePosition);
|
var tmp = Wnd32.fromPoint(MousePosition);
|
||||||
tmpWnd.enabled = true;
|
tmpWnd.enabled = true;
|
||||||
tmpWnd.isForeground = true;
|
tmpWnd.isForeground = true;
|
||||||
tmpWnd = tmp;
|
tmpWnd = tmp;
|
||||||
@ -130,18 +206,14 @@ namespace CC_Functions.W32.Test
|
|||||||
private void Mouse_enabled_CheckedChanged(object sender, EventArgs e)
|
private void Mouse_enabled_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (mouse_enabled.Checked)
|
if (mouse_enabled.Checked)
|
||||||
{
|
|
||||||
mHook.OnMouse += MHook_OnMouse;
|
mHook.OnMouse += MHook_OnMouse;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
mHook.OnMouse -= MHook_OnMouse;
|
mHook.OnMouse -= MHook_OnMouse;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MHook_OnMouse(MouseHookEventArgs _args)
|
private void MHook_OnMouse(MouseHookEventArgs _args)
|
||||||
{
|
{
|
||||||
mouse_log.Text = _args.Message.ToString() + " -|- " + _args.Point.ToString() + "\r\n" + mouse_log.Text;
|
mouse_log.Text = _args.Message + " -|- " + _args.Point + "\r\n" + mouse_log.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Mouse_log_TextChanged(object sender, EventArgs e)
|
private void Mouse_log_TextChanged(object sender, EventArgs e)
|
||||||
@ -158,18 +230,14 @@ namespace CC_Functions.W32.Test
|
|||||||
private void Keyboard_enabled_CheckedChanged(object sender, EventArgs e)
|
private void Keyboard_enabled_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (keyboard_enabled.Checked)
|
if (keyboard_enabled.Checked)
|
||||||
{
|
|
||||||
kHook.OnKeyPress += KHook_OnKeyPress;
|
kHook.OnKeyPress += KHook_OnKeyPress;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
kHook.OnKeyPress -= KHook_OnKeyPress;
|
kHook.OnKeyPress -= KHook_OnKeyPress;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void KHook_OnKeyPress(KeyboardHookEventArgs _args)
|
private void KHook_OnKeyPress(KeyboardHookEventArgs _args)
|
||||||
{
|
{
|
||||||
keyboard_log.Text = _args.Key.ToString() + "\r\n" + keyboard_log.Text;
|
keyboard_log.Text = _args.Key + "\r\n" + keyboard_log.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Keyboard_log_TextChanged(object sender, EventArgs e)
|
private void Keyboard_log_TextChanged(object sender, EventArgs e)
|
||||||
@ -185,7 +253,8 @@ namespace CC_Functions.W32.Test
|
|||||||
|
|
||||||
private void Wnd_action_pos_Click(object sender, EventArgs e)
|
private void Wnd_action_pos_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
tmpWnd.position = new Rectangle(wnd_action_pos_x_bar.Value, wnd_action_pos_y_bar.Value, wnd_action_pos_w_bar.Value, wnd_action_pos_h_bar.Value);
|
tmpWnd.position = new Rectangle(wnd_action_pos_x_bar.Value, wnd_action_pos_y_bar.Value,
|
||||||
|
wnd_action_pos_w_bar.Value, wnd_action_pos_h_bar.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Exit_Click(object sender, EventArgs e)
|
private void Exit_Click(object sender, EventArgs e)
|
||||||
@ -194,10 +263,6 @@ namespace CC_Functions.W32.Test
|
|||||||
Application.Exit();
|
Application.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool moving;
|
|
||||||
private Point locDelB;
|
|
||||||
private DateTime mST;
|
|
||||||
|
|
||||||
private void Exit_MouseMove(object sender, MouseEventArgs e)
|
private void Exit_MouseMove(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
if (moving && (DateTime.Now - mST).TotalSeconds >= 0.1f)
|
if (moving && (DateTime.Now - mST).TotalSeconds >= 0.1f)
|
||||||
@ -222,6 +287,9 @@ namespace CC_Functions.W32.Test
|
|||||||
tmpWnd.state = status;
|
tmpWnd.state = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void wnd_action_overlay_CheckedChanged(object sender, EventArgs e) => tmpWnd.overlay = wnd_action_overlay.Checked;
|
private void wnd_action_overlay_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
tmpWnd.overlay = wnd_action_overlay.Checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ namespace CC_Functions.W32.Test
|
|||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main()
|
private static void Main()
|
||||||
|
@ -8,22 +8,14 @@ namespace CC_Functions.W32
|
|||||||
{
|
{
|
||||||
public sealed class KeyboardHook : IDisposable
|
public sealed class KeyboardHook : IDisposable
|
||||||
{
|
{
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
instances.Remove(this);
|
|
||||||
if (instances.Count == 0)
|
|
||||||
UnhookWindowsHookEx(_hookID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<KeyboardHook> instances = new List<KeyboardHook>();
|
|
||||||
private const int WH_KEYBOARD_LL = 13;
|
|
||||||
private const int WM_KEYDOWN = 0x0100;
|
|
||||||
private static LowLevelKeyboardProc _proc = HookCallback;
|
|
||||||
private static IntPtr _hookID = IntPtr.Zero;
|
|
||||||
|
|
||||||
public delegate void keyPress(KeyboardHookEventArgs _args);
|
public delegate void keyPress(KeyboardHookEventArgs _args);
|
||||||
|
|
||||||
public event keyPress OnKeyPress;
|
private const int WH_KEYBOARD_LL = 13;
|
||||||
|
private const int WM_KEYDOWN = 0x0100;
|
||||||
|
|
||||||
|
private static readonly List<KeyboardHook> instances = new List<KeyboardHook>();
|
||||||
|
private static readonly LowLevelKeyboardProc _proc = HookCallback;
|
||||||
|
private static IntPtr _hookID = IntPtr.Zero;
|
||||||
|
|
||||||
public KeyboardHook()
|
public KeyboardHook()
|
||||||
{
|
{
|
||||||
@ -32,32 +24,39 @@ namespace CC_Functions.W32
|
|||||||
instances.Add(this);
|
instances.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
instances.Remove(this);
|
||||||
|
if (instances.Count == 0)
|
||||||
|
UnhookWindowsHookEx(_hookID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public event keyPress OnKeyPress;
|
||||||
|
|
||||||
private IntPtr SetHook(LowLevelKeyboardProc proc)
|
private IntPtr SetHook(LowLevelKeyboardProc proc)
|
||||||
{
|
{
|
||||||
using (Process curProcess = Process.GetCurrentProcess())
|
using (var curProcess = Process.GetCurrentProcess())
|
||||||
using (ProcessModule curModule = curProcess.MainModule)
|
using (var curModule = curProcess.MainModule)
|
||||||
{
|
{
|
||||||
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
|
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
|
|
||||||
|
|
||||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||||
{
|
{
|
||||||
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
|
if (nCode >= 0 && wParam == (IntPtr) WM_KEYDOWN)
|
||||||
{
|
{
|
||||||
int vkCode = Marshal.ReadInt32(lParam);
|
var vkCode = Marshal.ReadInt32(lParam);
|
||||||
for (int i = 0; i < instances.Count; i++)
|
for (var i = 0; i < instances.Count; i++)
|
||||||
{
|
instances[i].OnKeyPress?.Invoke(new KeyboardHookEventArgs((Keys) vkCode));
|
||||||
instances[i].OnKeyPress?.Invoke(new KeyboardHookEventArgs((Keys)vkCode));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return CallNextHookEx(_hookID, nCode, wParam, lParam);
|
return CallNextHookEx(_hookID, nCode, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
|
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod,
|
||||||
|
uint dwThreadId);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
@ -68,5 +67,7 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
private static extern IntPtr GetModuleHandle(string lpModuleName);
|
private static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||||
|
|
||||||
|
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,6 +12,9 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public Keys Key { get; }
|
public Keys Key { get; }
|
||||||
|
|
||||||
public override string ToString() => Key.ToString();
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Key.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,54 +8,8 @@ namespace CC_Functions.W32
|
|||||||
{
|
{
|
||||||
public sealed class MouseHook : IDisposable
|
public sealed class MouseHook : IDisposable
|
||||||
{
|
{
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
instances.Remove(this);
|
|
||||||
if (instances.Count == 0)
|
|
||||||
UnhookWindowsHookEx(_hookID);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<MouseHook> instances = new List<MouseHook>();
|
|
||||||
private static LowLevelMouseProc _proc = HookCallback;
|
|
||||||
private static IntPtr _hookID = IntPtr.Zero;
|
|
||||||
|
|
||||||
public delegate void mouseEvent(MouseHookEventArgs _args);
|
public delegate void mouseEvent(MouseHookEventArgs _args);
|
||||||
|
|
||||||
public event mouseEvent OnMouse;
|
|
||||||
|
|
||||||
public MouseHook()
|
|
||||||
{
|
|
||||||
if (instances.Count == 0)
|
|
||||||
_hookID = SetHook(_proc);
|
|
||||||
instances.Add(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IntPtr SetHook(LowLevelMouseProc proc)
|
|
||||||
{
|
|
||||||
using (Process curProcess = Process.GetCurrentProcess())
|
|
||||||
using (ProcessModule curModule = curProcess.MainModule)
|
|
||||||
{
|
|
||||||
return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
|
|
||||||
|
|
||||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
|
||||||
{
|
|
||||||
if (nCode >= 0)
|
|
||||||
{
|
|
||||||
MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
|
|
||||||
for (int i = 0; i < instances.Count; i++)
|
|
||||||
{
|
|
||||||
instances[i].OnMouse?.Invoke(new MouseHookEventArgs(new Point(hookStruct.pt.x, hookStruct.pt.y), (MouseMessages)wParam));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return CallNextHookEx(_hookID, nCode, wParam, lParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
private const int WH_MOUSE_LL = 14;
|
|
||||||
|
|
||||||
public enum MouseMessages
|
public enum MouseMessages
|
||||||
{
|
{
|
||||||
WM_LBUTTONDOWN = 0x0201,
|
WM_LBUTTONDOWN = 0x0201,
|
||||||
@ -66,21 +20,48 @@ namespace CC_Functions.W32
|
|||||||
WM_RBUTTONUP = 0x0205
|
WM_RBUTTONUP = 0x0205
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
private const int WH_MOUSE_LL = 14;
|
||||||
private struct POINT
|
|
||||||
|
private static readonly List<MouseHook> instances = new List<MouseHook>();
|
||||||
|
private static readonly LowLevelMouseProc _proc = HookCallback;
|
||||||
|
private static IntPtr _hookID = IntPtr.Zero;
|
||||||
|
|
||||||
|
public MouseHook()
|
||||||
{
|
{
|
||||||
public int x;
|
if (instances.Count == 0)
|
||||||
public int y;
|
_hookID = SetHook(_proc);
|
||||||
|
instances.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
public void Dispose()
|
||||||
private struct MSLLHOOKSTRUCT
|
|
||||||
{
|
{
|
||||||
public POINT pt;
|
instances.Remove(this);
|
||||||
public uint mouseData;
|
if (instances.Count == 0)
|
||||||
public uint flags;
|
UnhookWindowsHookEx(_hookID);
|
||||||
public uint time;
|
}
|
||||||
public IntPtr dwExtraInfo;
|
|
||||||
|
public event mouseEvent OnMouse;
|
||||||
|
|
||||||
|
private static IntPtr SetHook(LowLevelMouseProc proc)
|
||||||
|
{
|
||||||
|
using (var curProcess = Process.GetCurrentProcess())
|
||||||
|
using (var curModule = curProcess.MainModule)
|
||||||
|
{
|
||||||
|
return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||||
|
{
|
||||||
|
if (nCode >= 0)
|
||||||
|
{
|
||||||
|
var hookStruct = (MSLLHOOKSTRUCT) Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
|
||||||
|
for (var i = 0; i < instances.Count; i++)
|
||||||
|
instances[i].OnMouse?.Invoke(new MouseHookEventArgs(new Point(hookStruct.pt.x, hookStruct.pt.y),
|
||||||
|
(MouseMessages) wParam));
|
||||||
|
}
|
||||||
|
|
||||||
|
return CallNextHookEx(_hookID, nCode, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
@ -95,5 +76,24 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
private static extern IntPtr GetModuleHandle(string lpModuleName);
|
private static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||||
|
|
||||||
|
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct POINT
|
||||||
|
{
|
||||||
|
public readonly int x;
|
||||||
|
public readonly int y;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct MSLLHOOKSTRUCT
|
||||||
|
{
|
||||||
|
public readonly POINT pt;
|
||||||
|
public readonly uint mouseData;
|
||||||
|
public readonly uint flags;
|
||||||
|
public readonly uint time;
|
||||||
|
public readonly IntPtr dwExtraInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return Message.ToString() + "; " + Point.ToString();
|
return Message + "; " + Point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,20 +10,13 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public static bool IsKeyDown(Keys key)
|
public static bool IsKeyDown(Keys key)
|
||||||
{
|
{
|
||||||
try
|
var state = 0;
|
||||||
{
|
var retVal = GetKeyState((int) key);
|
||||||
int state = 0;
|
if ((retVal & 0x8000) == 0x8000)
|
||||||
short retVal = GetKeyState((int)key);
|
state |= 1;
|
||||||
if ((retVal & 0x8000) == 0x8000)
|
if ((retVal & 1) == 1)
|
||||||
state |= 1;
|
state |= 2;
|
||||||
if ((retVal & 1) == 1)
|
return (state & 1) == 1;
|
||||||
state |= 2;
|
|
||||||
return (state & 1) == 1;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
100
W32/Power.cs
100
W32/Power.cs
@ -6,22 +6,41 @@ namespace CC_Functions.W32
|
|||||||
{
|
{
|
||||||
public static class Power
|
public static class Power
|
||||||
{
|
{
|
||||||
[DllImport("ntdll.dll", SetLastError = true)]
|
[Flags]
|
||||||
private static extern IntPtr RtlAdjustPrivilege(int Privilege, bool bEnablePrivilege, bool IsThreadPrivilege, out bool PreviousValue);
|
public enum ExitWindows : uint
|
||||||
|
{
|
||||||
|
// ONE of the following five:
|
||||||
|
LogOff = 0x00,
|
||||||
|
|
||||||
[DllImport("ntdll.dll")]
|
ShutDown = 0x01,
|
||||||
private static extern uint NtRaiseHardError(
|
Reboot = 0x02,
|
||||||
uint ErrorStatus,
|
PowerOff = 0x08,
|
||||||
uint NumberOfParameters,
|
RestartApps = 0x40,
|
||||||
uint UnicodeStringParameterMask,
|
|
||||||
IntPtr Parameters,
|
|
||||||
uint ValidResponseOption,
|
|
||||||
out uint Response
|
|
||||||
);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
// plus AT MOST ONE of the following two:
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
Force = 0x04,
|
||||||
private static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
|
|
||||||
|
ForceIfHung = 0x10
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum ShutdownMod : uint
|
||||||
|
{
|
||||||
|
None = 0x00,
|
||||||
|
Force = 0x04,
|
||||||
|
ForceIfHung = 0x10
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum ShutdownMode : uint
|
||||||
|
{
|
||||||
|
LogOff = 0x00,
|
||||||
|
ShutDown = 0x01,
|
||||||
|
Reboot = 0x02,
|
||||||
|
PowerOff = 0x08,
|
||||||
|
RestartApps = 0x40,
|
||||||
|
BSoD = 0x29a
|
||||||
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum ShutdownReason : uint
|
public enum ShutdownReason : uint
|
||||||
@ -66,43 +85,26 @@ namespace CC_Functions.W32
|
|||||||
FlagPlanned = 0x80000000
|
FlagPlanned = 0x80000000
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[DllImport("ntdll.dll", SetLastError = true)]
|
||||||
public enum ExitWindows : uint
|
private static extern IntPtr RtlAdjustPrivilege(int Privilege, bool bEnablePrivilege, bool IsThreadPrivilege,
|
||||||
{
|
out bool PreviousValue);
|
||||||
// ONE of the following five:
|
|
||||||
LogOff = 0x00,
|
|
||||||
|
|
||||||
ShutDown = 0x01,
|
[DllImport("ntdll.dll")]
|
||||||
Reboot = 0x02,
|
private static extern uint NtRaiseHardError(
|
||||||
PowerOff = 0x08,
|
uint ErrorStatus,
|
||||||
RestartApps = 0x40,
|
uint NumberOfParameters,
|
||||||
|
uint UnicodeStringParameterMask,
|
||||||
|
IntPtr Parameters,
|
||||||
|
uint ValidResponseOption,
|
||||||
|
out uint Response
|
||||||
|
);
|
||||||
|
|
||||||
// plus AT MOST ONE of the following two:
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
Force = 0x04,
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
private static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason);
|
||||||
|
|
||||||
ForceIfHung = 0x10,
|
public static void RaiseEvent(ShutdownMode mode, ShutdownReason reason = ShutdownReason.MinorOther,
|
||||||
}
|
ShutdownMod mod = ShutdownMod.None)
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum ShutdownMode : uint
|
|
||||||
{
|
|
||||||
LogOff = 0x00,
|
|
||||||
ShutDown = 0x01,
|
|
||||||
Reboot = 0x02,
|
|
||||||
PowerOff = 0x08,
|
|
||||||
RestartApps = 0x40,
|
|
||||||
BSoD = 0x29a
|
|
||||||
}
|
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum ShutdownMod : uint
|
|
||||||
{
|
|
||||||
None = 0x00,
|
|
||||||
Force = 0x04,
|
|
||||||
ForceIfHung = 0x10
|
|
||||||
}
|
|
||||||
|
|
||||||
public static unsafe void RaiseEvent(ShutdownMode mode, ShutdownReason reason = ShutdownReason.MinorOther, ShutdownMod mod = ShutdownMod.None)
|
|
||||||
{
|
{
|
||||||
if (mode == ShutdownMode.BSoD)
|
if (mode == ShutdownMode.BSoD)
|
||||||
{
|
{
|
||||||
@ -114,7 +116,7 @@ namespace CC_Functions.W32
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
EnablePrivilege(SecurityEntity.SeShutdownPrivilege);
|
EnablePrivilege(SecurityEntity.SeShutdownPrivilege);
|
||||||
ExitWindowsEx((ExitWindows)((uint)mode | (uint)mod), reason);
|
ExitWindowsEx((ExitWindows) ((uint) mode | (uint) mod), reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,62 +7,6 @@ namespace CC_Functions.W32
|
|||||||
{
|
{
|
||||||
public static class Privileges
|
public static class Privileges
|
||||||
{
|
{
|
||||||
public static void EnablePrivilege(SecurityEntity securityEntity)
|
|
||||||
{
|
|
||||||
if (!Enum.IsDefined(typeof(SecurityEntity), securityEntity))
|
|
||||||
throw new InvalidEnumArgumentException("securityEntity", (int)securityEntity, typeof(SecurityEntity));
|
|
||||||
var securityEntityValue = securityEntity.ToString();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var locallyUniqueIdentifier = new NativeMethods.LUID();
|
|
||||||
if (NativeMethods.LookupPrivilegeValue(null, securityEntityValue, ref locallyUniqueIdentifier))
|
|
||||||
{
|
|
||||||
var TOKEN_PRIVILEGES = new NativeMethods.TOKEN_PRIVILEGES
|
|
||||||
{
|
|
||||||
PrivilegeCount = 1,
|
|
||||||
Attributes = NativeMethods.SE_PRIVILEGE_ENABLED,
|
|
||||||
Luid = locallyUniqueIdentifier
|
|
||||||
};
|
|
||||||
var tokenHandle = IntPtr.Zero;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var currentProcess = NativeMethods.GetCurrentProcess();
|
|
||||||
if (NativeMethods.OpenProcessToken(currentProcess, NativeMethods.TOKEN_ADJUST_PRIVILEGES | NativeMethods.TOKEN_QUERY, out tokenHandle))
|
|
||||||
{
|
|
||||||
if (NativeMethods.AdjustTokenPrivileges(tokenHandle, false, ref TOKEN_PRIVILEGES, 1024, IntPtr.Zero, IntPtr.Zero))
|
|
||||||
{
|
|
||||||
if (Marshal.GetLastWin32Error() == NativeMethods.ERROR_NOT_ALL_ASSIGNED)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("AdjustTokenPrivileges failed.", new Win32Exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("AdjustTokenPrivileges failed.", new Win32Exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "OpenProcessToken failed. CurrentProcess: {0}", currentProcess.ToInt32()), new Win32Exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (tokenHandle != IntPtr.Zero)
|
|
||||||
NativeMethods.CloseHandle(tokenHandle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "LookupPrivilegeValue failed. SecurityEntityValue: {0}", securityEntityValue), new Win32Exception());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "GrantPrivilege failed. SecurityEntity: {0}", securityEntityValue), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum SecurityEntity
|
public enum SecurityEntity
|
||||||
{
|
{
|
||||||
SeAssignPrimaryTokenPrivilege,
|
SeAssignPrimaryTokenPrivilege,
|
||||||
@ -143,19 +87,79 @@ namespace CC_Functions.W32
|
|||||||
SE_UNSOLICITED_INPUT_NAME_TEXT
|
SE_UNSOLICITED_INPUT_NAME_TEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SecurityEntity EntityToEntity(SecurityEntity2 entity) => (SecurityEntity)entity;
|
public static void EnablePrivilege(SecurityEntity securityEntity)
|
||||||
|
{
|
||||||
|
if (!Enum.IsDefined(typeof(SecurityEntity), securityEntity))
|
||||||
|
throw new InvalidEnumArgumentException("securityEntity", (int) securityEntity, typeof(SecurityEntity));
|
||||||
|
var securityEntityValue = securityEntity.ToString();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var locallyUniqueIdentifier = new NativeMethods.LUID();
|
||||||
|
if (NativeMethods.LookupPrivilegeValue(null, securityEntityValue, ref locallyUniqueIdentifier))
|
||||||
|
{
|
||||||
|
var TOKEN_PRIVILEGES = new NativeMethods.TOKEN_PRIVILEGES
|
||||||
|
{
|
||||||
|
PrivilegeCount = 1,
|
||||||
|
Attributes = NativeMethods.SE_PRIVILEGE_ENABLED,
|
||||||
|
Luid = locallyUniqueIdentifier
|
||||||
|
};
|
||||||
|
var tokenHandle = IntPtr.Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var currentProcess = NativeMethods.GetCurrentProcess();
|
||||||
|
if (NativeMethods.OpenProcessToken(currentProcess,
|
||||||
|
NativeMethods.TOKEN_ADJUST_PRIVILEGES | NativeMethods.TOKEN_QUERY, out tokenHandle))
|
||||||
|
{
|
||||||
|
if (NativeMethods.AdjustTokenPrivileges(tokenHandle, false, ref TOKEN_PRIVILEGES, 1024,
|
||||||
|
IntPtr.Zero, IntPtr.Zero))
|
||||||
|
{
|
||||||
|
if (Marshal.GetLastWin32Error() == NativeMethods.ERROR_NOT_ALL_ASSIGNED)
|
||||||
|
throw new InvalidOperationException("AdjustTokenPrivileges failed.",
|
||||||
|
new Win32Exception());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("AdjustTokenPrivileges failed.",
|
||||||
|
new Win32Exception());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
string.Format(CultureInfo.InvariantCulture,
|
||||||
|
"OpenProcessToken failed. CurrentProcess: {0}", currentProcess.ToInt32()),
|
||||||
|
new Win32Exception());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (tokenHandle != IntPtr.Zero)
|
||||||
|
NativeMethods.CloseHandle(tokenHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
string.Format(CultureInfo.InvariantCulture,
|
||||||
|
"LookupPrivilegeValue failed. SecurityEntityValue: {0}", securityEntityValue),
|
||||||
|
new Win32Exception());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
string.Format(CultureInfo.InvariantCulture, "GrantPrivilege failed. SecurityEntity: {0}",
|
||||||
|
securityEntityValue), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SecurityEntity EntityToEntity(SecurityEntity2 entity)
|
||||||
|
{
|
||||||
|
return (SecurityEntity) entity;
|
||||||
|
}
|
||||||
|
|
||||||
internal static class NativeMethods
|
internal static class NativeMethods
|
||||||
{
|
{
|
||||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
internal static extern bool LookupPrivilegeValue(string lpsystemname, string lpname, [MarshalAs(UnmanagedType.Struct)] ref LUID lpLuid);
|
|
||||||
|
|
||||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
|
||||||
internal static extern bool AdjustTokenPrivileges(IntPtr tokenhandle, [MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges,
|
|
||||||
[MarshalAs(UnmanagedType.Struct)]ref TOKEN_PRIVILEGES newstate, uint bufferlength, IntPtr previousState, IntPtr returnlength);
|
|
||||||
|
|
||||||
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
|
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
|
||||||
|
|
||||||
internal const int ERROR_NOT_ALL_ASSIGNED = 1300;
|
internal const int ERROR_NOT_ALL_ASSIGNED = 1300;
|
||||||
@ -171,17 +175,32 @@ namespace CC_Functions.W32
|
|||||||
internal const uint TOKEN_ADJUST_GROUPS = 0x0040;
|
internal const uint TOKEN_ADJUST_GROUPS = 0x0040;
|
||||||
internal const uint TOKEN_ADJUST_DEFAULT = 0x0080;
|
internal const uint TOKEN_ADJUST_DEFAULT = 0x0080;
|
||||||
internal const uint TOKEN_ADJUST_SESSIONID = 0x0100;
|
internal const uint TOKEN_ADJUST_SESSIONID = 0x0100;
|
||||||
internal const uint TOKEN_READ = (STANDARD_RIGHTS_READ | TOKEN_QUERY);
|
internal const uint TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY;
|
||||||
|
|
||||||
internal const uint TOKEN_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY
|
internal const uint TOKEN_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE |
|
||||||
| TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID;
|
TOKEN_IMPERSONATE | TOKEN_QUERY
|
||||||
|
| TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES |
|
||||||
|
TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID;
|
||||||
|
|
||||||
|
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
internal static extern bool LookupPrivilegeValue(string lpsystemname, string lpname,
|
||||||
|
[MarshalAs(UnmanagedType.Struct)] ref LUID lpLuid);
|
||||||
|
|
||||||
|
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
internal static extern bool AdjustTokenPrivileges(IntPtr tokenhandle,
|
||||||
|
[MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges,
|
||||||
|
[MarshalAs(UnmanagedType.Struct)] ref TOKEN_PRIVILEGES newstate, uint bufferlength,
|
||||||
|
IntPtr previousState, IntPtr returnlength);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
internal static extern IntPtr GetCurrentProcess();
|
internal static extern IntPtr GetCurrentProcess();
|
||||||
|
|
||||||
[DllImport("Advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("Advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
internal static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccesss, out IntPtr tokenHandle);
|
internal static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccesss,
|
||||||
|
out IntPtr tokenHandle);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
186
W32/Wnd32.cs
186
W32/Wnd32.cs
@ -15,56 +15,72 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
#region CreateInstance
|
#region CreateInstance
|
||||||
|
|
||||||
private Wnd32(IntPtr wndref) => hWnd = wndref;
|
private Wnd32(IntPtr wndref)
|
||||||
|
{
|
||||||
|
hWnd = wndref;
|
||||||
|
}
|
||||||
|
|
||||||
public static Wnd32 fromHandle(IntPtr handle) => new Wnd32(handle);
|
public static Wnd32 fromHandle(IntPtr handle)
|
||||||
|
{
|
||||||
|
return new Wnd32(handle);
|
||||||
|
}
|
||||||
|
|
||||||
public static Wnd32 fromMetadata(string lpClassName = null, string lpWindowName = null) => fromHandle(FindWindow(lpClassName, lpWindowName));
|
public static Wnd32 fromMetadata(string lpClassName = null, string lpWindowName = null)
|
||||||
|
{
|
||||||
|
return fromHandle(FindWindow(lpClassName, lpWindowName));
|
||||||
|
}
|
||||||
|
|
||||||
public static Wnd32 fromPoint(Point point) => fromHandle(WindowFromPoint(point.X, point.Y));
|
public static Wnd32 fromPoint(Point point)
|
||||||
|
{
|
||||||
|
return fromHandle(WindowFromPoint(point.X, point.Y));
|
||||||
|
}
|
||||||
|
|
||||||
public static Wnd32 fromForm(Form form) => fromHandle(form.Handle);
|
public static Wnd32 fromForm(Form form)
|
||||||
|
{
|
||||||
|
return fromHandle(form.Handle);
|
||||||
|
}
|
||||||
|
|
||||||
public static Wnd32 foreground() => fromHandle(GetForegroundWindow());
|
public static Wnd32 foreground()
|
||||||
|
{
|
||||||
|
return fromHandle(GetForegroundWindow());
|
||||||
|
}
|
||||||
|
|
||||||
public static Wnd32[] getVisible()
|
public static Wnd32[] getVisible()
|
||||||
{
|
{
|
||||||
WindowHandles = new List<IntPtr>();
|
WindowHandles = new List<IntPtr>();
|
||||||
if (!EnumDesktopWindows(IntPtr.Zero, FilterCallback, IntPtr.Zero))
|
if (!EnumDesktopWindows(IntPtr.Zero, FilterCallback, IntPtr.Zero))
|
||||||
{
|
|
||||||
throw new Win32Exception("There was a native error. This should never happen!");
|
throw new Win32Exception("There was a native error. This should never happen!");
|
||||||
}
|
return WindowHandles.Select(s => fromHandle(s)).ToArray();
|
||||||
else
|
|
||||||
{
|
|
||||||
return WindowHandles.Select(s => fromHandle(s)).ToArray();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion CreateInstance
|
#endregion CreateInstance
|
||||||
|
|
||||||
#region InstanceActions
|
#region InstanceActions
|
||||||
|
|
||||||
public string title
|
public string title
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
int length = GetWindowTextLength(hWnd);
|
{
|
||||||
StringBuilder sb = new StringBuilder(length + 1);
|
var length = GetWindowTextLength(hWnd);
|
||||||
|
var sb = new StringBuilder(length + 1);
|
||||||
GetWindowText(hWnd, sb, sb.Capacity);
|
GetWindowText(hWnd, sb, sb.Capacity);
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
set {
|
set => SetWindowText(hWnd, value);
|
||||||
SetWindowText(hWnd, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle position
|
public Rectangle position
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
RECT Rect = new RECT();
|
{
|
||||||
|
var Rect = new RECT();
|
||||||
GetWindowRect(hWnd, ref Rect);
|
GetWindowRect(hWnd, ref Rect);
|
||||||
return new Rectangle(new Point(Rect.left, Rect.top), new Size(Rect.right - Rect.left, Rect.bottom - Rect.top));
|
return new Rectangle(new Point(Rect.left, Rect.top),
|
||||||
|
new Size(Rect.right - Rect.left, Rect.bottom - Rect.top));
|
||||||
}
|
}
|
||||||
set {
|
set
|
||||||
RECT Rect = new RECT();
|
{
|
||||||
|
var Rect = new RECT();
|
||||||
GetWindowRect(hWnd, ref Rect);
|
GetWindowRect(hWnd, ref Rect);
|
||||||
MoveWindow(hWnd, value.X, value.Y, value.Width, value.Height, true);
|
MoveWindow(hWnd, value.X, value.Y, value.Width, value.Height, true);
|
||||||
}
|
}
|
||||||
@ -72,30 +88,27 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public bool isForeground
|
public bool isForeground
|
||||||
{
|
{
|
||||||
get {
|
get => GetForegroundWindow() == hWnd;
|
||||||
return GetForegroundWindow() == hWnd;
|
set
|
||||||
}
|
{
|
||||||
set {
|
|
||||||
if (value)
|
if (value)
|
||||||
SetForegroundWindow(hWnd);
|
SetForegroundWindow(hWnd);
|
||||||
else
|
else
|
||||||
throw new InvalidOperationException("You can't set a Window not to be in the foreground. Move another one over it!");
|
throw new InvalidOperationException(
|
||||||
|
"You can't set a Window not to be in the foreground. Move another one over it!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool enabled
|
public bool enabled
|
||||||
{
|
{
|
||||||
get {
|
get => IsWindowEnabled(hWnd);
|
||||||
return IsWindowEnabled(hWnd);
|
set => EnableWindow(hWnd, value);
|
||||||
}
|
|
||||||
set {
|
|
||||||
EnableWindow(hWnd, value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Icon icon
|
public Icon icon
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
|
{
|
||||||
var hicon = SendMessage(hWnd, 0x7F, 1, 0);
|
var hicon = SendMessage(hWnd, 0x7F, 1, 0);
|
||||||
if (hicon == IntPtr.Zero)
|
if (hicon == IntPtr.Zero)
|
||||||
hicon = SendMessage(hWnd, 0x7F, 0, 0);
|
hicon = SendMessage(hWnd, 0x7F, 0, 0);
|
||||||
@ -107,10 +120,9 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public bool shown
|
public bool shown
|
||||||
{
|
{
|
||||||
get {
|
get => IsWindowVisible(hWnd);
|
||||||
return IsWindowVisible(hWnd);
|
set
|
||||||
}
|
{
|
||||||
set {
|
|
||||||
if (value)
|
if (value)
|
||||||
ShowWindow(hWnd, 9);
|
ShowWindow(hWnd, 9);
|
||||||
else
|
else
|
||||||
@ -120,8 +132,9 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public string className
|
public string className
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
StringBuilder ClassName = new StringBuilder(256);
|
{
|
||||||
|
var ClassName = new StringBuilder(256);
|
||||||
_ = GetClassName(hWnd, ClassName, ClassName.Capacity);
|
_ = GetClassName(hWnd, ClassName, ClassName.Capacity);
|
||||||
return ClassName.ToString();
|
return ClassName.ToString();
|
||||||
}
|
}
|
||||||
@ -129,22 +142,17 @@ namespace CC_Functions.W32
|
|||||||
|
|
||||||
public FormWindowState state
|
public FormWindowState state
|
||||||
{
|
{
|
||||||
get {
|
get
|
||||||
int style = (int)GetWindowLong(hWnd, -16);
|
{
|
||||||
|
var style = GetWindowLong(hWnd, -16);
|
||||||
if ((style & 0x01000000) == 0x01000000)
|
if ((style & 0x01000000) == 0x01000000)
|
||||||
{
|
|
||||||
return FormWindowState.Maximized;
|
return FormWindowState.Maximized;
|
||||||
}
|
if ((style & 0x20000000) == 0x20000000)
|
||||||
else if ((style & 0x20000000) == 0x20000000)
|
|
||||||
{
|
|
||||||
return FormWindowState.Minimized;
|
return FormWindowState.Minimized;
|
||||||
}
|
return FormWindowState.Normal;
|
||||||
else
|
|
||||||
{
|
|
||||||
return FormWindowState.Normal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
set {
|
set
|
||||||
|
{
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
case FormWindowState.Minimized:
|
case FormWindowState.Minimized:
|
||||||
@ -162,13 +170,18 @@ namespace CC_Functions.W32
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MakeOverlay() => overlay = true;
|
public void MakeOverlay()
|
||||||
|
{
|
||||||
|
overlay = true;
|
||||||
|
}
|
||||||
|
|
||||||
public bool overlay
|
public bool overlay
|
||||||
{
|
{
|
||||||
set {
|
set
|
||||||
Rectangle tmp = position;
|
{
|
||||||
_ = SetWindowPos(hWnd, value ? HWND_TOPMOST : HWND_NOTOPMOST, tmp.X, tmp.Y, tmp.Width, tmp.Height, value ? SWP_NOMOVE | SWP_NOSIZE : 0);
|
var tmp = position;
|
||||||
|
_ = SetWindowPos(hWnd, value ? HWND_TOPMOST : HWND_NOTOPMOST, tmp.X, tmp.Y, tmp.Width, tmp.Height,
|
||||||
|
value ? SWP_NOMOVE | SWP_NOSIZE : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,23 +189,40 @@ namespace CC_Functions.W32
|
|||||||
{
|
{
|
||||||
if (DestroyWindow(hWnd))
|
if (DestroyWindow(hWnd))
|
||||||
return true;
|
return true;
|
||||||
else
|
throw new Exception("Failed.");
|
||||||
throw new Exception("Failed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool stillExists => IsWindow(hWnd);
|
public bool stillExists => IsWindow(hWnd);
|
||||||
|
|
||||||
public override string ToString() => hWnd.ToString() + "; " + title + "; " + position.ToString();
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return hWnd + "; " + title + "; " + position;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj) => Equals(obj as Wnd32);
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return Equals(obj as Wnd32);
|
||||||
|
}
|
||||||
|
|
||||||
public bool Equals(Wnd32 other) => other != null && EqualityComparer<IntPtr>.Default.Equals(hWnd, other.hWnd);
|
public bool Equals(Wnd32 other)
|
||||||
|
{
|
||||||
|
return other != null && EqualityComparer<IntPtr>.Default.Equals(hWnd, other.hWnd);
|
||||||
|
}
|
||||||
|
|
||||||
public override int GetHashCode() => -75345830 + EqualityComparer<IntPtr>.Default.GetHashCode(hWnd);
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return -75345830 + EqualityComparer<IntPtr>.Default.GetHashCode(hWnd);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool operator ==(Wnd32 left, Wnd32 right) => EqualityComparer<Wnd32>.Default.Equals(left, right);
|
public static bool operator ==(Wnd32 left, Wnd32 right)
|
||||||
|
{
|
||||||
|
return EqualityComparer<Wnd32>.Default.Equals(left, right);
|
||||||
|
}
|
||||||
|
|
||||||
public static bool operator !=(Wnd32 left, Wnd32 right) => !(left == right);
|
public static bool operator !=(Wnd32 left, Wnd32 right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion InstanceActions
|
#endregion InstanceActions
|
||||||
|
|
||||||
@ -241,17 +271,19 @@ namespace CC_Functions.W32
|
|||||||
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
||||||
private static readonly IntPtr HWND_TOP = new IntPtr(0);
|
private static readonly IntPtr HWND_TOP = new IntPtr(0);
|
||||||
private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
||||||
private const UInt32 SWP_NOSIZE = 0x0001;
|
private const uint SWP_NOSIZE = 0x0001;
|
||||||
private const UInt32 SWP_NOMOVE = 0x0002;
|
private const uint SWP_NOMOVE = 0x0002;
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy,
|
||||||
|
uint uFlags);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||||
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
|
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall,
|
||||||
|
ExactSpelling = true, SetLastError = true)]
|
||||||
private static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
|
private static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
|
||||||
|
|
||||||
private struct RECT
|
private struct RECT
|
||||||
@ -278,22 +310,24 @@ namespace CC_Functions.W32
|
|||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||||
|
|
||||||
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
|
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto,
|
||||||
private static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
|
SetLastError = true)]
|
||||||
|
private static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction,
|
||||||
|
IntPtr lParam);
|
||||||
|
|
||||||
// Define the callback delegate's type.
|
// Define the callback delegate's type.
|
||||||
private delegate bool EnumDelegate(IntPtr hWnd, int lParam);
|
private delegate bool EnumDelegate(IntPtr hWnd, int lParam);
|
||||||
|
|
||||||
private static List<IntPtr> WindowHandles;
|
private static List<IntPtr> WindowHandles;
|
||||||
|
|
||||||
private static bool FilterCallback(IntPtr hWnd, int lParam)
|
private static bool FilterCallback(IntPtr hWnd, int lParam)
|
||||||
{
|
{
|
||||||
StringBuilder sb_title = new StringBuilder(1024);
|
var sb_title = new StringBuilder(1024);
|
||||||
GetWindowText(hWnd, sb_title, sb_title.Capacity);
|
GetWindowText(hWnd, sb_title, sb_title.Capacity);
|
||||||
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(sb_title.ToString()) == false)
|
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(sb_title.ToString()) == false) WindowHandles.Add(hWnd);
|
||||||
{
|
|
||||||
WindowHandles.Add(hWnd);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion W32
|
#endregion W32
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user