PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 4

Author Topic: CWindow Release Candidate 27  (Read 3765 times)

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
CWindow Release Candidate 27
« on: March 19, 2017, 04:56:35 AM »

Added wrappers for the Rich Edit control.

Small modification in a couple of methods of the CTextStream class.

Modified the AfxAddTooltip, AfxSetTooltipText and AfxDeleteTooltip to check if the passed handle is a window or a child control.
« Last Edit: March 19, 2017, 05:00:16 AM by Josť Roca »
Logged

David Warner

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 110
Re: CWindow Release Candidate 27
« Reply #1 on: March 19, 2017, 05:21:33 PM »

Thank you Josť.  :)
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8104
  • Windows 10
    • PlanetSquires Software
Re: CWindow Release Candidate 27
« Reply #2 on: March 21, 2017, 02:34:38 PM »

Thanks Josť! Appreciate it!
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Marc Giao

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 35
Re: CWindow Release Candidate 27
« Reply #3 on: March 21, 2017, 03:07:26 PM »

Thank you very much Josť... What would we do without you ;)
Logged
Marc

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 27
« Reply #4 on: March 23, 2017, 02:50:45 PM »

Weird. The code has been downloaded 22 times and the help file 60!

David Warner

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 110
Re: CWindow Release Candidate 27
« Reply #5 on: March 23, 2017, 04:41:25 PM »

When I downloaded the files the help file download failed and I needed to do it again. Perhaps this accounts for the disparity.
Logged

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 24
Re: CWindow Release Candidate 27
« Reply #6 on: April 18, 2017, 11:07:33 AM »

hi,Josť Roca

I suggest renaming the afxmsg function to the Afxmsgbox function,and add a Title Parameter for non English speaking areas. would it be better than always showing "message" title?
The CWindow framework is a very powerful framework for freebasic use in Windows, you have done a great job, thank you very much!
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 27
« Reply #7 on: April 18, 2017, 11:26:25 AM »

This function is intended as a quick way to display a message box, mainly for debugging purposes. This is why it uses a short name and only needs to pass the text to display. In production code, I always use the Windows API function MessageBox, that allows to specify the parent window, the text to display, the caption and the type.

Andrew Lindsay

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 68
Re: CWindow Release Candidate 27
« Reply #8 on: April 23, 2017, 09:10:56 PM »

Jose,

Thanks so much for this.  I have been mashing around my own RTF stuff for about 18 months.  I had a few glitches that seemed to be a memory leak from somewhere, but as is usually the case, your code bolts in with a minimal amount of work and just does what is says on the box.

Love your work.
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 27
« Reply #9 on: April 23, 2017, 09:50:11 PM »

Thanks for your kind words. I have noticed that I forgot to add PRIVATE to the SUBs. I have added it in the attached file. Not very important, but it will save some bytes.

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 24
Re: CWindow Release Candidate 27
« Reply #10 on: April 29, 2017, 10:49:13 PM »

hi,Josť Roca

Why not encapsulate an easy-to-use thread class and add it to the CWindow frame?
Please forgive me for my reckless request.

thank you very much!

ganlinlao
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 27
« Reply #11 on: April 30, 2017, 09:33:07 AM »

I don't have expertise with threads. Maybe this thread class posted in the FB forum can be useful:
http://www.freebasic.net/forum/viewtopic.php?t=10053

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 27
« Reply #12 on: May 03, 2017, 07:13:26 PM »

Next version will include a localized Input Box dialog. Localization of the buttons is achieved by extracting the strings from the resource file of user32.dll (works also with 64 bit).

Usage example:
Code: [Select]
DIM cws AS CWSTR = AfxInputBox(hwnd, 0, 0, "InputBox test", "What's your name?", "My name is Josť")


Code: [Select]
' ########################################################################################
'                                *** INPUT BOX DIALOG ***
' ########################################################################################

