Skip to content

Commit f16c321

Browse files
committed
Enable-Disable of controls.
Listbox Scrollbar.
1 parent f349c92 commit f16c321

File tree

10 files changed

+136
-34
lines changed

10 files changed

+136
-34
lines changed

Src/ConsleCaller/ConsleCaller.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<PropertyGroup>
1212
<OutputType>WinExe</OutputType>
13-
<TargetFramework>netcoreapp3.0</TargetFramework>
13+
<TargetFramework>netcoreapp2.2</TargetFramework>
1414
<ApplicationIcon />
1515
<StartupObject />
1616
<ApplicationManifest>app.manifest</ApplicationManifest>

Src/ConsleCaller/Window1.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected override void InitControls()
127127

128128
this._ListBox = new NativeListBox();
129129
this._ListBox.Left = 300;
130-
this._ListBox.Top = 90;
130+
this._ListBox.Top = 200;
131131
this._ListBox.Width = 400;
132132
this._ListBox.Height = 400;
133133
this._ListBox.BackColor = ColorTool.Yellow;
@@ -216,17 +216,24 @@ private void button_OnClicked(object sender, EventArgs e)
216216
{
217217
MessageBox.Show("Button Clicked!");
218218
this._ListBox.Clear();
219+
this._Bitmap.Width = this._Bitmap.Width- 10;
220+
this._Bitmap.Refresh();
221+
this._Button.Enabled = false;
219222
}
220223

221224
private void Window1_Create(object sender, CreateEventArgs e)
222225
{
223-
this._Button.Text = "halllo";
226+
this._Button.Text = "hallo";
224227
this._Bitmap.Refresh();
225228
//MessageBox.Show("OnCreate");
226229
//this._Timer.ParentHandle = this.Handle;
227230
this._Timer.StartTimer();
228231
this._ListBox.AddText("hallo");
229-
this._ListBox.AddText("wert");
232+
this._ListBox.AddText("welt");
233+
for(int i = 1; i< 100;i++)
234+
{
235+
this._ListBox.AddText("welt" + i);
236+
}
230237
}
231238

232239
private void Window1_DblClick(object sender, MouseClickEventArgs e)

Src/CoreWindowsWrapper/Api/Win32/Win32Api.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ public static extern sbyte GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilte
101101
[DllImport("user32.dll", EntryPoint = "LoadImageW")]
102102
public static extern IntPtr LoadImage([In()] IntPtr hInst, [In()] [MarshalAs(UnmanagedType.LPWStr)] string name, uint type, int cx, int cy, uint fuLoad);
103103

104+
/// Return Type: BOOL->int
105+
///hWnd: HWND->HWND__*
106+
///X: int
107+
///Y: int
108+
///nWidth: int
109+
///nHeight: int
110+
///bRepaint: BOOL->int
111+
[DllImport("user32.dll", EntryPoint = "MoveWindow")]
112+
[return: MarshalAs(UnmanagedType.Bool)]
113+
public static extern bool MoveWindow([In()] IntPtr hWnd, int X, int Y, int nWidth, int nHeight, [MarshalAs(UnmanagedType.Bool)] bool bRepaint);
114+
115+
116+
/// Return Type: BOOL->int
117+
///hWnd: HWND->HWND__*
118+
///bEnable: BOOL->int
119+
[DllImport("user32.dll", EntryPoint = "EnableWindow")]
120+
[return: MarshalAs(UnmanagedType.Bool)]
121+
public static extern bool EnableWindow([In()] System.IntPtr hWnd, [MarshalAs(UnmanagedType.Bool)] bool bEnable);
104122

105123

106124
[DllImport("user32.dll")]

Src/CoreWindowsWrapper/CoreWindowsWrapper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<PropertyGroup>
12-
<TargetFramework>netcoreapp3.0</TargetFramework>
12+
<TargetFramework>netcoreapp2.2</TargetFramework>
1313
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1414
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1515
<Authors>Dipl.-Ing.(FH) Guido Agnesmeyer</Authors>

