PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 25 → WD - Trabalhando com APi do Windows, CROMAKI, Lupa e Janela Transparente/Janela Vazada
WD - Trabalhando com APi do Windows, CROMAKI, Lupa e Janela Transparente/Janela Vazada
Iniciado por adrianoboller, mai., 24 2016 11:15 PM - Sem resposta
Membro registado
3.659 mensagems
Popularité : +175 (223 votes)
Publicado em maio, 24 2016 - 11:15 PM
Prezados,

Segue exemplo

Imagem BMP com fundo na cor MAGENTA





Janela com fundo Magenta





Adicione o controle de imagem exatamente no tamanho da tela









CODIGO GLOBAL DO PROJETO:
CONSTANT
USER32 = "user32"
GDI32 = "gdi32"
MAGNIFICATION = "magnification.dll"
END

// If Windows is in 64-bit mode but if the 64-bit version of the executable has not been started
// Unable to continue (Windows Vista and earlier only)
IF (SysWindowsVersion(sysProcessor) = 64 _AND_ NOT In64bitMode()) _AND_ Val(SysWindowsVersion(sysVersionNumber)) <= 6 THEN
EndProgram("This program cannot operate on a 64-bit system.", "Start the 64-bit version of this program.", True)
END






No open da janela coloque o seguinte código:

GLOBAL DECLARATIONS
// Execution in Vista
gbVista is boolean = (Val(SysWindowsVersion(sysVersionNumber)) >= 6)

// Zoom coefficient
gnZoom is int = 2

// Makes the window "invisible" to the screen shots performed with dCopyBlt.
API(USER32, "SetWindowLongA", Handle(), -20, 0x00080000)
API(USER32, "SetLayeredWindowAttributes", Handle(), LightMagenta, 255, 0x00000001)

gnDC is system int
gnHwnd is system int

// By using the GDI API, create an elliptic area that corresponds to the circle of the magnifier.
gnRgn is system int = API(GDI32,"CreateEllipticRgn", 0, 0, 174, 174)

IF gbVista = False THEN

// Starts drawing in the image control named IMG_MAGNIFIER

gnDC = dStartDrawing(IMG_MAGNIFIER)
gnHwnd = Handle(IMG_MAGNIFIER)

// Applies the elliptical area to the image control
// The drawing will be enabled in this circular area only.
// Whenever a drawing function is used, only the circular area will be updated in the image control.
API(GDI32,"SelectObject", gnDC, gnRgn)
END

// Hides the mouse cursor: the mouse will not be visible when the window is hovered by the cursor
CursorDisplay(False)

LOCAL
// Retrieve the current coordinates of the mouse cursor on the screen

nX is int = LoWord(CursorPos(cpScreen))
nY is int = HiWord(CursorPos(cpScreen))

// Positions the window to the mouse coordinates
MyWindow..X = nX - (IMG_MAGNIFIER..X + IMG_MAGNIFIER..Width / 2)
MyWindow..Y = nY - (IMG_MAGNIFIER..Y + IMG_MAGNIFIER..Height / 2)

IF gbVista THEN

// Initializes the magnifier of Vista
InitializeVistaMagnifier()
END



END OF INICIALIZATION
// Positions the window in the foreground ("TOPMOST")
WinStatus(WIN_Magnifier, AboveAll)

// First display
Update()

WIN_Magnifier..Visible = True

// The source image must be re-displayed
IMG_MAGNIFIER = IMG_MAGNIFIER..InitialValue

// Triggers a timer that will position the window to the mouse coordinates
// Allows the cursor to be followed by the window
WindowPosition()




CLOSING OF JANELA
//AO SAIR
IF gbVista THEN

// Unloads the magnifier
API(MAGNIFICATION, "MagUninitialize")
END

// Redisplays the cursor
CursorDisplay(True)

// Destroys the circular area
API(GDI32, "DeleteObject", gnRgn)

// Frees the DC of the image control
dEndDrawing(IMG_MAGNIFIER)





PROCEDURES LOCAIS DA JANELA
// Summary: Initializes the magnifier of Vista
// Syntax:
// InitializeVistaMagnifier ()
//
// Parameters:
// None
// Return value:
// None
//
Procedure InitializeVistaMagnifier()

// Loads the DLL of the magnifier of Windows Vista
LoadDLL(MAGNIFICATION)

// Initializes the magnifier
API(MAGNIFICATION, "MagInitialize")