' ========================================================================================
' Input box dialog
' Parameters:
' - hParent = Handle of the parent window
' - x, y = The location on the screen to display the dialog. If both are 0, the dialog
'   is centered on the screen.
' - cwsCaption = Caption of the window
' - cwsPrompt = Prompt string
' - cwsText = Text to edit
' - nLen = [opt] Maximum length of the string to edit (default = 260 characters)
' - bPassword = [opt] TRUE or FALSE. Default FALSE. Displays all characters as an
'     asterisk (*) as they are typed into the edit control.
'   Note: The maximum length is 2048 characters.
' ========================================================================================
' Forward declaration of the callback function
DECLARE FUNCTION AfxInputBoxWindowProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT
' ========================================================================================
PRIVATE FUNCTION AfxInputBox (BYVAL hParent AS HWND, BYVAL x AS LONG, BYVAL y AS LONG, _
BYREF cwsCaption AS CWSTR, BYREF cwsPrompt AS CWSTR, BYREF cwsText AS CWSTR, _
BYVAL nLen AS LONG = 260, BYVAL bPassword AS BOOLEAN = FALSE) AS CWSTR

   ' // Create the window
   DIM pInputBox AS CWindow
   DIM dwStyle AS DWORD = WS_VISIBLE OR WS_CAPTION OR WS_POPUPWINDOW
   DIM dwExStyle AS DWORD = WS_EX_DLGMODALFRAME OR WS_EX_CONTROLPARENT
   DIM hInputBox AS HWND = pInputBox.Create(hParent, **cwsCaption, @AfxInputBoxWindowProc, x, y, 326, 142, dwStyle, dwExStyle)
   ' // Center the window
   IF x = 0 AND y = 0 THEN pInputBox.Center(hInputBox, hParent)
   ' // Add a label control
   pInputBox.AddControl("Label", hInputBox, -1, **cwsPrompt, 21, 10, 280, 19)
   ' // Add a TextBox control
   dwStyle = WS_VISIBLE OR WS_TABSTOP OR ES_LEFT OR ES_AUTOHSCROLL
   IF bPassWord THEN dwStyle = dwStyle OR ES_PASSWORD
   DIM hEdit AS HWND = pInputBox.AddControl("Edit", hInputBox, 101, "", 21, 33, 280, 19, dwStyle)
   ' // Add the buttons
   DIM hOkButton AS HWND = pInputBox.AddControl("Button", hInputBox, IDOK, "&Ok", 21, 72, 75, 22)
   DIM hCancelButton AS HWND = pInputBox.AddControl("Button", hInputBox, IDCANCEL, "&Cancel", 226, 72, 75, 22)
   ' // Localized strings. In the resource file of user32.dll, the OK button has
   ' // IDS_OK (801) as the identifier and the Cancel button IDS_CANCEL (801).
   DIM hUser32Instance AS HINSTANCE = GetModuleHandleW("user32.dll")
   DIM wszOk AS WSTRING * 260
   DIM cbLen AS LONG = LoadStringW(hUser32Instance, 800, @wszOk, SIZEOF(wszOk))
   IF cbLen THEN wszOk = "&" & wszOk : SendMessageW(hOkButton, WM_SETTEXT, 0, cast(LPARAM, @wszOk))
   DIM wszCancel AS WSTRING * 260
   cbLen = LoadStringW(hUser32Instance, 801, @wszCancel, SIZEOF(wszCancel))
   IF cbLen THEN wszCancel = "&" & wszCancel : SendMessageW(hCancelButton, WM_SETTEXT, 0, cast(LPARAM, @wszCancel))
   ' // Set the text and the limit
   IF nLen = 0 THEN nLen = 260
   IF nLen < 1 OR nLen > 2048 THEN nLen = 2048
   SendMessageW hEdit, EM_LIMITTEXT, nLen, 0
   IF LEN(cwsText) > nLen THEN cwsText = LEFT(**cwsText, nLen)
   SendMessageW(hEdit, WM_SETTEXT, 0, cast(LPARAM, *cwsText))
   SendMessageW(hEdit, EM_SETSEL, 0, -1)
   ' // Set the focus in the edit control
   SetFocus hEdit
   ' // Pointer to the allocated string to return the result
   DIM wszOut AS WSTRING * 2049
   SendMessageW hInputBox, WM_USER + 1, CAST(WPARAM, @wszOut), 0
   ' // Process Windows messages
   pInputBox.DoEvents
   ' // Enable the parent window
   EnableWindow hParent, CTRUE
   ' // Return the output string
   RETURN wszOut

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

