Converter API do Windows

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

chicaomogi1970
Usuário Nível 1
Usuário Nível 1
Mensagens: 1
Registrado em: 19 Abr 2021 11:41
Localização: Mogi das Cruzes / São Paulo

Converter API do Windows

Mensagem por chicaomogi1970 »

Tem uma função da API do Windows chamada SendInput, só que não sei como converter ela pra Harbour.

Estou usando Harbour MiniGUI Extended Edition 21.03 (Update 2)

SINTAXE em C++
==============

Código: Selecionar todos

UINT SendInput(
  UINT    cInputs,
  LPINPUT pInputs,
  int     cbSize
);
PARAMETROS
===========

Código: Selecionar todos

cInputs

Type: UINT

The number of structures in the pInputs array.

pInputs

Type: LPINPUT

An array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.

cbSize

Type: int

The size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails.
RETORNO
========

Código: Selecionar todos

Type: UINT

The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError.

This function fails when it is blocked by UIPI. Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking.
EXEMPLO
========

Código: Selecionar todos

//**********************************************************************
//
// Sends Win + D to toggle to the desktop
//
//**********************************************************************
void ShowDesktop()
{
    OutputString(L"Sending 'Win-D'\r\n");
    INPUT inputs[4];
    ZeroMemory(inputs, sizeof(inputs));

    inputs[0].type = INPUT_KEYBOARD;
    inputs[0].ki.wVk = VK_LWIN;
    
    inputs[1].type = INPUT_KEYBOARD;
    inputs[1].ki.wVk = VK_D;

    inputs[2].type = INPUT_KEYBOARD;
    inputs[2].ki.wVk = VK_D;
    inputs[2].ki.dwFlags = KEYEVENTF_KEYUP;

    inputs[3].type = INPUT_KEYBOARD;
    inputs[3].ki.wVk = VK_LWIN;
    inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;

    UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
    if (uSent != ARRAYSIZE(inputs))
    {
        OutputString(L"SendInput failed: 0x%x\n", HRESULT_FROM_WIN32(GetLastError()));
    }
}
REQUERIMENTOS
==============

Código: Selecionar todos

Minimum supported client 	Windows 2000 Professional [desktop apps only]
Minimum supported server 	Windows 2000 Server [desktop apps only]
Target Platform 	                Windows
Header 	                                winuser.h (include Windows.h)
Library 	                                User32.lib
DLL 	                                        User32.dll
Queria saber como faz, ou se existe algum artigo que ensina a fazer essa conversão.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Converter API do Windows

Mensagem por JoséQuintas »

O problema que vejo nesse é o parâmetro array, contendo uma variável do tipo "input".
Não basta passar parâmetros, tem que ser do tipo certo, e esse tipo foge das regras conhecidas pelo Harbour.
Se não me engano existe a SendKeys(), específica pra comandos de teclado, que pode simplificar os parâmetros.
Mas acho que a maioria das LIBs tem algo pra isso pronto.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder