Skip to content

Commit ba1cd38

Browse files
committed
Added q76181152
0 parents  commit ba1cd38

15 files changed

+330
-0
lines changed

q76181152/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
The fact that your controls are windowless, doesn't prevent you from doing that. You just have to ensure that you are sending the messages to the container window (the one that has its `hWnd` handle).
2+
3+
I tested the following code on VB6 app with windowless button. For me it simulates the click even for minimized window. The trick is to first send `WM_ACTIVATE` message, then `WM_LBUTTONDOWN/UP pair`:
4+
5+
```
6+
using System.Runtime.InteropServices;
7+
8+
// Win32 API definitions
9+
[DllImport("user32.dll", EntryPoint = "FindWindow")]
10+
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
11+
12+
[DllImport("user32.dll")]
13+
static extern int PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
14+
15+
16+
const uint WM_ACTIVATE = 0x0006;
17+
const uint WM_LBUTTONDOWN = 0x201;
18+
const uint WM_LBUTTONUP = 0x202;
19+
20+
const int MK_LBUTTON = 1;
21+
22+
const int WA_ACTIVE = 1;
23+
24+
int MAKELPARAM(int p, int p_2)
25+
{
26+
return ((p_2 << 16) | (p & 0xFFFF));
27+
}
28+
29+
// The code
30+
IntPtr hWnd = FindWindowByCaption(IntPtr.Zero, "Form1");
31+
32+
Thread.Sleep(3000);
33+
34+
PostMessage(hWnd, WM_ACTIVATE, WA_ACTIVE, 0);
35+
36+
int lParam = MAKELPARAM(62, 68); // Button coordinates relative to window "client area"
37+
PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, lParam);
38+
PostMessage(hWnd, WM_LBUTTONUP, 0, lParam);
39+
40+
```
41+
42+
See [this repo](https://github.com/vvv444/stackoverflow/q76181152/`) for working code example.
43+
Run `WLTest.exe` and minimize it's window. Then run the C# code and ensure the counter indeed increments in the VB6 window.

q76181152/bin/LTWTCT98.CHI

13.4 KB
Binary file not shown.

q76181152/bin/LTWTCT98.CHM

16.7 KB
Binary file not shown.

q76181152/bin/LTWTCT98.chw

23.9 KB
Binary file not shown.

q76181152/bin/MSWLESS.DEP

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
2+
; Dependency file for setup wizards.
3+
4+
[Version]
5+
Version=6.0.81.69
6+
7+
; Dependencies for MSWLess.ocx
8+
9+
; Default Dependencies ----------------------------------------------
10+
11+
[MSWLess.ocx]
12+
Dest=$(WinSysPath)
13+
Register=$(DLLSelfRegister)
14+
Version=6.0.81.69
15+
Uses1=ComCat.dll
16+
Uses2=
17+
CABFileName=MSWLess.cab
18+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
19+
CABINFFile=MSWLess.inf
20+
21+
[ComCat.dll]
22+
Dest=$(WinSysPathSysFile)
23+
Register=$(DLLSelfRegister)
24+
Uses1=
25+
26+
; Localized Dependencies --------------------------------------------
27+
28+
; ** German (DE) ***
29+
; (0007 = German)
30+
;
31+
[MSWLess.ocx <0007>]
32+
Uses1=MSWLsDE.dll
33+
Uses2=
34+
35+
[MSWLsDE.dll <0007>]
36+
Uses1=
37+
CABFileName=MSWLsDE.cab
38+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
39+
CABINFFile=MSWLsDE.inf
40+
41+
; ** French (FR) ***
42+
; (000C = French)
43+
;
44+
[MSWLess.ocx <000C>]
45+
Uses1=MSWLsFR.dll
46+
Uses2=
47+
48+
[MSWLsFR.dll <000C>]
49+
Uses1=
50+
CABFileName=MSWLsFR.cab
51+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
52+
CABINFFile=MSWLsFR.inf
53+
54+
; ** Italian (IT) ***
55+
; (0010 = Italian)
56+
;
57+
[MSWLess.ocx <0010>]
58+
Uses1=MSWLsIT.dll
59+
Uses2=
60+
61+
[MSWLsIT.dll <0010>]
62+
Uses1=
63+
CABFileName=MSWLsIT.cab
64+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
65+
CABINFFile=MSWLsIT.inf
66+
67+
; ** Spanish (ES) ***
68+
; (000A = Spanish)
69+
;
70+
[MSWLess.ocx <000A>]
71+
Uses1=MSWLsES.dll
72+
Uses2=
73+
74+
[MSWLsES.dll <000A>]
75+
Uses1=
76+
CABFileName=MSWLsES.cab
77+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
78+
CABINFFile=MSWLsES.inf
79+
80+
; ** Japanese (JP) ***
81+
; (0011 = Japanese)
82+
;
83+
[MSWLess.ocx <0011>]
84+
Uses1=MSWLsJP.dll
85+
Uses2=
86+
87+
[MSWLsJP.dll <0011>]
88+
Uses1=
89+
CABFileName=MSWLsJP.cab
90+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
91+
CABINFFile=MSWLsJP.inf
92+
93+
; ** Korean (KO) ***
94+
; (0012 = Korean)
95+
;
96+
[MSWLess.ocx <0012>]
97+
Uses1=MSWLsKO.dll
98+
Uses2=
99+
100+
[MSWLsKO.dll <0012>]
101+
Uses1=
102+
CABFileName=MSWLsKO.cab
103+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
104+
CABINFFile=MSWLsKO.inf
105+
106+
; ** Chinese Traditional (CHT) ***
107+
; (0404 = Chinese Traditional)
108+
;
109+
[MSWLess.ocx <0404>]
110+
Uses1=MSWLsCHT.dll
111+
Uses2=
112+
113+
[MSWLsCHT.dll <0404>]
114+
Uses1=
115+
CABFileName=MSWLsCHT.cab
116+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
117+
CABINFFile=MSWLsCHT.inf
118+
119+
; ** Chinese Simplified (CHS) ***
120+
; (0804 = Chinese Simplified)
121+
;
122+
[MSWLess.ocx <0804>]
123+
Uses1=MSWLsCHS.dll
124+
Uses2=
125+
126+
[MSWLsCHS.dll <0804>]
127+
Uses1=
128+
CABFileName=MSWLsCHS.cab
129+
CABDefaultURL=http://activex.microsoft.com/controls/vb6
130+
CABINFFile=MSWLsCHS.inf
131+

q76181152/bin/MSWLESS.OCX

378 KB
Binary file not shown.

q76181152/bin/MSWLESS.REG

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REGEDIT
2+
HKEY_CLASSES_ROOT\Licenses = Licensing: Copying the keys may be a violation of established copyrights.
3+
4+
HKEY_CLASSES_ROOT\Licenses\80E80EF0-DBBE-11D0-BCE2-00A0C90DCA10 = qijimitpmpnpxplpvjnikpkpqoxjmpkpoivj

q76181152/bin/MSWLESS.oca

216 KB
Binary file not shown.

q76181152/bin/WLTest.exe

20 KB
Binary file not shown.

q76181152/cs_code/CsTest.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>

q76181152/cs_code/CsTest.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33530.505
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsTest", "CsTest.csproj", "{7BA43375-2B91-414B-B51B-89415CBD80E7}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{7BA43375-2B91-414B-B51B-89415CBD80E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7BA43375-2B91-414B-B51B-89415CBD80E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7BA43375-2B91-414B-B51B-89415CBD80E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7BA43375-2B91-414B-B51B-89415CBD80E7}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2D784C01-B36A-499B-A1E1-808089897F5D}
24+
EndGlobalSection
25+
EndGlobal

