Find function not working - visual-c++

I am implementing a simple MFC text editor and I have run into trouble with my find function. Specfically in my 'find box' dialog class I have the following code:
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = _T("wallaby");
long n = pmyRichEditCtrl->FindText(FR_MATCHCASE|FR_WHOLEWORD, &ft);
if (n != -1)
pmyRichEditCtrl->SetSel(ft.chrgText);
However, n is always -1 even when the word wallaby is typed into the control. Any help would be greatly appreciated.

It all depends where your current cursor selection is. If you typed the word then most likely your cursor will be positioned directly after the typed word. If you do not care about the position of the cursor then you can set the position to the beginning and start finding the text from the beginning:
pmyRichEditCtrl->SetSel( 0, 0 );
long n = pmyRichEditCtrl->FindText(FR_DOWN|FR_MATCHCASE|FR_WHOLEWORD, &ft);
Also, do not forget to set FR_DOWN parameter to search forward. If this parameter is not set it will search backward from FINDTEXTEX.chrg.cpMin:
Microsoft Rich Edit 2.0 and later: If set, the search is forward from
FINDTEXTEX.chrg.cpMin; if not set, the search is backward from
FINDTEXTEX.chrg.cpMin.
Microsoft Rich Edit 1.0: The FR_DOWN flag is ignored. The search is
always forward.

Related

In PyQt QTreeView item, how to set color for specific column blocks

With PyQt4 based QTreeView, I've created 2 xml tree widgets. From both the trees, want to compare selected items and highlight the difference. For e.g.,
Left String : "CompareString"
Right String : "ComPareStringRight"
The observations of the diff :
Left[0:2] is same as Right[0:2]
Left[3:3] differs with Right[3:3]
Left[4-12] is same as Right[4-12]
Right[13-17] is not present in Left
Now, want to set colors according to :
matching characters - default
Differing characters - Orange
Added characters - Green
Deleted characters - Red
How can I implement this? Unable to find any reference implementation to pick up from. Pls suggest a way forward.
class QCustomDelegate (QItemDelegate):
global showDiffPaint
def paint (self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex):
column = indexQModelIndex.column()
if showDiffPaint == 1:
QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
else:
QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
After digging, found it useful to convert text into html, and present as below.
However, found bugs due to " and < and > characters display. which I think I need to escape somehow...
options = QStyleOptionViewItemV4(option)
doc = QTextDocument()
doc.setHtml(txt1)
doc.setTextWidth(option.rect.width())
style = QApplication.style()
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
textRect = style.subElementRect(QStyle.SE_ItemViewItemText,
options)
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)

How do I make an Excel ActiveX label to be transparent ... at runtime?

I want to put a transparent label on top of a sheet in Excel, so that I can take advantage of the MouseMove event of the label to "draw cells" (aka change their fill color and so on) by mouse click / drag / etc. - since I can't do that on the cells per se.
Now everything works just fine, except that I can't make the label transparent at runtime (aka in VBA) ... while by doing exactly the same thing in Design Mode works as expected. Specifically, I have the code (more or less):
Dim MapLabel As OLEObject
On Error Resume Next
Sheet2.OLEObjects("MapLabel").Delete
Set MapLabel = Sheet2.OLEObjects.Add("Forms.Label.1")
MapLabel.name = "MapLabel"
MapLabel.Placement = xlMoveAndSize
MapLabel.Object.Caption = ""
' Problem line below
MapLabel.Object.BackStyle = fmBackStyleTransparent
' Problem line above
MapLabel.Left = Sheet2.cells(2, 6).Left
MapLabel.Top = Sheet2.cells(2, 6).Top
MapLabel.Width = Sheet2.cells(2,6).Width * 10
MapLabel.Height = Sheet2.cells(2,6).Height * 10
So, in words, I first delete the label named 'MapLabel', then recreate it (the above code goes into a "init" Sub). All the code lines except the one marked produce the desired result. The marked one does set the BackStyle property of the label to fmBackStyleTransparent ... but it doesn't actually make the label transparent. This is frustrating, because it's the same approach that works flawlessly at design time!
Do you have a solution to this? I read about solving similar problems by declaring the label as MsForms.Label or as Control, but the sheet object doesn't have those properties, plus, there are far more label properties which can be set using the OLEObject than with the help of MsForms.Label or Control.
All you need to do after this line:
MapLabel.Object.BackStyle = fmBackStyleTransparent
put this line:
ActiveSheet.Shapes(MapLabel.Name).Fill.Transparency = 1
I hope I helped.
P.S. If you need explanation i will edit my answer.
I had the same problem as you but in Word. The solution for me was to do the following:
In design mode:
Right click on the object
Navigate to Switch to automatic form/Image > Wrapping > In front of the text
Add an empty picture to your label

