Author Topic: sdk frame Scintilla qt :)  (Read 4761 times)

0 Members and 1 Guest are viewing this topic.

Offline Frank Brübach

  • Full Member
  • ***
  • Posts: 109
  • User-Rate: +13/-5
sdk frame Scintilla qt :)
« on: August 02, 2010, 05:57:05 PM »
hi all,

because I am very new with scintilla topic and theme I wanted to know what's here missing (for example how to handle the sendmessage to the scintilla window/textbox?) or if I am on the right way to include "scintilla" in my powerbasic example. some help would be appreciate. I wanted to use it for my AdamEvaBasic Art project :)

Code: [Select]
'----- frank's scintilla sdk window try, 02.08.2010
'--------------------------------------------------

#COMPILE EXE
#DIM ALL
#INCLUDE "win32api.inc"
#INCLUDE "scintilla.inc"
#INCLUDE "richedit.inc"

%IDCOMBO = 10001
%SCI_ID  = 20000

GLOBAL hDlg, Scin, hLib AS DWORD

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   LOCAL hWndMain    AS DWORD
   LOCAL hCtl        AS DWORD
   LOCAL hFont       AS DWORD
   LOCAL wcex        AS WNDCLASSEX
   LOCAL szClassName AS ASCIIZ * 80
   LOCAL rc          AS RECT
   LOCAL szCaption   AS ASCIIZ * 255
   LOCAL nLeft       AS LONG
   LOCAL nTop        AS LONG
   LOCAL nWidth      AS LONG
   LOCAL nHeight     AS LONG
   LOCAL hCombo      AS DWORD
   LOCAL szItem      AS ASCIIZ * 96
   LOCAL Scin        AS DWORD

   hLib = LoadLibrary("SCILEXER.DLL")

   hFont = GetStockObject(%ANSI_VAR_FONT)

   ' Register the window class
   szClassName        = "MyClassName"
   wcex.cbSize        = SIZEOF(wcex)
   wcex.style         = %CS_HREDRAW OR %CS_VREDRAW
   wcex.lpfnWndProc   = CODEPTR(WndProc)
   wcex.cbClsExtra    = 0
   wcex.cbWndExtra    = 0
   wcex.hInstance     = hInstance
   wcex.hCursor       = LoadCursor (%NULL, BYVAL %IDC_ARROW)
   wcex.hbrBackground = %LtGray_BRUSH '%COLOR_3DFACE + 1
   wcex.lpszMenuName  = %NULL
   wcex.lpszClassName = VARPTR(szClassName)
   wcex.hIcon         = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
   wcex.hIconSm       = LoadIcon (%NULL, BYVAL %IDI_APPLICATION)
   RegisterClassEx wcex

   ' Window caption
   szCaption = "SDK_Scintilla_Test"

   ' Retrieve the size of the working area
   SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0

   ' Calculate the position and size of the window
   nWidth  = (((rc.nRight - rc.nLeft)) + 2) * 0.75
   nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.70
   nLeft   = ((rc.nRight - rc.nLeft) \ 2) - nWidth \ 2
   nTop    = ((rc.nBottom - rc.nTop) \ 2) - (nHeight \ 2)

   ' Create a window using the registered class
   hWndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _
                             szClassName, _
                             szCaption, _
                             %WS_OVERLAPPEDWINDOW OR _
                             %WS_CLIPCHILDREN, _
                             nLeft, _
                             nTop, _
                             nWidth, _
                             nHeight, _
                             %NULL, _
                             0, _
                             hInstance, _
                             BYVAL %NULL)

   hCtl = CreateWindowEx(0, "BUTTON", "&Popup", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
          0, 0, 0, 0, hWndMain, %IDOK, hInstance, BYVAL %NULL)
   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

   hCtl = CreateWindowEx(0, "BUTTON", "&Close", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
          0, 0, 0, 0, hWndMain, %IDCANCEL, hInstance, BYVAL %NULL)
   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

   hCombo = CreateWindowEx(0, "Combobox", "&combo", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
          0, 0, 0, 0, hWndMain, %IDCOMBO, hInstance, BYVAL %NULL)
   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

   hCtl = CreateWindowEx(0, "Scintilla", "&sci", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
          0, 0, 0, 0, hWndMain, %SCI_ID, hInstance, BYVAL %NULL)
   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0


   IF hCombo = 0 THEN  ' exit on failure
        MSGBOX "Unable to create window"
        EXIT FUNCTION
    END IF

         ' Add the initial items
         ' Turn off repainting
         SendMessage hCombo, %WM_SETREDRAW, %FALSE, 0
         szItem = "batman"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "hulk"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "spiderman"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "thor"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "xmen"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Asterix"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Obelix"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         ' Turn on repainting
         SendMessage hCombo, %WM_SETREDRAW, %TRUE, 0
         InvalidateRect hCombo, BYVAL %NULL, %TRUE
         UpdateWindow hCombo

   ' Show the window
   ShowWindow hWndMain, nCmdShow
   UpdateWindow hWndMain

   ' Message handler loop
   LOCAL uMsg AS tagMsg
   WHILE GetMessage(uMsg, %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWndMain, uMsg) THEN
         TranslateMessage uMsg
         DispatchMessage uMsg
      END IF
   WEND

   FUNCTION = uMsg.wParam

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   LOCAL rc AS RECT   
   ' Retrieve the handle of the edit window
   'Scin = GetEdit

   SELECT CASE wMsg

      CASE %WM_CREATE
      CASE %WM_SIZE

         ' Resize the two sample buttons of the dialog
         IF wParam <> %SIZE_MINIMIZED THEN
            GetClientRect hWnd, rc
            MoveWindow GetDlgItem(hWnd, %IDOK), (rc.nRight - rc.nLeft) - 185, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
            MoveWindow GetDlgItem(hWnd, %IDCANCEL), (rc.nRight - rc.nLeft) - 95, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
            MoveWindow GetDlgItem(hWnd, %IDCOMBO), (rc.nRight - rc.nLeft) - 285, (rc.nBottom - rc.nTop) - 35, 75, 23, %TRUE
            MoveWindow GetDlgItem(hWnd, %SCI_ID), (rc.nRight - rc.nLeft) - 625, (rc.nBottom - rc.nTop) - 435, 375, 280, %TRUE
         END IF

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)

            CASE %IDOK
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  ShowPopupDialog hwnd
               END IF

            CASE %IDCANCEL
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF

         END SELECT

      CASE %WM_CTLCOLORBTN, %WM_CTLCOLOREDIT, %WM_CTLCOLORLISTBOX, %WM_CTLCOLORSTATIC

      CASE %WM_SYSCOMMAND
         ' Capture this message and send a WM_CLOSE message
         IF (wParam AND &HFFF0) = %SC_CLOSE THEN
            SendMessage hWnd, %WM_CLOSE, 0, 0
            EXIT FUNCTION
         END IF

      CASE %WM_CLOSE

      CASE %WM_DESTROY
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Popup dialog - Calling example: ShowPopupDialog hWnd
' ========================================================================================
FUNCTION ShowPopupDialog (BYVAL hParent AS LONG) AS LONG

   LOCAL hWndPopup   AS LONG
   LOCAL hCtl        AS LONG
   LOCAL hFont       AS LONG
   LOCAL rc          AS RECT
   LOCAL wcex        AS WNDCLASSEX
   LOCAL szClassName AS ASCIIZ * 80
   LOCAL szCaption   AS ASCIIZ * 255

   hFont = GetStockObject(%ANSI_VAR_FONT)

   szClassName        = "MyPopupClassName"
   wcex.cbSize        = SIZEOF(wcex)
   wcex.style         = %CS_HREDRAW OR %CS_VREDRAW
   wcex.lpfnWndProc   = CODEPTR(PopupDlgProc)
   wcex.cbClsExtra    = 0
   wcex.cbWndExtra    = 0
   wcex.hInstance     = GetModuleHandle("")
   wcex.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
   wcex.hbrBackground = %LtGray_BRUSH '%COLOR_3DFACE + 1
   wcex.lpszMenuName  = %NULL
   wcex.lpszClassName = VARPTR(szClassName)
   wcex.hIcon         = 0
   wcex.hIconSm       = 0
   RegisterClassEx wcex

   GetWindowRect hParent, rc
   rc.nRight = rc.nRight - rc.nLeft
   rc.nBottom = rc.nBottom - rc.nTop

   szCaption = "Popup dialog"
   hWndPopup = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT, _
               szClassName, szCaption, %WS_CAPTION OR %WS_POPUPWINDOW OR %WS_VISIBLE, _
               rc.nLeft + (rc.nRight - 290) / 2, _
               rc.nTop + (rc.nBottom - 180) / 2, _
               290, 180, hParent, 0, GetModuleHandle(""), BYVAL %NULL)

   hCtl = CreateWindowEx(0, "BUTTON", "&Close", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
               200, 118, 75, 23, hWndPopup, %IDCANCEL, GetModuleHandle(""), BYVAL %NULL)
   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

   ShowWindow hWndPopup, %SW_SHOW
   UpdateWindow hWndPopup
   ' Message handler loop
   LOCAL uMsg AS tagMsg
   WHILE GetMessage(uMsg, %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWndPopup, uMsg) THEN
         TranslateMessage uMsg
         DispatchMessage uMsg
      END IF
   WEND

   FUNCTION = uMsg.wParam

