NTK and The NTK Project
are properties of Jn Dechereux
Home | Documentation | FAQ.

Vanilla 1.1.8 is a product of Lussumo. More Information: Documentation, Community Support.

Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentTimeJan 18th 2022
    can anyone else verify that "NTK_SETPIXEL" correctly sets the requested colour?

    e.g. from the NTK CORE documentation the following example in my own testing will not draw a red pixel, it will draw a black pixel: furthermore the return value of the call to NTK_SetPixel (whatever colour is requested) is always "4"

    nRed = NTK_Rgb ( 255 , 0 , 0 )
    NTK_SetPixel ( hDC , 100 , 100 , nRed )

    i appreciate it could be some quirk of my own code / testing though
    • CommentTimeJan 19th 2022
    no problem with this function here - works as expected - plots dots using the right color.

    my code:
    function WndProc(hWnd, nMsg, nwParam, nlParam)
    static nCount := 0
    local aPaint[PS_LENGTH], hDC, i, j
    Local hPen, hOldPen
    local nRed := RGB(255,0,0)
    local nGreen := RGB(0,255,0)

    do case
    case nMsg == WM_LBUTTONDOWN
    // this is logically the 1st event we want to handle...
    nCount = 0
    return 0 // 0 means we processed the msg

    case nMsg == WM_MOUSEMOVE
    // ... but it would be faster to put this first
    // (only matters on a _slow_ cpu) ...
    if C4W_And(nwParam, MOUSE_LBUTTON) != 0 .and. nCount < MAXPOINTS
    aX[nCount] = c4w_LoWord(nlParam)
    aY[nCount] = c4w_HiWord(nlParam)

    // leave a trail of red dots
    hDC = GetDC(hWnd)
    SetPixel(hDC, aX[nCount], aY[nCount], nRed)
    ReleaseDC(hWnd, hDC)
    return 0 // 0 means we processed the msg

    case nMsg == WM_LBUTTONUP
    // ... then this is the last of the sequence, before...
    return 0 // 0 means we processed the msg

    case nMsg == WM_CTLCOLOR

    case nMsg == WM_PAINT
    // ... now we join the dots in many ways!
    hDC = BeginPaint(hWnd, aPaint)

    hPen := NTK_CreatePen( PS_SOLID, 1, nGreen )
    hOldPen := NTK_SelectObject( hDC, hPen )

    for i = 1 to nCount - 1
    for j = 1 to nCount
    MoveTo(hDC, aX[i], aY[i])
    LineTo(hDC, aX[j], aY[j])
    next j
    next i

    NTK_SelectObject( hDC, hOldPen )
    NTK_DeleteObject( hPen )

    EndPaint(hWnd, aPaint)
    return 0 // 0 means we processed the msg

    case nMsg == WM_DESTROY
    // leave out this, and you can't exit!!
    return 0 // 0 means we processed the msg

    return DefWindowProc(hWnd, nMsg, nwParam, nlParam)
    • CommentTimeJan 19th 2022
    Hi there
    Same for me. Basic API that does the job as doc'ed.
    • CommentTimeJan 24th 2022
    thank you very much xbasefan / Lucas: i will continue to explore what could be wrong in my own code then (i can circumvent the requirement fairly easily anyway)

    the strange thing is the same section of code also uses the "NTK_POLYLINE" method and that is successfully drawing the correct colour


    local nBckgrdRGB := NTK_RGB(192, 192, 192)
    hPenLight := NTK_CREATEPEN(PS_SOLID, 1, NTK_RGB(224, 224, 224))
    NTK_POLYLINE(hDC, {{nLeft - 1, nTop + nBmpHeight}, {nLeft - 1, nTop - 1}, {nLeft + nBmpWidth, nTop - 1}})
    // works - the drawn colour is NTK_RGB(224, 224, 224)

    NTK_SETPIXEL(hDC, nLeft - 1, nTop - 1, nBckgrdRGB)
    // fails - the drawn corner pixel is NOT NTK_RGB(192, 192, 192) (appears black)

    i wonder if it is something to do with calling "NTK_SETPIXEL" immediately at the same position "NTK_POLYLINE" just drew on
    • CommentTimeFeb 1st 2022 edited
    Hi there:
    I'm not a not a NTKCORE expert but I just replaced the winproc portion in my ..\contribs\c4W2ntk\Draw.Prg (joint-the-dots tutorial) with code from Wilson in the above. And no surprise - dots are properly drawn in red and when you release the mouse button the resulting shape is painted/flooded in green. So its Ok here. See attached.
    • CommentTimeFeb 4th 2022
    thanks very much for the help guys / confirming no issue with "NTK_SETPIXEL"

    in my own code this issue just went away i.e. it now works correctly: i am in the middle of converting a fairly large old CLIPPER / CLIP4WIN application and cannot trace what exact change got this working but if i was to guess it would be tidy ups i made to the sub-classed procedure for the window where things were being drawn