Solucio a teclado virtual

08/06/2007 - 10:48 por Jowie | Informe spam
Hola a todos,

Hace poquito tiempo estuve preguntando unas dudas sobre como enviar
mensajes a ventanas porque necesitaba hacer un teclado virtual
(teclado en pantalla) que al final no consegui :( Podia haber usado el
teclado de guindous pero a este no se le podia cambiar el tamaño
entonces investigando un poquito he conseguido hacer una aplicación
para cambiarle el tamaño a dicho teclado, lo pongo a continuacion
porque me pareció algo interesante.

Este codigo hace que el formulario del teclado se pueda redimensionar
pero has de ser tu quien lo redimensione, eso si, al guardarlo y
volverlo a abrir guarda su ultimo tamaño. Esto es bastante util en
caso de touchscreens, espero que os sirva.

//Codigo para hacer la ventana redimensionable donde hWnd el el handle
de la ventana activa obtenido con GetForegroudWindow

Style = GetWindowLong(this.hWnd.ToInt32(), GWL_STYLE);
if ((Style & WS_THICKFRAME) != WS_THICKFRAME)
{
//' Si no lo tiene, lo pone
Style = Style | WS_THICKFRAME; // | = Or
SetWindowLong(this.hWnd.ToInt32(), GWL_STYLE, Style);
SetWindowPos(this.hWnd.ToInt32(), this.Handle.ToInt32(), 0, 0, 0,
0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_DRAWFRAME);
}

//Codigo para dejarla en su estado normal
Style = GetWindowLong(this.hWnd.ToInt32(), GWL_STYLE);
if ((Style & WS_THICKFRAME) == WS_THICKFRAME) // & = And
{
//' Si ya lo tiene, lo quita
Style = Style ^ WS_THICKFRAME; // ^ = Xor
SetWindowLong(this.hWnd.ToInt32(), GWL_STYLE, Style);
SetWindowPos(this.hWnd.ToInt32(), this.Handle.ToInt32(), 0, 0, 0,
0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_DRAWFRAME);
}

//Constantes utilizadas
const int GWL_STYLE = (-16);
const int WS_THICKFRAME = 0x40000; //' Con borde redimensionable //'
const int SWP_DRAWFRAME = 0x20;
const int SWP_NOMOVE = 0x2;
const int SWP_NOSIZE = 0x1;
const int SWP_NOZORDER = 0x4;

//api`s
[DllImport("user32.dll")]
public static extern int GetWindowTextLengthA(IntPtr hWnd);

[DllImport("user32.DLL")]
public static extern IntPtr GetWindowTextA(IntPtr hWnd, StringBuilder
puntero, int longitud);
[DllImport("User32.dll")]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.DLL", EntryPoint = "GetWindowLong")]
static extern int GetWindowLong(int hWnd, int nIndex);

[DllImport("user32.DLL", EntryPoint = "SetWindowLong")]
static extern int SetWindowLong(
int hWnd, // handle to window
int nIndex, // ofsizFontet of value to set
int dwNewLong // new value
);

[DllImport("user32.DLL", EntryPoint = "SetWindowPos")]
static extern bool SetWindowPos(
int hWnd, // handle to window
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags // window-positioning options
);

Ahh, se me olvidava, este codigo vale tanto como para formularios como
para los controles de los formularios.

Un saludo a todos.
 

Leer las respuestas

#1 Alhambra Eidos Kiquenet
14/06/2007 - 21:08 | Informe spam
Algunas webs de referencia o proyectos de ejemplo en codeproject o codeplex ???

SAlu2.

Preguntas similares