END FUNCTION
' ========================================================================================

' ========================================================================================
' Popup dialog procedure
' ========================================================================================
FUNCTION PopupDlgProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE wMsg
      CASE %WM_CREATE
         EnableWindow GetWindow(hWnd, %GW_OWNER), %FALSE

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE %WM_CLOSE
         EnableWindow GetWindow(hWnd, %GW_OWNER), %TRUE

      CASE %WM_DESTROY
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)

END FUNCTION
' ========================================================================================


thanks, best regards, frank

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2485
  • User-Rate: +204/-0
Re: sdk frame Scintilla qt :)
« Reply #1 on: August 02, 2010, 06:47:57 PM »
 
You handle it as with any other control, e.g.

Code: [Select]
   LOCAL hSci AS DWORD
   hSci = CreateWindowEx(0, "Scintilla", "&", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
          0, 0, 0, 0, hWndMain, %SCI_ID, hInstance, BYVAL %NULL)
   LOCAL strText AS STRING
   strText = "Test string"
   SendMessage hSci, %SCI_SETTEXT, 0, STRPTR(strText)

BTW change

Code: [Select]
MoveWindow GetDlgItem(hWnd, %SCI_ID), (rc.nRight - rc.nLeft) - 625, (rc.nBottom - rc.nTop) - 435, 375, 280, %TRUE