' ========================================================================================
' Input box callback function.
' ========================================================================================
PRIVATE FUNCTION AfxInputBoxWindowProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   STATIC pText AS WSTRING PTR   ' // Pointer to the string buffer

   SELECT CASE uMsg
      CASE WM_CREATE
         ' Disable parent window to make popup window modal
         EnableWindow GetParent(hwnd), FALSE
         EXIT FUNCTION
      CASE WM_USER + 1
         ' // Pointer to allocated string to return the result
         IF wParam THEN
            pText = cast(WSTRING PTR, wParam)
            EXIT FUNCTION
         END IF
      CASE WM_COMMAND
         SELECT CASE GET_WM_COMMAND_ID(wParam, lParam)
            CASE IDCANCEL
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
            CASE IDOK
               IF GET_WM_COMMAND_CMD(wParam, lParam) = BN_CLICKED THEN
                  DIM nLen AS LONG = SendMessageW(GetDlgItem(hwnd, 101), WM_GETTEXTLENGTH, 0, 0)
                  IF nLen > 2048 THEN nLen = 2048
                  nLen = SendMessageW(GetDlgItem(hwnd, 101), WM_GETTEXT, nLen + 1, cast(.LPARAM, pText))
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT
      CASE WM_CLOSE
         ' // Enables parent window keeping parent's zorder
         EnableWindow GetParent(hwnd), CTRUE
         ' // Don't exit; let DefWindowProcW perform the default action
      CASE WM_DESTROY
         ' // Close the main window
         PostQuitMessage(0)
         EXIT FUNCTION
   END SELECT

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

END FUNCTION
' ========================================================================================
« Last Edit: May 03, 2017, 11:25:19 PM by Josť Roca »
Logged

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 24
Re: CWindow Release Candidate 27
« Reply #13 on: May 03, 2017, 09:26:20 PM »

hi,Josť Roca
I use AfxNewCom ("Excel.Application"), but it cannot return  Excel.Application objects

How to call Excel.Application correctly?

I like others, I hope you can retain the COM-related classes in the framework, we can not use IE, we can not use Ocx, but many people have to use the Ms-offIce software, many people uses the Ms-office x64-bit Edition, which requires FreeBASIC to support and compile 64-bit tools, if Ms-office dies, and then removes COM-related classes, otherwise, COM-related classes, There are still many people who need to use it.
Your profound knowledge will bring more simple, easier, more powerful tools, making it easier to use Freebasic  for others.

Please

thanks
ganlinlao
« Last Edit: May 03, 2017, 09:42:30 PM by ganlinlao »
Logged

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2785
    • Josť Roca Software
Re: CWindow Release Candidate 27
« Reply #14 on: May 03, 2017, 10:21:18 PM »

Office applications can only be used with COM Automation, i.e. through the Invoke method of the IDispatch interface. Although their type libraries let you think that they expose dual interfaces, it isn't true. If you do calls through the VTable, the methods that should return pointers to other VTable interfaces return pointers to the automation interfaces, and if you use them, your application will crash. Besides, I don't have Office installed since many years ago. I use Libre Office, that is free.

> we can not use IE, we can not use Ocx

You can. My framework includes an OLE container that allows you to embed the WebBrowser control. Many OCXs will also work with it, although not all. I have provided several examples.

> I like others, I hope you can retain the COM-related classes in the framework

Without native support for BSTR and VARIANTs it is difficult. I tried to implement classes to support them, but I was not fully satisfied with the results. There is also the problem that variadic functions don't work with Free Basic 64 bit.
« Last Edit: May 03, 2017, 10:42:36 PM by Josť Roca »
Logged
Pages: [1] 2 3 4