q76181152/cs_code/Program.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Runtime.InteropServices;
2+
3+
// Win32 API definitions
4+
[DllImport("user32.dll", EntryPoint = "FindWindow")]
5+
static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
6+
7+
[DllImport("user32.dll")]
8+
static extern int PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
9+
10+
11+
const uint WM_ACTIVATE = 0x0006;
12+
const uint WM_LBUTTONDOWN = 0x201;
13+
const uint WM_LBUTTONUP = 0x202;
14+
15+
const int MK_LBUTTON = 1;
16+
17+
const int WA_ACTIVE = 1;
18+
19+
int MAKELPARAM(int p, int p_2)
20+
{
21+
return ((p_2 << 16) | (p & 0xFFFF));
22+
}
23+
24+
// The code
25+
IntPtr hWnd = FindWindowByCaption(IntPtr.Zero, "Form1");
26+
27+
Thread.Sleep(3000);
28+
29+
PostMessage(hWnd, WM_ACTIVATE, WA_ACTIVE, 0);
30+
31+
int lParam = MAKELPARAM(62, 68); // Button coordinates relative to window "client area"
32+
PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, lParam);
33+
PostMessage(hWnd, WM_LBUTTONUP, 0, lParam);

q76181152/vb_code/Form1.frm

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
VERSION 5.00
2+
Object = "{CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0"; "MSWLESS.OCX"
3+
Begin VB.Form Form1
4+
Caption = "Form1"
5+
ClientHeight = 3135
6+
ClientLeft = 60
7+
ClientTop = 405
8+
ClientWidth = 4680
9+
LinkTopic = "Form1"
10+
ScaleHeight = 3135
11+
ScaleWidth = 4680
12+
StartUpPosition = 3 'Windows Default
13+
Begin MSWLess.WLText WLText1
14+
Height = 1695
15+
Left = 2400
16+
TabIndex = 1
17+
Top = 480
18+
Width = 1815
19+
_ExtentX = 3201
20+
_ExtentY = 2990
21+
_Version = 393216
22+
Text = "0"
23+
ForeColor = -2147483640
24+
BackColor = -2147483643
25+
BorderStyle = 1
26+
Appearance = 1
27+
End
28+
Begin MSWLess.WLCommand WLCommand1
29+
Height = 735
30+
Left = 240
31+
TabIndex = 0
32+
Top = 600
33+
Width = 1815
34+
_ExtentX = 3201
35+
_ExtentY = 1296
36+
_Version = 393216
37+
Caption = "WL Increment"
38+
ForeColor = -1
39+
BackColor = -2147483633
40+
Appearance = 1
41+
End
42+
End
43+
Attribute VB_Name = "Form1"
44+
Attribute VB_GlobalNameSpace = False
45+
Attribute VB_Creatable = False
46+
Attribute VB_PredeclaredId = True
47+
Attribute VB_Exposed = False
48+
Private Sub WLCommand1_Click()
49+
WLText1.Text = CInt(WLText1.Text) + 1
50+
End Sub

