How to Activate A Control Added to Desktop
-
I have Created A ListBox Control Whose Handle is Desktop. My code for ListBox: #using using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System:ata; using namespace System:rawing; using namespace System::Runtime::InteropServices; using namespace System::Security::Permissions; namespace DeskTopTest { /// /// Summary for MyListBox /// // Requires unmanaged code [assembly: SecurityPermissionAttribute (SecurityAction::RequestMinimum, UnmanagedCode=true)]; // Requires ability to create any window type [assembly:UIPermissionAttribute(SecurityAction::RequestMinimum, Window=UIPermissionWindow::AllWindows)]; public ref class MyListBox : public ListBox { public: MyListBox(void) { } protected: virtual property System::Windows::Forms::CreateParams^ CreateParams { virtual System::Windows::Forms::CreateParams^ get() override { const int WS_EX_TOOLWINDOW = 0x00000080; const int WS_EX_NOACTIVATE = 0x08000000; const int WS_EX_TOPMOST = 0x00000008; try { System::Windows::Forms::CreateParams ^p =ListBox::CreateParams; p->ExStyle |= (WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST); p->Parent = IntPtr::Zero; return p; } catch (Exception^ e) { return nullptr; } } } public:[DllImport("user32.dll")] static int SetParent( IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll")] static int ShowWindow( IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] static IntPtr GetDesktopWindow(void); public: void ShowFloating() { if (this->Handle == IntPtr::Zero) { ListBox::CreateControl(); } //IntPtr s=GetDesktopWindow(); int x=SetParent(ListBox::Handle, IntPtr::Zero); x=ShowWindow(ListBox::Handle,1); } protected: virtual void WndProc(Message% m)override { ListBox::WndProc(m); } }; } but when i Added this listbox to my form like: MyListBox ^lst=gcnew MyListBox(); lst->Location=System:rawing::Point(264, 166); lst->Name = L"comboBox1"; lst->TabIndex = 1; lst->Visible=false; lst->Size = System:rawing::Size(171, 200); for (UInt16 i=1;i<100;i++) { lst->Items->Add("Item"+i.ToString()); } lst->ShowFloating(); and calling the function ShowFloating(); It is working fine. But I cant unable to focus On my Listbox & can