// Creates a window to receives the images from the magnifier
gnHwnd = API(USER32, "CreateWindowExA", 0, "Magnifier", ProjectInfo(piProjectName), ...
0x40000000 + 0x08000000, 0, 0, IMG_MAGNIFIER..Width, ...
IMG_MAGNIFIER..Height, Handle(IMG_MAGNIFIER), 0, SysInstance(), 0)

// Retrieves the DC of the window
gnDC = API(USER32, "GetWindowDC", gnHwnd)

// Applies the elliptical section to the window for receiving the images from the magnifier
// The drawing will be enabled in this circular area only.
// Whenever the image is updated by the magnifier, only the circular section
// will be updated.
API(USER32, "SetWindowRgn", gnHwnd, gnRgn, True)

// Prepare the zoom
arrZoom is array of 3 by 3 4-byte real
arrZoom[1][1] = gnZoom
arrZoom[2][2] = gnZoom
arrZoom[3][3] = 1

// Initialize the zoom
API(MAGNIFICATION, "MagSetWindowTransform", gnHwnd, &arrZoom)

// Displays the window that was created
API(USER32, "ShowWindow", gnHwnd, 5)
API(USER32, "SetWindowPos", gnHwnd, -1, 0, 0, 0, 0, 0x0001 + 0x0040)



// Syntax:
//Update ()
//
// Parameters:
// None
// Return value:
// None
//
Procedure Update()

// Whenever the window is moved, perform a screen shot of the area occupied by the image control in the image control

nX, nY are int
nXCopy, nYCopy are int
nXCopy = (MyWindow..X + IMG_MAGNIFIER..X + IMG_MAGNIFIER..Width / 2) - (86 / gnZoom)
nYCopy = (MyWindow..Y + IMG_MAGNIFIER..Y + IMG_MAGNIFIER..Height / 2) - (86 / gnZoom)


IF gbVista THEN

// Retrieves the mouse coordinates on the screen
nX = LoWord(CursorPos(cpScreen))
nY = HiWord(CursorPos(cpScreen))

RECT is structure
nLeft, nTop, nRight, nBottom are int
END

// Use the magnifier
stRectCopy is RECT

stRectCopy:nLeft = nXCopy
stRectCopy:nRight = 172
stRectCopy:nTop = nYCopy
stRectCopy:nBottom = 172
nHandle is system int = gnHwnd

// Retrieves the image
IF In64bitMode() THEN
API(MAGNIFICATION, "MagSetWindowSource", nHandle, &stRectCopy)
ELSE
API(MAGNIFICATION, "MagSetWindowSource", nHandle, stRectCopy)
END

// Update
API(USER32, "InvalidateRect", nHandle, Null, True)

ELSE

// Copies (X,Y)-(X+85,Y+85) to (0,0)-(170,170)
// => the copied area is zoomed by 2
dCopyBlt(copyScreen, IMG_MAGNIFIER, copySrcCopy, nXCopy, nYCopy, 172 / gnZoom, 172 / gnZoom, 0, 0, 172, 172)
END





// Syntax:
//WindowPosition ()
//
// Parameters:
// None
// Return value:
// None

Procedure WindowPosition()

EndTimer(1000)

nX is int
nY is int
nOldX is int
nOldY is int

// Retrieves the mouse coordinates on the screen
nX = LoWord(CursorPos(cpScreen))
nY = HiWord(CursorPos(cpScreen))

// Retrieves the current coordinates of the window on the screen
nOldX = MyWindow..X
nOldY = MyWindow..Y

// The window must be moved if the mouse coordinates have changed
IF (nOldX <> nX - (IMG_MAGNIFIER..X + IMG_MAGNIFIER..Width / 2)) _OR_ (nOldY <> nY - (IMG_MAGNIFIER..Y + IMG_MAGNIFIER..Height / 2)) THEN

// Moves the window
WinSize(WIN_Magnifier, (nX - (IMG_MAGNIFIER..X + IMG_MAGNIFIER..Width / 2)), (nY - (IMG_MAGNIFIER..Y + IMG_MAGNIFIER..Height / 2)), MyWindow..Width, MyWindow..Height)

END

// Positions the window in the foreground ("TOPMOST")
WinStatus(WIN_Magnifier, AboveAll)
Timer(WindowPosition, 1, 1000)





BOTAO ESC - SHORTCUT KEY HOT KEY = ESC
// Closes the window by pressing ESC
Close



RESULTADO FINAL





--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/