PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 10
 1 
 on: April 18, 2021, 06:59:45 AM 
Started by jermy - Last post by jermy
I have looked at some examples in C-code, what i wanted to do is very complex. and examples are not very comprehensive.
This is still too difficult for me.

Thanks for the effort.

 2 
 on: April 17, 2021, 09:04:24 PM 
Started by jermy - Last post by Paul Squires
I was hoping to be able to get the current font of the control and select it into the DC, but that doesn't seem to work. Maybe because it is a RichEdit control? Maybe because RichEdit controls can have multiple fonts, it does not expose access to the WM_GETFONT message?

Code: [Select]
     Case WM_PAINT
            DIM hDC AS HDC                                                                                           
            Dim As RECT  rect
                                                                                                                 
             DefSubclassProc(hwnd, uMsg, wParam, lParam)         
             
             hdc  = GetDC(hWnd)                                                                                                               
             
             dim as long state = SaveDC(hdc)
             
             dim as HFONT hFont1 = GetWindowFont(hWnd)
             
             SelectObject( hdc, hFont1 )
             
             SetBkMode(hdc,TRANSPARENT)
             SendMessageW( hWnd, EM_GETRECT, 0, cast(LPARAM, @rect) )
             
             DrawTextW(hdc,"Hello World",-1,@rect,0)
             
             RestoreDC(hdc, state)
             DeleteDC(hdc)                       

I guess you could create a scaled CWindow font in WM_PAINT, select it into the DC, do your painting, restore the DC, and finally delete the created font. I haven't tried that but it should definitely work.

 3 
 on: April 16, 2021, 06:43:25 PM 
Started by jermy - Last post by jermy
Hello people,

i am trying to draw with drawtext in a richedit control 'hello world' it works but the text is very small.
I don't know how to scale this correctly.

Code: [Select]
#define UNICODE
#INCLUDE ONCE "Afx/CWindow.inc"
USING Afx

CONST IDC_RICHEDIT = 1001

DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                          BYVAL hPrevInstance AS HINSTANCE, _
                          BYVAL szCmdLine AS ZSTRING PTR, _
                          BYVAL nCmdShow AS LONG) AS LONG

   END WinMain(GetModuleHandleW(NULL), NULL, COMMAND(), SW_NORMAL)



' // Forward declaration
DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
Declare FUNCTION RichEdit_SubclassProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM, BYVAL uIdSubclass AS UINT_PTR, BYVAL dwRefData AS DWORD_PTR) AS LRESULT

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                  BYVAL hPrevInstance AS HINSTANCE, _
                  BYVAL szCmdLine AS ZSTRING PTR, _
                  BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
    AfxSetProcessDPIAware

   DIM pWindow AS CWindow
   pWindow.Create(NULL, "CWindow with a Rich Edit control", @WndProc)
   pWindow.SetClientSize(500, 320)
   pWindow.Center
   
   DIM hRichEdit AS HWND = pWindow.AddControl("RichEdit", , IDC_RICHEDIT, "", 350, 250, 75, 23, , , , CAST(SUBCLASSPROC, @RichEdit_SubclassProc), IDC_RICHEDIT, CAST(DWORD_PTR, @pWindow))
   SetFocus hRichEdit
   

   ' // Dispatch Windows messages
   FUNCTION = pWindow.DoEvents(nCmdShow)

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

' ========================================================================================
' Processes messages for the subclassed RichEdit window.
' ========================================================================================
FUNCTION RichEdit_SubclassProc ( BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM, BYVAL uIdSubclass AS UINT_PTR, BYVAL dwRefData AS DWORD_PTR ) AS LRESULT

   SELECT CASE uMsg

     Case WM_PAINT
            DIM hDC AS HDC                                                                                           
            Dim As RECT  rect
                                                                                                                 
             DefSubclassProc(hwnd, uMsg, wParam, lParam)         
             
             hdc  = GetDC(hWnd)                                                                                                               
             
             SetBkMode(hdc,TRANSPARENT)
             SendMessageW( hWnd, EM_GETRECT, 0, cast(LPARAM, @rect) ) 
             
             DrawTextW(hdc,"Hello World",-1,@rect,0)
             
             DeleteDC(hdc)                       
         
      CASE WM_DESTROY
         ' // REQUIRED: Remove control subclassing
         RemoveWindowSubclass hwnd, @RichEdit_SubclassProc, uIdSubclass

   END SELECT

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

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

' ========================================================================================
' Main window callback procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   SELECT CASE uMsg

      CASE WM_COMMAND
         SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
            ' // If ESC key pressed, close the application sending an WM_CLOSE message
            CASE IDCANCEL
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE WM_SIZE
         ' // If the window isn't minimized, resize it
         IF wParam <> SIZE_MINIMIZED THEN
            ' // Resize the controls
            DIM pWindow AS CWindow PTR = AfxCWindowPtr(hwnd)
            IF pWindow THEN
               pWindow->MoveWindow GetDlgItem(hwnd, IDC_RICHEDIT), 100, 50, pWindow->ClientWidth - 200, pWindow->ClientHeight - 150, CTRUE
            END IF
         END IF

    CASE WM_DESTROY
         ' // End the application by sending an WM_QUIT message
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   ' // Default processing of Windows messages
   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

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


