-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Beeper and LineDemo from WInterop
- Loading branch information
1 parent
7ece471
commit 1bd452e
Showing
13 changed files
with
352 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\thirtytwo\thirtytwo.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Drawing; | ||
using Windows; | ||
using Windows.Win32; | ||
using Windows.Win32.Foundation; | ||
using Windows.Win32.Graphics.Gdi; | ||
using Windows.Win32.UI.WindowsAndMessaging; | ||
|
||
namespace Beeper; | ||
|
||
internal class Beeper1 : MainWindow | ||
{ | ||
private bool _flipFlop = false; | ||
private nuint _timerId; | ||
|
||
public Beeper1(string title) : base(title) { } | ||
|
||
protected override LRESULT WindowProcedure(HWND window, MessageType message, WPARAM wParam, LPARAM lParam) | ||
{ | ||
switch (message) | ||
{ | ||
case MessageType.Create: | ||
_timerId = window.SetTimer(1000); | ||
return (LRESULT)0; | ||
case MessageType.Timer: | ||
Interop.MessageBeep(MESSAGEBOX_STYLE.MB_OK); | ||
_flipFlop = !_flipFlop; | ||
window.Invalidate(); | ||
return (LRESULT)0; | ||
case MessageType.Paint: | ||
using (DeviceContext dc = window.BeginPaint()) | ||
{ | ||
using HBRUSH brush = HBRUSH.CreateSolid(_flipFlop ? Color.Red : Color.Blue); | ||
dc.FillRectangle(window.GetClientRectangle(), brush); | ||
} | ||
return (LRESULT)0; | ||
case MessageType.Destroy: | ||
window.KillTimer(_timerId); | ||
break; | ||
} | ||
|
||
return base.WindowProcedure(window, message, wParam, lParam); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Drawing; | ||
using Windows; | ||
using Windows.Win32; | ||
using Windows.Win32.Foundation; | ||
using Windows.Win32.Graphics.Gdi; | ||
using Windows.Win32.UI.WindowsAndMessaging; | ||
|
||
namespace Beeper; | ||
|
||
internal class Beeper2 : MainWindow | ||
{ | ||
private bool _flipFlop = false; | ||
private nuint _timerId; | ||
private TimerProcedure? _timerCallback; | ||
|
||
public Beeper2(string title) : base(title) { } | ||
|
||
protected override LRESULT WindowProcedure(HWND window, MessageType message, WPARAM wParam, LPARAM lParam) | ||
{ | ||
switch (message) | ||
{ | ||
case MessageType.Create: | ||
_timerCallback = TimerProcedure; | ||
_timerId = window.SetTimer(1000, callback: _timerCallback); | ||
return (LRESULT)0; | ||
case MessageType.Destroy: | ||
window.KillTimer(_timerId); | ||
break; | ||
} | ||
|
||
return base.WindowProcedure(window, message, wParam, lParam); | ||
} | ||
|
||
private void TimerProcedure(HWND window, MessageType message, nuint timerId, uint time) | ||
{ | ||
Interop.MessageBeep(MESSAGEBOX_STYLE.MB_OK); | ||
_flipFlop = !_flipFlop; | ||
using DeviceContext dc = window.GetDeviceContext(); | ||
using HBRUSH brush = HBRUSH.CreateSolid(_flipFlop ? Color.Red : Color.Blue); | ||
dc.FillRectangle(window.GetClientRectangle(), brush); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Windows; | ||
|
||
namespace Beeper; | ||
|
||
/// <summary> | ||
/// Samples from Programming Windows, 5th Edition. | ||
/// Original (c) Charles Petzold, 1998 | ||
/// </summary> | ||
internal static class Program | ||
{ | ||
[STAThread] | ||
private static void Main() | ||
{ | ||
// Figure 8-1, Pages 331-333. | ||
Application.Run(new Beeper1("Timer on Message Loop")); | ||
|
||
// Figure 8-2, Pages 335-337. | ||
Application.Run(new Beeper2("Timer Procedure")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\thirtytwo\thirtytwo.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Drawing; | ||
using Windows; | ||
using Windows.Win32.Foundation; | ||
|
||
namespace LineDemo; | ||
|
||
/// <summary> | ||
/// Sample from Programming Windows, 5th Edition. | ||
/// Original (c) Charles Petzold, 1998 | ||
/// Figure 5-14, Pages 153-155. | ||
/// </summary> | ||
internal static class Program | ||
{ | ||
[STAThread] | ||
private static void Main() => Application.Run(new LineDemo("LineDemo")); | ||
|
||
private class LineDemo : MainWindow | ||
{ | ||
private static int s_cxClient, s_cyClient; | ||
|
||
public LineDemo(string title) : base(title) { } | ||
|
||
protected override LRESULT WindowProcedure(HWND window, MessageType message, WPARAM wParam, LPARAM lParam) | ||
{ | ||
switch (message) | ||
{ | ||
case MessageType.Size: | ||
s_cxClient = lParam.LOWORD; | ||
s_cyClient = lParam.HIWORD; | ||
return (LRESULT)0; | ||
case MessageType.Paint: | ||
using (DeviceContext dc = window.BeginPaint()) | ||
{ | ||
dc.Rectangle(s_cxClient / 8, s_cyClient / 8, 7 * s_cxClient / 8, 7 * s_cyClient / 8); | ||
dc.MoveTo(0, 0); | ||
dc.LineTo(s_cxClient, s_cyClient); | ||
dc.MoveTo(0, s_cyClient); | ||
dc.LineTo(s_cxClient, 0); | ||
dc.Ellipse(s_cxClient / 8, s_cyClient / 8, 7 * s_cxClient / 8, 7 * s_cyClient / 8); | ||
dc.RoundRectangle( | ||
Rectangle.FromLTRB(s_cxClient / 4, s_cyClient / 4, 3 * s_cxClient / 4, 3 * s_cyClient / 4), | ||
new Size(s_cxClient / 4, s_cyClient / 4)); | ||
} | ||
|
||
return (LRESULT)0; | ||
} | ||
|
||
return base.WindowProcedure(window, message, wParam, lParam); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.