to something like

Code: [Select]
MoveWindow GetDlgItem(hWnd, %SCI_ID), 0, 0, 375, 280, %TRUE

or you won't see the string, because you are placing the control outside of the dialog.

Offline Frank Brübach

  • Full Member
  • ***
  • Posts: 109
  • User-Rate: +13/-5
Re: sdk frame Scintilla qt :)
« Reply #2 on: August 02, 2010, 09:05:59 PM »
hello josé, many thanks for the good hints, my little example works now as I like to see the test text :) great !

=> but just another thing belongs to my AdamEvaBasic Project: perhaps as you know I am working with your cWindow.inc. And here's the problem that I cannot insert something like "pWindow.AddRichEdit" for "Scintilla" handling. Something like "pWindow.AddScintilla" command would be nice, or it's possible that I can add such method for "cWindow.inc" myself ?

Quote
     pWindow.AddRichEdit(hwnd, %SCI_ID,"&Scintilla is better than rich Edit, use it :)", _
                        0, 0, 0, 0,-1,-1)

     pWindow.AddScintilla

can you help ?

thanks again, servus, Frank

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2485
  • User-Rate: +204/-0
Re: sdk frame Scintilla qt :)
« Reply #3 on: August 02, 2010, 09:51:57 PM »
 
If we had to add a method for every third party control we will end with a very bloated application. There is a method called AddControl that can be used to add any control and which is called by the other Addxxx methods to do the work.

See how easy is to use it:

Code: [Select]
#COMPILE EXE
#DIM ALL

%USEMACROS = 1                ' // Use macros
#INCLUDE ONCE "CWindow.inc"   ' // CWindow class
#INCLUDE ONCE "winctrl.inc"   ' // Window wrapper functions

%IDC_SCI = 101

' ########################################################################################
' Main
' ########################################################################################
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   ' // Create an instance of the class
   LOCAL pWindow AS IWindow
   pWindow = CLASS "CWindow"
   IF ISNOTHING(pWindow) THEN EXIT FUNCTION

   ' // Create the main window
   LOCAL hwnd AS DWORD
   hwnd = pWindow.CreateWindow(%NULL, "SDK Window", 0, 0, 500, 350, -1, -1, CODEPTR(WindowProc))
   Window_Center hwnd

   ' // Add a scintilla control
   LOCAL hLib AS DWORD
   LOCAL hSci AS DWORD
   hLib = LoadLibrary("SCILEXER.DLL")
   IF hLib THEN
      hSci = pWindow.AddControl("Scintilla", hwnd, %IDC_SCI, "", 50, 50, 380, 200, _
             %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_BORDER, 0)
   END IF

   ' // Default message pump (you can replace it with your own)
   pWindow.DoEvents

   IF hLib THEN FreeLibrary hLib

END FUNCTION
' ########################################################################################

' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   SELECT CASE uMsg

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE %WM_DESTROY
         ' // Close the main window
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

Offline Frank Brübach

  • Full Member
  • ***
  • Posts: 109
  • User-Rate: +13/-5
Re: sdk frame Scintilla qt :)
« Reply #4 on: August 02, 2010, 11:43:31 PM »
thanks again, here's now everything working fine. I have included Scintilla in my AEB project (here you can open new sdk window frame by a little Icon in Toolbar). - It's also important not to forget to copy (!) the "scilexer.dll" file in same folder as your current powerbasic example you're working with ;) I have learned new things, that's a good feeling! And to see that's much more possible with cWindow and Scintilla I will working with this team for the next days. For my AEB project it's a good little code editor tool, until there will be a better tool I don't know yet.

best regards, frank