Src/CoreWindowsWrapper/IControl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ internal interface IControl:IWindow
1414
int Top { get; set; }
1515
int Width { get; set; }
1616
int Height { get; set; }
17+
bool Enabled{get;set;}
1718
Point Location { get; set; }
1819
int ControlId { get; set; }
1920
bool ClientEdge{get;set;}

Src/CoreWindowsWrapper/NativeControlBase.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,28 @@ public Font Font
145145
get
146146
{
147147
Font f = this._Font;
148-
if(this.Control!= null)
148+
if (this.Control != null)
149149
{
150150
f = this.Control.Font;
151-
if(!f.Equals(this._Font))
151+
if (!f.Equals(this._Font))
152152
{
153153
this._Font = f;
154154
}
155155
}
156156
return f;
157157
}
158158
set
159-
{
159+
{
160160
this._Font = value;
161-
if(this.Control!= null)
161+
if (this.Control != null)
162162
{
163163
this.Control.Font = this._Font;
164164
}
165-
165+
166166
}
167167
}
168168

169-
169+
170170

171171
public virtual bool Create(IntPtr parentId)
172172
{
@@ -199,5 +199,11 @@ public virtual void Destroy()
199199
{
200200
Console.Write("on Destroy");
201201
}
202+
203+
public bool Enabled
204+
{
205+
get => this.Control.Enabled;
206+
set => this.Control.Enabled = value;
207+
}
202208
}
203209
}

Src/CoreWindowsWrapper/NativeListBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ protected override void Initialize()
99
base.Initialize();
1010
this.TypeIdentifier = "listbox";
1111
this.ClientEdge = true;
12-
//this.Style = this.Style | (int)WindowStyles.WS_VSCROLL | EditBoxStyles.ES_AUTOVSCROLL;
12+
this.Style = this.Style | (int)WindowStyles.WS_VSCROLL | (int)WindowStyles.WS_HSCROLL | EditBoxStyles.ES_AUTOVSCROLL;
1313

1414
}
1515

Src/CoreWindowsWrapper/NativeWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ bool IControl.Create(IntPtr parentId)
131131
}
132132

