September 25, 2020, 02:23:02 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Special characters on windows

Started by fasecero, October 14, 2017, 06:31:32 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

I made another one for fun. This sample uses unicode symbols inside labels and buttons. Take your browser and search for "unicode characters" or "unicode character list", there are tons of websites with those symbols. To build a wstring one, just use GetUnicodeChar(byte1, byte2), these bytes can be found by using "string bytes" that I did the other day. Have fun.

Code Select


$INCLUDE "windowssdk.inc"
$include "commctrl.inc"

'------------------------------------------
' VARIBLES
'------------------------------------------

HFONT guiFont = 0
HFONT bigFont = 0
INT backColor = GetSysColor(COLOR_BTNFACE)
HBRUSH hBrush = CreateSolidBrush(backColor)
INT SUBCLASS_ID = 12345

'------------------------------------------
' INTERFACE
'------------------------------------------

CONST STATIC_1 = 1
CONST STATIC_2 = 2
CONST STATIC_3 = 3
CONST STATIC_4 = 4
CONST STATIC_5 = 5
CONST STATIC_6 = 6
CONST BUTTON_7 = 7
CONST UPDOWN_1 = 8
CONST UPDOWN_2 = 9
CONST EDIT_10 = 10
CONST EDIT_11 = 11
CONST STATIC_12 = 12
DIALOG d1
CREATEDIALOG d1,0,0,500,220,0x80C80080,0,"",&d1_handler
'CONTROL d1,@STATIC,"Static",18,13,70,20,0x5000010B,STATIC_1
'CONTROL d1,@STATIC,"Static",17,39,70,20,0x5000010B,STATIC_2
'CONTROL d1,@STATIC,"Static",15,82,70,20,0x5000010B,STATIC_3
'CONTROL d1,@STATIC,"Static",14,110,70,20,0x5000010B,STATIC_4
'CONTROL d1,@STATIC,"Static",14,152,70,20,0x5000010B,STATIC_5
'CONTROL d1,@STATIC,"Static",18,197,70,20,0x5000010B,STATIC_6
'CONTROL d1,@BUTTON,"Button1",147,194,70,20,0x50000000,BUTTON_7
CONTROL d1,@EDIT,"",412,12,40,20,0x50802000,EDIT_10
CONTROL d1,@EDIT,"",332,12,40,20,0x50802000,EDIT_11

'------------------------------------------
' PROGRAM ENTRY POINT
'------------------------------------------

DOMODAL d1

'------------------------------------------
' PROCEDURE
'------------------------------------------

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
OnInit()
CASE @IDCLOSEWINDOW
OnFinish()
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_7
IF @NOTIFYCODE = 0
/*button clicked*/
_SendMessage(d1.hwnd, WM_CLOSE, 0, 0)
ENDIF
CASE EDIT_10
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENCHANGE
OnEdit()
ENDSELECT
CASE EDIT_11
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENCHANGE
OnEdit()
ENDSELECT
ENDSELECT
ENDSELECT
RETURN
ENDSUB

SUB MySubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
SELECT (uMsg)
CASE WM_CTLCOLORSTATIC
   INT hDC = wParam
   SetTextColor(hDC, RGB(0,0,0))
   SetBkColor(hDC, backColor)
   return hBrush
ENDSELECT

RETURN DefSubclassProc(hWnd, uMsg, wParam, lParam)
ENDSUB

'------------------------------------------
' EVENTS
'------------------------------------------

SUB OnInit()
SetWindowSubclass(d1.hwnd, &MySubclassProc, SUBCLASS_ID, 0)