How to change / assign BGCOLOR to a field/cell/row/column in a freeform query

I am using a freeform query that will populate the temp table fields. i can adjust the width fine but i cant assign a color to the field/cell/row/column. How do you assign color ?
You need a "row display trigger" to go with your browse widget. Something like:
on row-display of f anywhere do:
if "{&window-system}" = "tty" then
columnHandle:dcolor = getColorNum( "red" ).
else
columnHandle:fgcolor = getColorNum( "red" ).
return.
end.
Something like this might be handy for getting the columnHandle:
function getBrowseColumnByName returns handle ( z as handle, n as character ):
define variable c as handle no-undo.
c = z:first-column.
do while valid-handle( c ):
if c:name = n then
leave.
else
c = c:next-column.
end.
return c.
end.
Thanks for the answer. I also did a workaround and ask a coworker and found a different answer.
under DISPLAY trigger of freeform query.
tt-table COLUMN-FGCOLOR 15 COLUMN-BGCOLOR 3.

Delete a character from string realbasic

I have a virtual keyboard created in RealBasic.
When I press letters, numbers I append it to a textfield all its ok but, how do I delete characters from that textfield from current cursor position when I press "Delete" button from virtual keyboard?
To append letters or numbers to the textfields I use:
TextField1.Text = TextField1.text + me.Caption //to append caption
TextField1.SelStart = Len(TextField1.text) // to move cursor at the end of string
Paul's solution works if you only plan to delete the last typed character.
But beware: If you let the user also move the cursor left and right, you have to delete the text at the position of the cursor, of course. And if you also allow the user to select text, then it's even more complicated.
I suggest that your virtual keyboard simply send the typed key to the system as if the user had pressed the key. That way, the TextEdit field will do everything for you.
To make this work, however, you need custom solutions for each OS platform you want to support.
Let me know which platforms you plan to support and I'll see what I can find. I have some code for OSX but not for Windows, yet.
Doing what Thomas said means:
dim n as String = TextField1.Text
n = newText.left(TextField1.selStart) + n.right(n.len - textField1.selStart - 1)
textField1.text = n
Just lop off the last character:
TextField1.Text = TextField1.Text.Left(TextField1.Len-1)

how to get cursor position using GetSelection in text service framework windows8 application?

HRESULT hr;
TF_SELECTION tfSelection;
ULONG uFetched;
//Obtain the default selection.
hr = _pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &uFetched);
UINT ar=(UINT)uFetched;
if(SUCCEEDED(hr) && (uFetched > 0))
{
UINT ar=(UINT)uFetched;
//Work with the selection.
//Release the selection range object.
tfSelection.range->Release();
}
Hi all. I am implementing this code in the DoEditSession method. When I try to get the selection, I always get a value of 1 for uFetched. But the cursor position is not coming?
I am developing a text service for windows RT using Tsf interface. I
have integrated libraries that suggests words based on letters we type
in the candidate window. Now I need to get the letters before and
after the Cursor Position in the Document. So here I have
used GetSelection to retrieve the selected text. The problem is I am
not able to retrieve the caret position in the document (notepad). Is there any specific way in which i can get the letter/text around the caret/cursor position?
You can shift the start/end of the selection range without actually modifying the selection.

Resources