q76181152/vb_code/WLTest.vbp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Type=Exe
2+
Form=Form1.frm
3+
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
4+
Object={CFC13920-9EF4-11D0-B72F-0000C04D4C0A}#6.0#0; MSWLESS.OCX
5+
IconForm="Form1"
6+
Startup="Form1"
7+
HelpFile=""
8+
Title="WLTest"
9+
ExeName32="WLTest.exe"
10+
Command32=""
11+
Name="WLTest"
12+
HelpContextID="0"
13+
CompatibleMode="0"
14+
MajorVer=1
15+
MinorVer=0
16+
RevisionVer=0
17+
AutoIncrementVer=0
18+
ServerSupportFiles=0
19+
CompilationType=0
20+
OptimizationType=0
21+
FavorPentiumPro(tm)=0
22+
CodeViewDebugInfo=0
23+
NoAliasing=0
24+
BoundsCheck=0
25+
OverflowCheck=0
26+
FlPointCheck=0
27+
FDIVCheck=0
28+
UnroundedFP=0
29+
StartMode=0
30+
Unattended=0
31+
Retained=0
32+
ThreadPerObject=0
33+
MaxNumberOfThreads=1

q76181152/vb_code/WLTest.vbw

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Form1 = 180, 176, 1004, 716, , 26, 26, 1113, 566, C

0 commit comments

Comments
 (0)