Click here to Skip to main content
15,887,683 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWindows Forms UI Pin
pix_programmer9-Feb-11 22:39
pix_programmer9-Feb-11 22:39 
AnswerRe: Windows Forms UI Pin
Schehaider_Aymen9-Feb-11 23:39
Schehaider_Aymen9-Feb-11 23:39 
Questionhow to select the text of windows client area Pin
sarfaraznawaz9-Feb-11 22:08
sarfaraznawaz9-Feb-11 22:08 
AnswerRe: how to select the text of windows client area Pin
Niklas L10-Feb-11 22:31
Niklas L10-Feb-11 22:31 
GeneralRe: how to select the text of windows client area Pin
sarfaraznawaz11-Feb-11 0:39
sarfaraznawaz11-Feb-11 0:39 
GeneralRe: how to select the text of windows client area Pin
Niklas L11-Feb-11 0:59
Niklas L11-Feb-11 0:59 
GeneralRe: how to select the text of windows client area Pin
sarfaraznawaz15-Feb-11 19:43
sarfaraznawaz15-Feb-11 19:43 
GeneralRe: how to select the text of windows client area Pin
Niklas L16-Feb-11 2:00
Niklas L16-Feb-11 2:00 
You should move your painting code to OnPaint if you use a CDialog, or to OnDraw if you use a doc/view architecture.
Keep a selection range as a member variable, as well as the text printed.

Maybe something like this in your header file
C++
struct SelectionRange
{
	SelectionRange(int f, int e) : first(f), end(e) {}
	int first;
	int end;
	bool empty() const { return first < 0 || end < first; }
	size_t size() const { return end - first; }
};
SelectionRange range;
const TCHAR* text;
In constructor:
C++
range(2, 4);
text = _T("Hello world!");
In OnPaint() or OnDraw():
C++
int oldBM = dc.SetBkMode(TRANSPARENT);
if (range.empty())
{
	dc.TextOut(30, 30, text); // Paint all as unselected
}
else
{
	dc.MoveTo(30, 30);
	UINT ta = dc.GetTextAlign();
	UINT oldTA = dc.SetTextAlign(ta | TA_UPDATECP);
	dc.TextOut(0, 0, text, range.first);
	dc.SetBkMode(oldBM);
	COLORREF oldTC = dc.SetTextColor(RGB(255, 255, 255));
	COLORREF oldBC = dc.SetBkColor(RGB(0, 0, 255));
	dc.TextOut(0, 0, &text[range.first], range.size());
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(oldTC);
	dc.SetBkColor(oldBC);
	dc.TextOutA(0, 0, &text[range.end]);
	dc.SetTextAlign(oldTA);
}
dc.SetBkColor(oldBM);

This will draw the text with characters text[range.first] to text[range.last-1] as selected.
You will have to calculate the range variable in your WM_LBUTTONDOWN / WM_MOUSEMOVE handlers, and add some logic to support negative ranges (last < first), or just turn them into positive ranges if that is sufficient your needs.

GeneralRe: how to select the text of windows client area Pin
sarfaraznawaz21-Feb-11 18:39
sarfaraznawaz21-Feb-11 18:39 
GeneralRe: how to select the text of windows client area Pin
Niklas L21-Feb-11 20:22
Niklas L21-Feb-11 20:22 
GeneralRe: how to select the text of windows client area Pin
sarfaraznawaz21-Feb-11 22:31
sarfaraznawaz21-Feb-11 22:31 
GeneralRe: how to select the text of windows client area Pin
Niklas L21-Feb-11 22:55
Niklas L21-Feb-11 22:55 
GeneralRe: how to select the text of windows client area Pin
sarfaraznawaz27-Feb-11 18:24
sarfaraznawaz27-Feb-11 18:24 
GeneralRe: how to select the text of windows client area Pin
Niklas L27-Feb-11 23:07
Niklas L27-Feb-11 23:07 
GeneralRe: how to select the text of windows client area Pin
sarfaraznawaz4-Mar-11 1:55
sarfaraznawaz4-Mar-11 1:55 
GeneralRe: how to select the text of windows client area Pin
Niklas L4-Mar-11 9:52
Niklas L4-Mar-11 9:52 
QuestionHow to use PostMessage function to Close the Recorder of MS-Window-XP Pin
cerne1840@yahoo.com9-Feb-11 17:05
cerne1840@yahoo.com9-Feb-11 17:05 
AnswerRe: How to use PostMessage function to Close the Recorder of MS-Window-XP Pin
Cool_Dev9-Feb-11 19:06
Cool_Dev9-Feb-11 19:06 
AnswerRe: How to use PostMessage function to Close the Recorder of MS-Window-XP Pin
User 74293389-Feb-11 19:56
professionalUser 74293389-Feb-11 19:56 
AnswerRe: How to use PostMessage function to Close the Recorder of MS-Window-XP Pin
Cool_Dev9-Feb-11 20:11
Cool_Dev9-Feb-11 20:11 
QuestionHeight of combo-box Pin
includeh109-Feb-11 7:07
includeh109-Feb-11 7:07 
AnswerRe: Height of combo-box Pin
User 74293389-Feb-11 7:21
professionalUser 74293389-Feb-11 7:21 
GeneralRe: Height of combo-box Pin
includeh109-Feb-11 22:10
includeh109-Feb-11 22:10 
GeneralRe: Height of combo-box Pin
sarfaraznawaz10-Feb-11 1:35
sarfaraznawaz10-Feb-11 1:35 
AnswerRe: Height of combo-box [modified] Pin
User 742933810-Feb-11 5:14
professionalUser 742933810-Feb-11 5:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.