Bootstrap

创建类似软键盘的无焦点对话框程序

如果想创建一个类似windows里的屏幕键盘式的程序,由于需要将模拟键盘的输入发送到原来处于活动状态的程序,因此,我们的程序应该不改变原来的焦点。在vc6和vc#中可以通过以下方式实现:

1. VC6.0

在对话框的OnInitDialog()函数最后的初始化处,添加以下代码:

// TODO: Add extra initialization here

     LONG exs = GetWindowLong(this->m_hWnd, GWL_EXSTYLE);

     exs |= 0x08000000;//始终不处于活动状态

 

     SetWindowLong(this->m_hWnd,GWL_EXSTYLE, exs);

     SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

2. VC#

在.net平台下,可以同样导入API实现无焦点程序,方法如下:

 

using System.Runtime.InteropServices;

 

namespace CardDisp

{

     public partial class Form1 : Form

     {

         [DllImport("user32.dll", EntryPoint="GetWindowLong")]

         public static extern int GetWindowLong(IntPtr hWnd, int type);

         [DllImport("user32.dll", EntryPoint = "SetWindowLong")]

         public static extern int SetWindowLong(IntPtr hWnd, int type,int dwNewLong);

 

         public Form1()

         {

              InitializeComponent();

         }

 

         private void Form1_Load(object sender, EventArgs e)

         {           

              Int32 exs = GetWindowLong(Handle, -20);

              exs |= 0x08000000;//始终不处于活动状态

              SetWindowLong(Handle,-20, exs);

         }

     }

}   

转载于:https://www.cnblogs.com/rogee/archive/2011/02/15/1954964.html

;