• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

how to clear off label

Started by Chris Chancellor, October 09, 2018, 07:06:35 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

Hello all

i have modified Jose's  textbox subclassing program by adding a label so that it echo out any key
that has been typed into the textbox

The initial screen is good but the label gets overwritten over and over again on subsequent screens
as shown in images below



Chris Chancellor

#1
the code are as below :

how do i correct this overwritten label ?




'TB_Subclass.o2bas
' http://www.jose.it-berater.org/smfforum/index.php?PHPSESSID=e68084f2532745d95d4873d328710a18&topic=5383.msg23376;topicseen#msg23376
'  Subclassing a Textbox  SDK style

$ filename "TB_Subclass.exe"
uses rtl64
uses coreWin
uses User
uses Comctl
#lookahead

%GWLP_WNDPROC = -4

sys lbl1
 
' for painting the dialog background
! WindowFromDC lib "user32.dll" (sys hDc) as sys
! DestroyWindow lib "user32.dll" (sys hWnd) as bool
! CreateSolidBrush lib "GDi32.dll" (byte COLORREF crColor)
! GetStockObject lib "GDi32.dll" (int fnObject)



'============================
        ' RGB function for O2
         function RGB(int rcc, gcc, bcc) as int
                    return (rcc + gcc*256 + bcc*65536)
        end Function



'============================
function WinMain() as sys

   WndClass wc
   MSG      wm
   sys inst = GetModuleHandle 0

   sys hwnd, wwd, wht, wtx, wty, tax
   wc.style = CS_HREDRAW or CS_VREDRAW
   wc.lpfnWndProc = &WndProc
   wc.cbClsExtra = 0
   wc.cbWndExtra = 0   
   wc.hInstance = GetModuleHandle 0
   wc.hIcon=LoadIcon 0, IDI_APPLICATION
   wc.hCursor=LoadCursor 0,IDC_ARROW
   wc.hbrBackground = GetStockObject WHITE_BRUSH
   wc.lpszMenuName =0
   wc.lpszClassName =@"Demo"

   RegisterClass (&wc)

   Wwd = 320 : Wht = 200
   Tax = GetSystemMetrics SM_CXSCREEN
   Wtx = (Tax - Wwd) /2
   Tax = GetSystemMetrics SM_CYSCREEN
   Wty = (Tax - Wht) /2

   hwnd = CreateWindowEx(0,wc.lpszClassName,"OXYGEN BASIC  SDK ", _
         WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0)

'   Add in a textbox
   sys hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, _
                              "Edit", _
                              "", _
                              WS_CHILD OR WS_VISIBLE OR WS_TABSTOP, _
                              20, 30, _
                              250, 25, _
                              hWnd, 102, _
                              inst, 0)

  ' Set the subclassing for the textbox
   SetProp(hedit, "OLDWNDPROC", SetWindowLongPtr(hEdit, GWLP_WNDPROC, _
                             &EditSubclassProc))
     SetFocus hEdit


    lbl1=CreateWindowEx(0, "static", "", _
        WS_CHILD|WS_VISIBLE, 20,70,150,25, hwnd,103,inst,0)

    SetWindowText( lbl1, "Char enter ")



   ShowWindow hwnd,SW_SHOW
   UpdateWindow hwnd

   WHILE GetMessage(&wm, 0, 0, 0) > 0
      IF IsDialogMessage(hWnd, &wm) = 0 THEN
         TranslateMessage(&wm)
         DispatchMessage(&wm)
      END IF
   WEND

End Function



'==================================================================
'  The main callback function
'  note that you need to place in sys callback
function WndProc (sys hWnd, wMsg, wParam, lparam) as sys callback

' for painting background of dialog
  LOCAL hDC  AS sys
'
    SELECT wMsg
       
      CASE WM_CREATE
         EXIT FUNCTION

     CASE  WM_ERASEBKGND     
          hDC = wParam
        ' Pass the DC of the region to repaint
          DrawGradient hDC           
          FUNCTION = 1
          EXIT FUNCTION


       CASE   WM_CTLCOLORSTATIC
                  '  set text forecolor to  Red
               SetTextColor(wPARAM, RGB(250,0,112))
                 ' set background to transparent
               SetBkMode(wPARAM, TRANSPARENT)
               FUNCTION = GetStockObject(NULL_BRUSH)
               EXIT FUNCTION


      CASE WM_COMMAND
         SELECT CASE LOWORD(wParam)
            CASE IDCANCEL
               ' // If the Escape key has been pressed...
               IF HIWORD(wParam) = BN_CLICKED THEN
                  ' // ... close the application by sending a WM_CLOSE message
                  SendMessage hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE WM_DESTROY
         PostQuitMessage 0

    END SELECT

   function = DefWindowProc hWnd,wMsg,wParam,lParam

end function ' WndProc



'================================
'  Subclass the textbox
'  note that you need to place in sys callback
FUNCTION EditSubclassProc (sys hWnd, wMsg, wParam, lparam) as sys callback

   SELECT CASE wMsg
      CASE WM_DESTROY
         ' // REQUIRED: Remove control subclassing
         SetWindowLongPtr hwnd, GWLP_WNDPROC, _
                              RemoveProp(hwnd, "OLDWNDPROC")

      CASE WM_KEYDOWN
      '   SetWindowText GetParent(hwnd), "ASCII " & STR(wParam)
           SetWindowText   lbl1, "                                   "
           SetWindowText   lbl1, "ASCII " & STR(wParam)

   END SELECT


   FUNCTION = CallWindowProc(GetProp(hwnd, "OLDWNDPROC"),  _
                           hwnd, wMsg, wParam, lParam)

END FUNCTION



'==========================================
' Repaint background with a color gradient
SUB DrawGradient (BYVAL hDC AS DWORD)
   LOCAL rectFill AS RECT, rectClient AS RECT, fStep AS SINGLE
   local hBrush AS DWORD, lOnBand AS LONG
   GetClientRect WindowFromDC(hDC), rectClient
   fStep = rectClient.bottom / 75

   FOR lOnBand = 0 TO 199
      SetRect rectFill, 0, lOnBand * fStep, rectClient.right + 1, (lOnBand + 1) * fStep
      ' paint the background -- change the first 2 colors R and G
      ' to vary the color gradient
      hBrush = CreateSolidBrush(rgb(228, 240, 230 - lOnBand))
      Fillrect hDC, rectFill, hBrush
      DeleteObject hBrush
   NEXT

END SUB





WinMain




in the subclass textbox callback function,  i had placed in the code to clear off the
text in the label lbl1  but not successful as shown below


    CASE WM_KEYDOWN
      '   SetWindowText GetParent(hwnd), "ASCII " & STR(wParam)
           SetWindowText   lbl1, "                                   "
           SetWindowText   lbl1, "ASCII " & STR(wParam)



there must be a better way to clear off all previous entry,  please help


José Roca

If yu make the label transparent, the background isen't erased. You have to use OPAQUE instead of TRANSPARENT.