Jump to content

winapi math


Recommended Posts

winapi draw line uses the x,y of the line start and x,y of the line end

_WinAPI_DrawLine($guiname, x1, y1, x2, y2)

I've been searching google all morning looking for the the simple formula to plot a curve using 2 given points but can't find it.

I'm hoping that by using the formula in place of the coordinates, winapi will draw a curve instead of a straight line.

Possible?

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

kaotkbliss,

I've been searching google all morning looking for the the simple formula to plot a curve using 2 given points but can't find it.

That might because you need 3 points to define a curve. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well, I know what the 3rd point is, but winapi only accepts 2. I can't remember any of this graphing stuff from math class so I didn't know if there was a way to get this to work.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

kaotkbliss,

_WinAPI_DrawLine only draws straight lines, as its name suggests.

Perhaps you should look at _GDIPlus_GraphicsDrawCurve - sounds like a better bet to me! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I tried gdi plus drawing commands, but they don't seem to want to draw on the window I need it to.

Unless I can figure that out, it seems my only other option would be to draw many straight short lines in a curve shape.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I've tried gdi+ drawing but can't get any to work on my particular window.

#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$dll = DllOpen("user32.dll")
Global $hParent, $hForm, $Pos, $hBitmap = 0, $Go = 1, $XPrev = MouseGetPos(0), $YPrev = MouseGetPos(1)
Global $hDC, $hMemDC, $hSv, $pBlend, $tBlend, $pSize, $tSize, $pSource, $tSource, $hWnd,$iX,$iY,$iHeight
Global $scope = 0

$hParent = GUICreate('', -1, -1, -1, -1, -1, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TRANSPARENT ))
$hForm = GUICreate('', 150, 150, $XPrev + 25, $YPrev + 25, BitOR($WS_DISABLED, $WS_POPUPWINDOW), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_TRANSPARENT ), $hParent)
GUISetState(@SW_HIDE, $hForm)

While 1

    If _IsPressed("1B", $dll) Then
        DllClose($dll)
        Exit (1)
    EndIf

    If _IsPressed("5A", $dll) And $scope = 0 Then
        $scope = 1
        Sleep(500)
    EndIf

    If _IsPressed("5A", $dll) And $scope = 1 Then
        $scope = 0
        GUISetState(@SW_HIDE, $hForm)
        Sleep(500)
    EndIf

    If $scope = 1 Then

        GUISetState(@SW_SHOWNOACTIVATE, $hForm)

        $Pos = MouseGetPos()
        If ($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev) Then
            WinMove($hForm, '', $Pos[0] - 75, $Pos[1] - 75)
            _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
            $XPrev = $Pos[0]
            $YPrev = $Pos[1]
            $Go = 0
        EndIf
        _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
    EndIf

WEnd

Func _Capture($iX, $iY, $iWidth, $iHeight)

    Local $tRect, $hDC, $hMemDC, $hScreenshort = _ScreenCapture($iX, $iY, $iWidth, $iHeight)
    _WinAPI_FreeObject($hBitmap)
    $hBitmap = _WinAPI_FitToBitmap($hScreenshort, 150, 150)
    _WinAPI_FreeObject($hScreenshort)
    $hDC = _WinAPI_GetDC($hForm)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_BRUSH))
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCPenColor($hMemDC, 0xA00000)
    _WinAPI_DrawLine($hMemDC, 150, 75, -150, 75)
    _WinAPI_DrawLine($hMemDC, 75, 150, 75, -150)

    _WinAPI_DrawLine($hMemDC, 70, 65, 80, 65)
    _WinAPI_DrawLine($hMemDC, 85, 70, 85, 80)
    _WinAPI_DrawLine($hMemDC, 70, 85, 80, 85)
    _WinAPI_DrawLine($hMemDC, 65, 70, 65, 80)

    _WinAPI_DrawLine($hMemDC, 65, 50, 85, 50)
    _WinAPI_DrawLine($hMemDC, 100, 65, 100, 85)
    _WinAPI_DrawLine($hMemDC, 65, 100, 85, 100)
    _WinAPI_DrawLine($hMemDC, 50, 65, 50, 85)

    _WinAPI_DrawLine($hMemDC, 60, 35, 90, 35)
    _WinAPI_DrawLine($hMemDC, 115, 60, 115, 90)
    _WinAPI_DrawLine($hMemDC, 60, 115, 90, 115)
    _WinAPI_DrawLine($hMemDC, 35, 60, 35, 90)

    _WinAPI_ReleaseDC($hForm, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetBitmap($hForm, $hBitmap, 254)
EndFunc   ;==>_Capture

Func _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    Local $hWnd, $hDC, $hMemDC, $hBitmap

    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $MERGECOPY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    Return $hBitmap
EndFunc   ;==>_ScreenCapture

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $pSize = DllStructGetPtr($tSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 0)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMemDC, $hSv)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...