guiFont = CreateGuiFont()
bigFont = CreateFontW (90, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Arial")

INITCOMMONCONTROLSEX icex
    icex.dwSize = LEN(icex)
    icex.dwICC  = ICC_UPDOWN_CLASS
    InitCommonControlsEx(&icex)

UnicodeLabelCreate(d1, STATIC_1, 18, 12, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_1, GetUnicodeChar(240 ,35) + L" Please wait a few moments...")

UnicodeLabelCreate(d1, STATIC_2, 18, 36, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_2, GetUnicodeChar(20 ,39) + L" Done")

UnicodeLabelCreate(d1, STATIC_3, 18, 72, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_3, GetUnicodeChar(14 ,38) + L" phone: +1-202-555-0171")

UnicodeLabelCreate(d1, STATIC_4, 18, 96, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_4, GetUnicodeChar(9 ,39) + L" email: support@nosupport.com")

UnicodeLabelCreate(d1, STATIC_5, 18, 132, 300, 24, guiFont, SS_LEFT)
wstring star1 = GetUnicodeChar(5 ,38)
wstring star2 = GetUnicodeChar(6 ,38)
wstring text = star1+star1+star1+star1+star2
UnicodeControlSetText(d1, STATIC_5, L"Rating " + text)

UnicodeLabelCreate(d1, STATIC_6, 18, 172, 300, 24, guiFont, SS_RIGHT)
UnicodeControlSetText(d1, STATIC_6, L"Press this button to exit " + GetUnicodeChar(146 ,33))

UnicodeButtonCreate(d1, BUTTON_7, 330, 168, 140, 24, guiFont)
UnicodeControlSetText(d1, BUTTON_7, GetUnicodeChar(24 ,39) + L" Exit")

UpDownCreate(d1, UPDOWN_1, 452, 11, 30, 20, guiFont, EDIT_10)
UpDownSetRange(d1, UPDOWN_1, 0, 255)
UpDownSetValue(d1, UPDOWN_1, 242)

UpDownCreate(d1, UPDOWN_2, 373, 11, 30, 20, guiFont, EDIT_11)
UpDownSetRange(d1, UPDOWN_2, 0, 255)
UpDownSetValue(d1, UPDOWN_2, 35)

UnicodeLabelCreate(d1, STATIC_12, 336, 35, 125, 125, bigFont, SS_CENTER)
OnEdit()
ENDSUB

SUB OnFinish()
RemoveWindowSubclass(d1.hwnd, &MySubclassProc, SUBCLASS_ID)

DeleteGuiFont(guiFont)
IF bigFont THEN DeleteObject(bigFont)
ENDSUB

SUB OnEdit()
WSTRING character = L""
STRING text1 = GETCONTROLTEXT (d1, EDIT_10)
INT value1 = VAL(text1)

STRING text2 = GETCONTROLTEXT (d1, EDIT_11)
INT value2 = VAL(text2)

IF value1 >= 0 AND value1 <= 255 AND value2 >= 0 AND value2 <= 255 THEN
character = GetUnicodeChar(value1, value2)
ENDIF

UnicodeControlSetText(d1, STATIC_12, character)
ENDSUB

'------------------------------------------
' UNICODE FUNCTIONS
'------------------------------------------

SUB GetUnicodeChar(char byte1, char byte2), wstring
iwstring c[4] : pointer p = &c + 0
*<char>p = byte1 : p+=1
*<char>p = byte2 : p+=1
*<char>p = 0 : p+=1
*<char>p = 0
RETURN c
ENDSUB

SUB UnicodeLabelCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT font, INT align)
INT dwStyles = WS_CHILD | WS_VISIBLE | ES_LEFT | align
INT hwndEDIT = CreateWindowExW(0, L"STATIC", NULL, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwndEDIT, WM_SETFONT, font, MAKELPARAM(TRUE,0) )
ENDSUB

SUB UnicodeButtonCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT font)
INT dwStyles = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
INT hwndEDIT = CreateWindowExW(0, L"BUTTON", NULL, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwndEDIT, WM_SETFONT, font, MAKELPARAM(TRUE,0) )
ENDSUB

SUB UnicodeControlSetText(window w, INT ctrlID, pointer buffer)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
SetWindowTextW(hwnd, buffer)
ENDSUB

'------------------------------------------
' GUI FONT
'------------------------------------------

SUB CreateGuiFont(), INT
NONCLIENTMETRICSW metrics
metrics.cbSize = LEN(metrics)
SystemParametersInfow(SPI_GETNONCLIENTMETRICS, LEN(metrics), &metrics, 0)
RETURN CreateFontIndirectW(&metrics.lfSmCaptionFont)
ENDSUB

SUB DeleteGuiFont(INT font)
IF font THEN DeleteObject(font)
ENDSUB