133133
bool IControl.ClientEdge{get=>throw new NotImplementedException(); set=> throw new NotImplementedException();}
134-
134+
public bool Enabled { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
135135

136136
public bool HandleEvents(IntPtr hWndParent, IntPtr hWndControl, int controlId, uint command, IntPtr wParam, IntPtr lParam)
137137
{

Src/CoreWindowsWrapper/Win32ApiForm/Win32Control.cs

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,99 @@ namespace CoreWindowsWrapper.Win32ApiForm
55
{
66
internal class Win32Control : IWindowClass
77
{
8-
9-
public static int LastControlId{get;set;} = 500;
8+
9+
public static int LastControlId { get; set; } = 500;
1010
public IntPtr Handle { get; protected set; }
1111
public IntPtr ParentHandle { get; internal set; }
1212
public string Text { get; set; }
1313
public string Name { get; set; }
1414
public Point Location { get; set; }
15-
public int Left { get; set; }
16-
public int Top { get; set; }
17-
public int Width { get; set; }
18-
public int Height { get; set; }
19-
public bool ClientEdge{get;set;}
15+
private bool _Enabled = true;
16+
public bool Enabled
17+
{
18+
get
19+
{
20+
return this._Enabled;
21+
}
22+
set
23+
{
24+
this._Enabled = value;
25+
if(this.Handle != IntPtr.Zero)
26+
{
27+
Win32Api.EnableWindow(this.Handle, this._Enabled);
28+
}
29+
}
30+
}
31+
public int Left
32+
{
33+
get
34+
{
35+
return this._Left;
36+
}
37+
set
38+
{
39+
this._Left = value;
40+
MoveMyWindow();
41+
42+
}
43+
}
44+
public int Top
45+
{
46+
get
47+
{
48+
return this._Top;
49+
}
50+
set
51+
{
52+
this._Top = value;
53+
MoveMyWindow();
54+
}
55+
}
56+
public int Width
57+
{
58+
get
59+
{
60+
return this._Width;
61+
}
62+
set
63+
{
64+
this._Width = value;
65+
MoveMyWindow();
66+
}
67+
}
68+
public int Height
69+
{
70+
get
71+
{
72+
return this._Height;
73+
}
74+
set
75+
{
76+
this._Height = value;
77+
MoveMyWindow();
78+
}
79+
}
80+
public bool ClientEdge { get; set; }
2081
public string TypeIdentifyer { get; set; }
2182
public int ControlId { get; set; }
2283
public int BackColor { get; set; }
23-
public int ForeColor{get;set;}
24-
public Font Font{get;set;}
84+
public int ForeColor { get; set; }
85+
public Font Font { get; set; }
2586
public CommonControls CommonControType { get; set; } = CommonControls.ICC_UNDEFINED;
2687
public uint Style { get; set; } =
2788
(WindowStylesConst.WS_VISIBLE | WindowStylesConst.WS_CHILD | WindowStylesConst.WS_TABSTOP);
2889

2990
private readonly WndProc _DelegateWndProc = MyWndProc;
91+
private int _Left;
92+
private int _Top;
93+
private int _Width;
94+
private int _Height;
3095

96+
private void MoveMyWindow()
97+
{
98+
if (this.Handle == IntPtr.Zero) return;
99+
Win32Api.MoveWindow(this.Handle, this.Left, this.Top, this.Width, this.Height, true);
100+
}
31101
private static IntPtr MyWndProc(IntPtr hwnd, uint msg, IntPtr wparam, IntPtr lparam)
32102
{
33103
return Win32Api.DefWindowProc(hwnd, msg, wparam, lparam);
@@ -46,29 +116,29 @@ internal virtual bool Create(IntPtr parentHandle)
46116
Win32Api.InitCommonControlsEx(ref ccInit);
47117
}
48118
this.ParentHandle = parentHandle;
49-
119+
50120
int ediged = 0;
51-
if(this.ClientEdge)
52-
ediged =(int)WindowStyles.WS_EX_CLIENTEDGE;
121+
if (this.ClientEdge)
122+
ediged = (int)WindowStyles.WS_EX_CLIENTEDGE;
53123

54-
this.Handle = Win32Api.CreateWindowEx(ediged,
55-
this.TypeIdentifyer , this.Text,
56-
this.Style, this.Left ,
124+
this.Handle = Win32Api.CreateWindowEx(ediged,
125+
this.TypeIdentifyer, this.Text,
126+
this.Style, this.Left,
57127
this.Top,
58128
this.Width, this.Height, this.ParentHandle,
59-
(IntPtr) this.ControlId, IntPtr.Zero, IntPtr.Zero);
129+
(IntPtr)this.ControlId, IntPtr.Zero, IntPtr.Zero);
60130

61-
if(this.Font != null)
131+
if (this.Font != null)
62132
{
63133

64134
this.Font.FromLogFont(this.Handle);
65135

66-
LOGFONTW f = this.Font.ToLogFont(this.Handle);
136+
LOGFONTW f = this.Font.ToLogFont(this.Handle);
67137
IntPtr hFont = Win32Api.CreateFontIndirect(ref f);
68-
IntPtr retVal = Win32Api.SendMessage(this.Handle,WindowsMessages.WM_SETFONT,hFont,0);
138+
IntPtr retVal = Win32Api.SendMessage(this.Handle, WindowsMessages.WM_SETFONT, hFont, 0);
69139

70140
}
71-
141+
72142
return true;
73143

74144
}

Src/DIGAAppSetup/DIGAAppSetup.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
66
<ApplicationIcon>Firmen_Emblem.ico</ApplicationIcon>
77
<StartupObject>DIGAAppSetup.Program</StartupObject>
88
<ApplicationManifest>app.manifest</ApplicationManifest>

0 commit comments

Comments
 (0)