it is possible to inherit the scaling, font, etc. from the RichEdit control so that the text being drawn looks the same as the typed version?


 4 
 on: April 12, 2021, 06:52:20 PM 
Started by jermy - Last post by Josť Roca
Yes. I changed the code but forgot to update the documentation. Thanks for pointig it.

 5 
 on: April 12, 2021, 06:17:52 PM 
Started by jermy - Last post by jermy
There is a small mistake in the help text.

WNDPROC ?
Code: [Select]
pWindow.AddControl("Button", pWindow.hWindow, IDC_BUTTON, "Click me", 350, 250, 75, 23, , , , _
   CAST(WNDPROC, @Button_SubclassProc), IDC_BUTTON, CAST(DWORD_PTR, @pWindow))

I think it must be
Code: [Select]
pWindow.AddControl("Button", pWindow.hWindow, IDC_BUTTON, "Click me", 350, 250, 75, 23, , , , _
   CAST(SUBCLASSPROC, @Button_SubclassProc), IDC_BUTTON, CAST(DWORD_PTR, @pWindow))

thanks for sharing the framework

 6 
 on: April 11, 2021, 11:27:00 AM 
Started by ron77 - Last post by jermy
The code is stripped version of a vb6 program to edit odl files and compile them.
Only the parser and some other small parts of code could be used.
The problem was that vb6 puts everything in a container, completely useless and would have to be completely rewritten.
Now that we no longer use vb6, I no longer need the odl ide.

explain to me how to add more keywords to be highlighted 
Look for
Code: [Select]
' assumes one character long comment
Const COMMENT = "'"

Const DELIMITER = " {}[]()"

Dim shared RESERVED As String: RESERVED = " DIM LONG BOOLEAN IN DECLARE FUNCTION Ron77 "     
Const FUNC_OBJ As String = " ENTRY "
Const KEYWORD_PAD As String = " "     

And for the color's, look for
Code: [Select]
Private Sub Highlight(hEdit As hwnd, SyntaxType As long, StartPos As Long, Length As Long)
    dim cf AS CHARFORMAT2
        cf.cbsize            = sizeof(cf)
        cf.dwMask            = CFM_COLOR
     
    select case SyntaxType
          case 0             ' ColorComment
              cf.crTextColor = colors.Green ' colors.

afther pressing a dot behind 'colors' you get a drop-down list with built-in colors. 

 7 
 on: April 11, 2021, 10:35:09 AM 
Started by ron77 - Last post by ron77
hello jermy and everyone :)

well i made a second version of my text editor (which now i'm trying to make a basic IDE for freebasic from it) instead of "textbox" i use "richtext" component and i downloaded your TLB-IDE and added the parser and you are corrected it works to some extend it colors some freebasic commands like "string text in commas" or "dim" and "function" etc... however the code of the parser is a mess lots of line are commented and it's hard to figure what does what or who is what... i wish to make the parser better that is to color more FB commands and keywords yet it's hard to understand how to do so... i laso don't understand where are the data for the keywords/commands that is uses to color the commands...

i bring you the full code of the parser in the hope that someone can explain to me how to add more keywords to be highlighted - also for some reason i cannot use the tab in the richtext component although i clearly made sure that property "acceptTab" will be set to true... (it worked in the textbox component) - anyway here is the parser full code... any help will be appreciated...

file Parser.inc:

https://pastebin.com/dbkA0RTX

ron77

 8 
 on: April 11, 2021, 04:58:55 AM 
Started by Bumblebee - Last post by Bumblebee
I couldn't have written a backup program without CWSTR variables and arrays. My previous backup program written in VB6 did not manage files with non-latin characters properly. It was always on my "to be resolved" list.

I don't do enough programming to encounter enough problems to learn to replace old ways of doing things, with the new.

 9 
 on: April 10, 2021, 03:46:51 PM 
Started by jermy - Last post by jermy
It is being overwritten by the RichEdit control. Change the position of the ListBox.

yes that's it, thanks.

How can I be so blind? It must be because of corona.
Code: [Select]
          pWindow->SetWindowPos GetDlgItem(hwnd, IDC_LISTBOX), Null, pWindow->UnScaleX(pt.x) + 15, pWindow->UnScaleY(pt.y) + 27, 100, 80, SWP_SHOWWINDOW

 10 
 on: April 10, 2021, 03:31:10 PM 
Started by jermy - Last post by Josť Roca
It is being overwritten by the RichEdit control. Change the position of the ListBox.

Pages: [1] 2 3 ... 10