'------------------------------------------
' UP-DOWN CONTROL
'------------------------------------------

SUB UpDownCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT font, INT editId)
INT dwStyles = WS_CHILD | WS_VISIBLE | UDS_SETBUDDYINT
INT hwnd = CreateWindowEx(0, UPDOWN_CLASS, NULL, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwnd, WM_SETFONT, font, MAKELPARAM(TRUE,0) )
_SendMessage(hwnd, UDM_SETBUDDY , GetDlgItem(w.hwnd, editId), 0)
ENDSUB

SUB UpDownSetRange(window w, INT ctrlID, word min, word max)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
_SendMessage(hwnd, UDM_SETRANGE, 0, MAKELPARAM(max, min))
ENDSUB

SUB UpDownSetValue(window w, INT ctrlID, word value)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
_SendMessage(hwnd, UDM_SETPOS, 0, value)
ENDSUB


Andy

That's very very nice!  8)

One question - is it possible to change the font size of a specific unicode character? I tried setfont but it changed everything instead of one specific control.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

Thanks! If you want to change the text size of all the content of one control then sure, create a new font and asign it to the control. But, I suspect you want to change the size of some characters only. If this is the case then it should be posible using ownerdraw but you know, It's a very hard thing to do. LarryMc has made some amazing tutorials about it. Otherwise you could create an unicode richedit and load some formated text from a .rtf file. I think I have some old code featuring a rich ctrl, I will check it.

fasecero

Here it goes an update for more complex text arrangements. Formatted unicode can now be inserted into a "modified" richedit that behaves like a static. At first I tried to fill the richedit content from code but it became a very cumbersome and difficult process, so I was quite correct about loading text from disk. So text is loaded from an rtf file called text.rtf, attached here. I recommend editing the .rtf file using the old WordPad instead of the well-known Microsoft Word for back-compatibility's sake. Of course once you open the rtf file you can edit text, font, size, style and color without limitation.

EDIT: rtf file is located inside the zip, I couldn't attach the rtf file directly.

Code Select

$INCLUDE "windowssdk.inc"
$include "commctrl.inc"
$INCLUDE "Richedit.inc"

'------------------------------------------
' VARIBLES
'------------------------------------------

HFONT guiFont = 0
HFONT bigFont = 0
INT backColor = RGB(255,255,255) ' GetSysColor(COLOR_BTNFACE)
HBRUSH hBrush = CreateSolidBrush(backColor)
UINT hInstRE20 = 0 ' UNICODE RichEdit ver 2.0
INT SUBCLASS_ID = 12345
INT SUBCLASS_RE_ID = 67890

'------------------------------------------
' INTERFACE
'------------------------------------------

CONST STATIC_1 = 1
CONST STATIC_2 = 2
CONST STATIC_3 = 3
CONST STATIC_4 = 4
CONST STATIC_5 = 5
CONST STATIC_6 = 6
CONST BUTTON_7 = 7
CONST UPDOWN_1 = 8
CONST UPDOWN_2 = 9
CONST EDIT_10 = 10
CONST EDIT_11 = 11
CONST STATIC_12 = 12
CONST RICH_20 = 20
DIALOG d1
CREATEDIALOG d1,0,0,500,260,0x80C80080,0,"",&d1_handler
'CONTROL d1,@STATIC,"Static",18,13,70,20,0x5000010B,STATIC_1
'CONTROL d1,@STATIC,"Static",17,39,70,20,0x5000010B,STATIC_2
'CONTROL d1,@STATIC,"Static",15,82,70,20,0x5000010B,STATIC_3
'CONTROL d1,@STATIC,"Static",14,110,70,20,0x5000010B,STATIC_4
'CONTROL d1,@STATIC,"Static",14,152,70,20,0x5000010B,STATIC_5
'CONTROL d1,@STATIC,"Static",18,197,70,20,0x5000010B,STATIC_6
'CONTROL d1,@BUTTON,"Button1",147,194,70,20,0x50000000,BUTTON_7
CONTROL d1,@EDIT,"",332,12,40,20,0x50802000,EDIT_10
CONTROL d1,@EDIT,"",412,12,40,20,0x50802000,EDIT_11

'------------------------------------------
' PROGRAM ENTRY POINT
'------------------------------------------

DOMODAL d1

'------------------------------------------
' PROCEDURE
'------------------------------------------

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
OnInit()
CASE @IDCLOSEWINDOW
OnFinish()
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_7
IF @NOTIFYCODE = 0
/*button clicked*/
_SendMessage(d1.hwnd, WM_CLOSE, 0, 0)
ENDIF
CASE EDIT_10
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENCHANGE
OnEdit()
ENDSELECT
CASE EDIT_11
/* respond to edit notifications here */
SELECT @NOTIFYCODE
CASE @ENCHANGE
OnEdit()
ENDSELECT
ENDSELECT
ENDSELECT
RETURN
ENDSUB

SUB MySubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
INT hDC
WINRECT rc

SELECT (uMsg)
CASE WM_ERASEBKGND ' painting dialog background
hDC = wParam
GetClientRect(hwnd, &rc)
FillRect(hdc, &rc, hBrush)
RETURN 1

CASE WM_CTLCOLORSTATIC ' painting static's text & back
   hDC = wParam
   
   IF lParam = GetDlgItem(d1.hwnd, STATIC_2) THEN
SetTextColor(hDC, RGB(100,107,134))
   ELSE
SetTextColor(hDC, RGB(0,0,0))
   ENDIF
   
   SetBkColor(hDC, backColor)
   return hBrush
ENDSELECT

RETURN DefSubclassProc(hWnd, uMsg, wParam, lParam)
ENDSUB

' this procedure makes the richedit behave like a static
SUB MyRichEditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
SELECT (uMsg)
CASE WM_SETCURSOR
RETURN TRUE ' this prevents the selection cursor from being displayed
CASE WM_MOUSEACTIVATE
RETURN MA_NOACTIVATEANDEAT ' this prevents any selection on the richedit
ENDSELECT

RETURN DefSubclassProc(hWnd, uMsg, wParam, lParam)
ENDSUB

'------------------------------------------
' EVENTS
'------------------------------------------

SUB OnInit()
OleInitialize(0)

SetWindowSubclass(d1.hwnd, &MySubclassProc, SUBCLASS_ID, 0)

guiFont = CreateFontW (18, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Segoe UI") ' CreateGuiFont()
bigFont = CreateFontW (90, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Arial")

INITCOMMONCONTROLSEX icex
    icex.dwSize = LEN(icex)
    icex.dwICC  = ICC_UPDOWN_CLASS
    InitCommonControlsEx(&icex)

hInstRE20 = LoadLibraryW(L"riched20.dll") ' RichEdit ver 2.0

UnicodeLabelCreate(d1, STATIC_1, 18, 12, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_1, GetUnicodeChar(240 ,35) + L" Please wait a few moments...")

UnicodeLabelCreate(d1, STATIC_2, 18, 36, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_2, GetUnicodeChar(20 ,39) + L" Done")

UnicodeLabelCreate(d1, STATIC_3, 18, 72, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_3, GetUnicodeChar(14 ,38) + L" phone: +1-202-555-0171")

UnicodeLabelCreate(d1, STATIC_4, 18, 96, 300, 24, guiFont, SS_LEFT)
UnicodeControlSetText(d1, STATIC_4, GetUnicodeChar(9 ,39) + L" email: support@nosupport.com")

UnicodeLabelCreate(d1, STATIC_5, 18, 132, 300, 24, guiFont, SS_LEFT)
wstring star1 = GetUnicodeChar(5 ,38)
wstring star2 = GetUnicodeChar(6 ,38)
wstring text = star1+star1+star1+star1+star2
UnicodeControlSetText(d1, STATIC_5, L"Rating " + text)

UnicodeLabelCreate(d1, STATIC_6, 18, 172, 300, 24, guiFont, SS_RIGHT)
UnicodeControlSetText(d1, STATIC_6, L"Press this button to exit " + GetUnicodeChar(146 ,33))

UnicodeButtonCreate(d1, BUTTON_7, 330, 168, 140, 24, guiFont)
UnicodeControlSetText(d1, BUTTON_7, GetUnicodeChar(24 ,39) + L" Exit")

UpDownCreate(d1, UPDOWN_1, 373, 11, 30, 20, guiFont, EDIT_10)
UpDownSetRange(d1, UPDOWN_1, 0, 255)
UpDownSetValue(d1, UPDOWN_1, 244)

UpDownCreate(d1, UPDOWN_2, 452, 11, 30, 20, guiFont, EDIT_11)
UpDownSetRange(d1, UPDOWN_2, 0, 255)
UpDownSetValue(d1, UPDOWN_2, 38)

UnicodeLabelCreate(d1, STATIC_12, 336, 35, 125, 125, bigFont, SS_CENTER)
OnEdit()

UnicodeRichCreate(d1, RICH_20, 18, 215, 460, 50, backColor, &MyRichEditProc, SUBCLASS_RE_ID)
UnicodeRichLoad(d1, RICH_20, L"text.rtf")
ENDSUB

SUB OnFinish()
RemoveWindowSubclass(d1.hwnd, &MySubclassProc, SUBCLASS_ID)

DeleteGuiFont(guiFont)
IF bigFont THEN DeleteObject(bigFont)

UnicodeRichDestroy(d1, RICH_20, &MyRichEditProc, SUBCLASS_RE_ID)
IF hInstRE20 THEN FreeLibrary(hInstRE20)
ENDSUB

SUB OnEdit()
WSTRING character = L""
STRING text1 = GETCONTROLTEXT (d1, EDIT_10)
INT value1 = VAL(text1)

STRING text2 = GETCONTROLTEXT (d1, EDIT_11)
INT value2 = VAL(text2)

IF value1 >= 0 AND value1 <= 255 AND value2 >= 0 AND value2 <= 255 THEN
character = GetUnicodeChar(value1, value2)
ENDIF

UnicodeControlSetText(d1, STATIC_12, character)
ENDSUB

'------------------------------------------
' UNICODE FUNCTIONS
'------------------------------------------

SUB GetUnicodeChar(char byte1, char byte2), wstring
iwstring c[4] : pointer p = &c + 0
*<char>p = byte1 : p+=1
*<char>p = byte2 : p+=1
*<char>p = 0 : p+=1
*<char>p = 0
RETURN c
ENDSUB

SUB UnicodeLabelCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT font, INT align)
INT dwStyles = WS_CHILD | WS_VISIBLE | ES_LEFT | align
INT hwndEDIT = CreateWindowExW(0, L"STATIC", NULL, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwndEDIT, WM_SETFONT, font, MAKELPARAM(TRUE,0) )
ENDSUB

SUB UnicodeButtonCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT font)
INT dwStyles = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
INT hwndEDIT = CreateWindowExW(0, L"BUTTON", NULL, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwndEDIT, WM_SETFONT, font, MAKELPARAM(TRUE,0) )
ENDSUB

SUB UnicodeControlSetText(window w, INT ctrlID, pointer buffer)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
SetWindowTextW(hwnd, buffer)
ENDSUB

'------------------------------------------
' GUI FONT
'------------------------------------------

SUB CreateGuiFont(), INT
NONCLIENTMETRICSW metrics
metrics.cbSize = LEN(metrics)
SystemParametersInfow(SPI_GETNONCLIENTMETRICS, LEN(metrics), &metrics, 0)
RETURN CreateFontIndirectW(&metrics.lfSmCaptionFont)
ENDSUB

SUB DeleteGuiFont(INT font)
IF font THEN DeleteObject(font)
ENDSUB

'------------------------------------------
' UP-DOWN CONTROL
'------------------------------------------

SUB UpDownCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT font, INT editId)
INT dwStyles = WS_CHILD | WS_VISIBLE | UDS_SETBUDDYINT
INT hwnd = CreateWindowEx(0, UPDOWN_CLASS, NULL, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwnd, WM_SETFONT, font, MAKELPARAM(TRUE,0) )
_SendMessage(hwnd, UDM_SETBUDDY , GetDlgItem(w.hwnd, editId), 0)
ENDSUB

SUB UpDownSetRange(window w, INT ctrlID, word min, word max)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
_SendMessage(hwnd, UDM_SETRANGE, 0, MAKELPARAM(max, min))
ENDSUB

SUB UpDownSetValue(window w, INT ctrlID, word value)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
_SendMessage(hwnd, UDM_SETPOS, 0, value)
ENDSUB

'------------------------------------------
' UNICODE RICHEDIT
'------------------------------------------

SUB UnicodeRichCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, INT backcolor, pointer richProc, INT subclassid)
INT dwStyles = WS_CHILD | WS_VISIBLE | ES_READONLY | ES_MULTILINE | ES_CENTER
    INT hwnd = CreateWindowExW(0, RICHEDIT_CLASSW, L"", dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
SendMessageW(hwnd, EM_SETBKGNDCOLOR, 0, backcolor)
SetWindowSubclass(hwnd, richProc, subclassid, 0)
ENDSUB

SUB UnicodeRichDestroy(window w, INT ctrlID, pointer richProc, INT subclassid)
INT hwnd = GetDlgItem(w.hwnd, ctrlID)
RemoveWindowSubclass(hwnd, richProc, subclassid)
DestroyWindow(hwnd)
ENDSUB

SUB UnicodeRichLoad(window w, INT ctrlID, wstring szFileName), INT
HANDLE hFile
EDITSTREAM es

INT hwnd = GetDlgItem(w.hwnd, ctrlID)

' Open the file for reading
hFile = CreateFileW(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)

IF hFile = INVALID_HANDLE_VALUE THEN RETURN 0

es.dwCookie = hFile
es.pfnCallback = &MyStreamInCallback

SendMessageW(hwnd, EM_STREAMIN, SF_RTF, &es) ' SF_TEXT
CloseHandle(hFile)

return TRUE
ENDSUB

SUB MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, pointer pcb), DWORD
' Required for StreamIn
if cb = 0 THEN RETURN 1

*<LONG>pcb = 0
ReadFile(dwCookie, pbBuff, cb, pcb, NULL)

RETURN 0
ENDSUB


Andy

Fasecero,

Think this is great!

What I wanted was to enlarge a unicode character for a button, so using what you have done to a static control, placing a border around it, making it slightly grey and finally using my mouse over controls inc file it looks and acts like a button.

Click on "Where words leave off....." it does the same action as the exit button when you click on it.

I can see a lot of uses for this!

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

Ah I see, I did this thinking on a label, but you have turned it into a button. Nice! Very well done. There are still more things that can be added but I will stop here for a few days. I'm thinking about .rtf embedded images, hyperlinks, and custom fonts. There are some awesome fonts available online that I have been able to find.

Andy

October 19, 2017, 12:28:00 am #6 Last Edit: October 19, 2017, 12:32:28 am by Andy
Just thought I would clarify how to use the mouse over controls commands a little for those of you who have not used it before.

Command number 1:

After you have created your control - what ever type it is you need this line -
MouseOverControl(d1,RICH_20) 

The above line stores the co-ordinates (on screen) of a specified control - in this case RICH_20 - which is in a window called "d1".


Command number 2:

You need to start a fast timer-
starttimer d1,50


Command number 3:
In the timer section of the windows handler you need-

TrackWindow(d1) 'This tells the include file that you are actively tracking the window AND all controls specified with command number 1 ( MouseOverControl(d1, MyControl) ).


Finally, command number 4:
Do something when the mouse is over the specified tracked control....

Again in the timer section (after TrackWindow(MyWindow)) simply use this...

IF MouseOver(d1,RICH_20) > 0
   'Do something.....
ENDIF

Example:

Code Select

UnicodeRichCreate(d1, RICH_20, 18, 215, 440, 30, RGB(242,242,242),&MyRichEditProc,SUBCLASS_RE_ID)
UnicodeRichLoad(d1, RICH_20, L"text.rtf")

MouseOverControl(d1,RICH_20)      '<---------- command 1 placed after control creation.


Finally:

Code Select
      case @IDTIMER

                       TrackWindow(d1)   '<--------- Next state that you are tracking the window and specified controls

           'If mouse is left clicked AND mouse is over the static - do something....

-------------> if MOUSEDOWN(1) and MouseOver(d1,RICH_20) > 0 'Mouse is over the static

  'Do something.......
                                        stoptimer d1
OnFinish()
CLOSEWINDOW d1
end

   endif


Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.