How to convert HWND to IWin32Window? (Why the 64-bit is not available?)

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:24.0pt; font-family:Tahoma,sans-serif C# <span style="font-size:10.0pt; font-family:Tahoma,sans-serif
<span style="font-size:9.5pt; font-family:Consolas; color:blue using<span style="font-size:9.5pt; font-family:Consolas System;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue using<span style="font-size:9.5pt; font-family:Consolas System.Windows.Forms;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue namespace<span style="font-size:9.5pt; font-family:Consolas WindowsFormsApplication1
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:blue public <span style="color:blue class <span style="color:#2B91AF
Program
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:blue public <span style="color:blue static
<span style="color:blue void Message(<span style="color:#2B91AF IWin32Window owner,
<span style="color:blue string Text)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
{
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:green // The aim is to convert a HWND to a IWin32Window
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span> <span style="color:#2B91AF MessageBox.Show(owner, Text);
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
}
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
}
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:10.0pt; font-family:Tahoma,sans-serif <span style="font-size:24.0pt; font-family:Tahoma,sans-serif C++ <span style="font-size:10.0pt; font-family:Tahoma,sans-serif
<span style="font-size:9.5pt; font-family:Consolas; color:blue using<span style="font-size:9.5pt; font-family:Consolas
<span style="color:blue namespace System;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue void<span style="font-size:9.5pt; font-family:Consolas Test(HWND hWnd)
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas {
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #if<span style="font-size:9.5pt; font-family:Consolas 0
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:gray <span>
Windows::Forms::IWin32Window ^owner = hWnd;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:#8DB3E2 #error <span style="color:gray "error C2440: initializing : cannot convert from HWND to System::Windows::Forms::IWin32Window ^"
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #else
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
Windows::Forms::IWin32Window ^owner = *(Windows::Forms::IWin32Window ^ *)&hWnd;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:green // I use Windows 32-bit, but if I will use Windows 64-bit
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:green // then (sizeof(hWnd) == 2*sizeof(int)).
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:green <span>
<span> // IWin32Window is always 32-bit i.e. one int, "Can you explain me something?"
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas; color:blue #endif
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
WindowsFormsApplication1::Program Program;
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
Program.Message(owner, <span style="color:#A31515 "This is a text");
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas <span>
<span style="color:green // The application crashes! "Can you solve the problem?".
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas }
<p style="margin-bottom:0in; margin-bottom:.0001pt; line-height:normal; text-autospace:none
<span style="font-size:9.5pt; font-family:Consolas

View the full article
 
Back
Top