Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Excel Font Generator Tool "copy to clipboard" doesn't work on windows 10. But I found a solution. #58

Open
Cherianpaul opened this issue Nov 17, 2023 · 6 comments
Assignees
Labels

Comments

@Cherianpaul
Copy link

IMPORTANT

Before submitting this issue
[] Have you tried using the latest version of the library?
[
] Have you checked this has not already been submitted and/or resolved?
[ ] If you are requesting help a better choice may be the Arduino forum

Subject of the issue

The Excel Font Generator Tool "copy to clipboard" doesn't work on windows 10. But I found a solution.

Your Environment

Library Version:
Arduino IDE version:
Host OS and Version:
CPU Hardware model/type:
Matrix hardware model/type: [ ] Parola [ ] Generic [ ] ICStation [*] FC-16 [ ] Custom (describe how wired)

Steps to Reproduce

It is not with Arduino code, it is about the Excel Font Generator Tool.

Expected Behaviour

It should copy the generated array into clipboard.

Actual Behaviour

It does not copy as obj.PutInClipboard does not work on windows 10.

Code Demonstrating the Issue

MyDataObj.PutInClipboard
@Cherianpaul
Copy link
Author

Cherianpaul commented Nov 17, 2023

Solution found from this link : https://chandoo.org/forum/threads/clipboard-copy-vba-code-not-working-in-windows-10.37126/post-223256

Option Explicit
#If Mac Then
' ignore
#Else
#If VBA7 Then
Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As LongPtr) As LongPtr
Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
ByVal dwBytes As LongPtr) As LongPtr

    Declare PtrSafe Function CloseClipboard Lib "User32" () As Long
    Declare PtrSafe Function OpenClipboard Lib "User32" (ByVal hwnd As LongPtr) As LongPtr
    Declare PtrSafe Function EmptyClipboard Lib "User32" () As Long

    Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
                                                     ByVal lpString2 As Any) As LongPtr

    Declare PtrSafe Function SetClipboardData Lib "User32" (ByVal wFormat _
                                                            As Long, ByVal hMem As LongPtr) As LongPtr
#Else
    Declare PtrSafe Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
    Declare PtrSafe Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
    Declare PtrSafe Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, _
                                                 ByVal dwBytes As Long) As Long

    Declare PtrSafe Function CloseClipboard Lib "User32" () As Long
    Declare PtrSafe Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
    Declare PtrSafe Function EmptyClipboard Lib "User32" () As Long

    Declare PtrSafe Function lstrcpy Lib "kernel32" (ByVal lpString1 As Any, _
                                             ByVal lpString2 As Any) As Long

    Declare PtrSafe Function SetClipboardData Lib "User32" (ByVal wFormat _
                                                    As Long, ByVal hMem As Long) As Long
#End If

#End If
Public Const GHND = &H42
Public Const CF_TEXT = 1
Public Const MAXSIZE = 4096

Sub ClipBoard_SetData(MyString As String)
#If Mac Then
With New MSForms.DataObject
.SetText MyString
.PutInClipboard
End With
#Else
#If VBA7 Then
Dim hGlobalMemory As LongPtr
Dim hClipMemory As LongPtr
Dim lpGlobalMemory As LongPtr
#Else
Dim hGlobalMemory As Long
Dim hClipMemory As Long
Dim lpGlobalMemory As Long
#End If

    Dim x                 As Long

    ' Allocate moveable global memory.
    '-------------------------------------------
    hGlobalMemory = GlobalAlloc(GHND, Len(MyString) + 1)

    ' Lock the block to get a far pointer
    ' to this memory.
    lpGlobalMemory = GlobalLock(hGlobalMemory)

    ' Copy the string to this global memory.
    lpGlobalMemory = lstrcpy(lpGlobalMemory, MyString)

    ' Unlock the memory.
    If GlobalUnlock(hGlobalMemory) <> 0 Then
        MsgBox "Could not unlock memory location. Copy aborted."
        GoTo OutOfHere2
    End If

    ' Open the Clipboard to copy data to.
    If OpenClipboard(0&) = 0 Then
        MsgBox "Could not open the Clipboard. Copy aborted."
        Exit Sub
    End If

    ' Clear the Clipboard.
    x = EmptyClipboard()

    ' Copy the data to the Clipboard.
    hClipMemory = SetClipboardData(CF_TEXT, hGlobalMemory)

OutOfHere2:

    If CloseClipboard() = 0 Then
        MsgBox "Could not close Clipboard."
    End If
#End If

End Sub

then call it like this:
Code:
ClipBoard_SetData "your text here"

@MajicDesigns MajicDesigns self-assigned this Nov 17, 2023
@MajicDesigns
Copy link
Owner

MajicDesigns commented Nov 17, 2023

This will need fixing. I don't have easy access to Microsoft Office any more so it may take a while. Are you able to implement a fix and submit?

@Cherianpaul
Copy link
Author

Cherianpaul commented Nov 17, 2023

Parola MD_MAX72xx Font Builder v4.zip
Sure. No problem.
I attached it here.

@MajicDesigns
Copy link
Owner

Better you email the excel file directly to me.

@Cherianpaul
Copy link
Author

Your email?

@MajicDesigns
Copy link
Owner

Oops, forgot that I made it private here. OK, try and attach the file to one of these comments. The toolbar above the text as you type has a paperclip for attachment. Not sure if there is a size limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants