|
Indeed. I was actually thinking more along the lines of what sort of mainframe? e.g US Military, CRAY, and a couple of other whose name escapes me just now. I played with DEC Alphas a million years ago, MIPS before the orig PlayStation implemented it, Had a couple of old SuperSparc's sitting in cases in the CS building in uni. Perhaps I was simply too inarticulate. No matter. Sorry for my intrusiveness.
Yeah, one would certainly think that your code would colour the line red - though I've been spectacularly unsuccessful at changing the text colour using MFC. I can make the line bold, underlined or whatever - but I can't color the text. The same task I have easily achieved in native code in the past and cant see any special colour handling functions that seem relevant. I'm more than a little perplexed just now. Here's the (hacked together)code I have for Bolding the target line.
Also, for some reason I had to remove the other flags you'd used in FindText. It wouldn't return a valid hit for the text "_ " unless I did so, too tired to read help docs just at the moment, no doubt such limitations are mentioned in there somewhere.
Of course, if you change the "or equals" to "xor equals" you can toggle the state, rather than just setting it.
Oops! I mean, if you xor the dwEffects with CF_BOLD, instead of setting it - you'll toggle the state of the char formatting.
Also, you should be using SetSelectionCharFormat, SetDefaultCharFormat acts on the whole control, not just the selection.
void CmfcRichEditDlg::OnBnClickedButton3()
{
FINDTEXTEX ft;
CHARFORMAT cfm;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = "_ ";
long n = m_RichEdit.FindText(FR_DOWN, &ft);
long l = m_RichEdit.LineLength(n);
m_RichEdit.SetSel(n,l);
m_RichEdit.GetSelectionCharFormat(cfm);
cfm.dwMask |= CFM_BOLD;
cfm.dwEffects = CFE_BOLD;
m_RichEdit.SetSelectionCharFormat(cfm);
}
modified 6-May-12 16:32pm.
|
|
|
|
|
Thought I'd add another reply so that you get a notification.
Just solved the question of why no colouring?
I tried it as a release-mode app and voila! Tried again as a debug, Nada!
Anyways, here's a function that will flip the line back and forth between
std-weight black text & bold red text.
void CmfcRichEditDlg::OnBnClickedButton3()
{
FINDTEXTEX ft;
CHARFORMAT cfm;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = "_ ";
long n = m_RichEdit.FindText(FR_DOWN, &ft);
long l = m_RichEdit.LineLength(n);
m_RichEdit.SetSel(n,l);
m_RichEdit.GetSelectionCharFormat(cfm);
cfm.cbSize = sizeof(cfm);
cfm.dwMask = CFM_BOLD;
cfm.dwEffects ^= CFE_BOLD;
m_RichEdit.SetSelectionCharFormat(cfm);
cfm.cbSize = sizeof(cfm);
if (cfm.crTextColor == RGB(0,0,0))
cfm.crTextColor = RGB(200,0,0);
else
cfm.crTextColor = RGB(0,0,0);
cfm.dwMask = CFM_COLOR;
cfm.dwEffects = NULL;
m_RichEdit.SetSelectionCharFormat(cfm);
}
|
|
|
|
|
thnaks
tried one minor modification
after
long l = m_RichEdit.LineLength(n);
l = l + n;
|
|
|
|
|
Hi,
I have a text file that at certain lines I insert a "_" as the first character
Here is a example
_ 000000 90EC D00C 0000C 34 STM R14,R12,12(R13)
This works fine ..
I would like to highlight the first such line in Bold Red to do this i use the FindText function however for some reason this return a -1
CHARFORMAT cfm;
SetSel(0,-1);
cfm.cbSize = sizeof(CHARFORMAT);
cfm.dwMask = CFM_FACE | CFM_SIZE | CFM_BOLD |
CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED;
cfm.dwEffects = 0;
cfm.yHeight = 240;
::lstrcpy(cfm.szFaceName, "Times New Roman");
SetDefaultCharFormat(cfm);
// LOOK for the first executable instruction
SetSel(0,0); // start at the beginig
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText = (LPSTR) "_ ";
long n = FindText(FR_MATCHCASE|FR_WHOLEWORD, &ft);
long l = LineLength(n);
SetSel(n,l);
cfm.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
SetDefaultCharFormat(cfm);
SetSel(0,0);
|
|
|
|
|
It's a very simple fix. I must have spent 1/2 an hour looking over it until it hit me - you're missing a flag from the call to FindText.
long n = FindText(FR_MATCHCASE|FR_WHOLEWORD, &ft);
long n = FindText(FR_DOWN | FR_MATCHCASE|FR_WHOLEWORD, &ft);
|
|
|
|
|
Thanks worked howeever the return code from FindText was a big number X'00000830'
This is what I observed in the AX register which is always the return code from a API
I thought the return code would be the zero based character which is alot smaller
if you have any clues Please Let me know
I am going to Start another thread reagarding this question as may be I am
misunderstanding the concept
thanks
|
|
|
|
|
That's okay.
It's a bit hard to tell without seeing the data that you've got in the control. From your number X'00000830', I don't know if you mean 830 or 0x830.
In either case, it's indicating that the (0x?)830th character is the start of the sequence you're searching for.
Assuming (say) 20 chars per line & 830 decimal, this would correspond to the 10th char of the 42nd line in the control.
|
|
|
|
|
Hello,
I am working on a math program for my daughter in C# using a Form. Here is the gist of my program:
1) Create random numbers.
2) Add numbers together. Compare to user input.
3) Tell user if question was answered correctly.
I can get the program to cycle through once successfully. I can't figure out how to loop through a series of 50 questions though. When I've tried to loop it, I either end up on question 50 or suffer through an infinite loop.
If anyone could point me in the right direction, I would greatly appreciate it. Also, this is the first time I've posted in a programming forum so I've left out any pertinent info please let me know!!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Math
{
public partial class NewMathForm : Form
{
public NewMathForm()
{
InitializeComponent();
int questionCounter = 1;
addition();
}
private void sumTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
sumTextBox.SelectionStart = 0;
}
public void shuffle(ref int[] array)
{
Random rng = new Random();
int count = array.Length;
while (count > 1)
{
int k = rng.Next(count);
count--;
int temp = array[count];
array[count] = array[k];
array[k] = temp;
}
}
private void parseNumbers(ref int[] array)
{
double addend1 = 0;
double addend2 = 0;
string number;
char num1;
char num2;
for (int count = 0; count < 50; count++)
{
number = array[count].ToString();
num1 = number[0];
int length = number.Length;
if (length < 2)
{
char zero = '0';
num2 = zero;
}
else
num2 = number[1];
addend1 = System.Char.GetNumericValue(num1);
addend2 = System.Char.GetNumericValue(num2);
array[count] = Convert.ToInt32(addend1);
count++;
array[count] = Convert.ToInt32(addend2);
}
}
private void addition()
{
int[] numbers = new int[100];
int counter = 0;
int questionCounter = 1;
int numberOfQuestions = 50;
for (counter = 0; counter < 100; counter++)
{
numbers[counter] = counter;
}
shuffle(ref numbers);
parseNumbers(ref numbers);
addendOneLabel.Text = numbers[questionCounter].ToString();
addendTwoLabel.Text = numbers[questionCounter + 1].ToString();
}
private void checkAnswerButton_Click(object sender, EventArgs e)
{
checkAnswer();
}
public void checkAnswer()
{
int sum = Convert.ToInt32(sumTextBox.Text);
int number1 = Convert.ToInt32(addendOneLabel.Text);
int number2 = Convert.ToInt32(addendTwoLabel.Text);
int answer = number1 + number2;
if (answer == sum)
correctAnswer();
else
incorrectAnswer(answer);
}
private void correctAnswer ()
{
MessageBox.Show ("That is correct!");
}
private void incorrectAnswer (int sum)
{
MessageBox.Show ("That is incorrect! The correct answer is " + sum + ".");
}
}
}
|
|
|
|
|
First of all, you got the wrong forum, this message board is for C++/MFC related topics, you should have asked this on the C# dedicated message board.
Secondly, i am not sure i understand your problem, but as much as i can gather, you have a "check answer" button, so, why don't you define a counter of type e.g. int in the class and increase it every time the button is pressed, each time generating a new "problem" to solve, once it reaches 50, you're (or your doughter for that matter) is done. Am i misunderstanding you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Sorry, I saw the title C/C++/MFC and assumed it was also for C programming. You are correct in what I am trying to accomplish. The 'checkAnswer' button should tell the user if she is right or wrong, and then cycle to the next question. The problem I am having is figuring out where (and how) to implement the loop. It's not in the code provided, as I was testing before posting, but I previously had it in the addition() function. What I can't see how to do is how do I implement a return value to increase the counter when the 'checkAnswer' button is pressed?
If I increment the loop in the addition() function, then I end up on question 50 and only 1 question gets asked. I've thought, well just provide a bool flag in the 'checkAnswer' button event handler, and only increment the loop counter if that flag is true. But I can't figure out how to return that value. Or am I going about this the wrong way?
|
|
|
|
|
Not really able to acertain your level of programming experience, though it does sound like perhaps you're coming from a background in DOS or console app programming - not the event driven model that's used in windows.
I say that in reference to your mention of loops.
For this kind of a question, a loop in the classic sense is not appropriate. Think of your code as a state-machine. Every time something happens on the form, windows calls the appropriate function in your code and you handle it. Rather than looping, you should increment a counter that indicates the current question. If you then use this counter in all of your functions that display num1 & num2, or check for the correct answer you're done.
Here's something I just had a play with. It should be enough to demonstrate the ideas you need.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace mathProj
{
public partial class Form1 : Form
{
private const int maxQuestions = 50;
private int curQuestion;
private int[] num1 = new int[maxQuestions];
private int[] num2 = new int[maxQuestions];
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
bool isCorrect;
textBox1.Text = curQuestion.ToString();
if (curQuestion < maxQuestions-1)
curQuestion++;
else
{
initNumbers();
curQuestion = 0;
}
setNumberLabels();
}
private void Form1_Load(object sender, EventArgs e)
{
initNumbers();
setNumberLabels();
}
private void setNumberLabels()
{
lblNum1.Text = num1[curQuestion].ToString();
lblNum2.Text = num2[curQuestion].ToString();
}
private void initNumbers()
{
curQuestion = 0;
int i;
for (i = 0; i < maxQuestions; i++)
{
num1[i] = i*2;
num2[i] = i*3;
}
}
}
}
|
|
|
|
|
Hi and thanks for the help. My level of programming experience goes as far as C++ console programming classes in high school and college (for a whopping total of 2). C# seems more intuitive to me, and I have picked up several books to help me learn. I have written several basic programs for my own use, I just got stumped here. I guess looking at it for hours on end caused me to take too many wrong turns.
Of course you are right, enhzflep. I should have concentrated more on what would happen when I pressed the button instead of how to feedback that input to the main program. After integrating your code with mine, and after I finish making a few last tweaks to suit my needs, it will work great!
Thank you again.
For anyone else:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Math
{
public partial class SimpleAdditionMathForm : Form
{
private const int maxQuestions = 50;
private int currentQuestion;
private int arrayCounter;
int[] numbers = new int[100];
int timerRecord;
public SimpleAdditionMathForm()
{
InitializeComponent();
questionTimer.Start ();
initNumbers();
setNumberLabels();
}
private void initNumbers()
{
timerRecord = 31;
currentQuestion = 1;
for (int counter = 0; counter < 100; counter++)
{
numbers[counter] = counter;
}
shuffle(numbers);
parseNumbers(numbers);
}
private void setNumberLabels()
{
addendOneLabel.Text = numbers[arrayCounter].ToString();
addendTwoLabel.Text = numbers[arrayCounter + 1].ToString();
questionTimer.Start();
}
public void shuffle(int[] array)
{
Random rng = new Random();
int count = array.Length;
while (count > 1)
{
int k = rng.Next(count);
count--;
int temp = array[count];
array[count] = array[k];
array[k] = temp;
}
}
private void parseNumbers(int[] array)
{
double addend1 = 0;
double addend2 = 0;
string number;
char num1;
char num2;
for (int count = 0; count < 100; count++)
{
number = array[count].ToString();
num1 = number[0];
int length = number.Length;
if (length < 2)
{
char zero = '0';
num2 = zero;
}
else
num2 = number[1];
addend1 = System.Char.GetNumericValue(num1);
addend2 = System.Char.GetNumericValue(num2);
array[count] = Convert.ToInt32(addend1);
count++;
array[count] = Convert.ToInt32(addend2);
}
}
private void checkAnswerButton_Click(object sender, EventArgs e)
{
questionTimer.Stop();
timerRecord = 31;
if (currentQuestion < maxQuestions - 1)
{
int sum;
if (sumTextBox.Text != "")
{
sum = Convert.ToInt32(sumTextBox.Text);
}
else
sum = 0;
int number1 = Convert.ToInt32(addendOneLabel.Text);
int number2 = Convert.ToInt32(addendTwoLabel.Text);
int answer = number1 + number2;
if (answer == sum)
correctAnswer();
else
incorrectAnswer(answer);
sumTextBox.Text = "";
currentQuestion++;
arrayCounter = arrayCounter + 2;
questionCounterLabel.Text = currentQuestion.ToString();
sumTextBox.Focus();
}
else
{
MessageBox.Show("You have completed all 50 questions!");
this.Close();
}
setNumberLabels();
}
private void correctAnswer ()
{
MessageBox.Show ("That is correct!");
}
private void incorrectAnswer (int sum)
{
MessageBox.Show ("That is incorrect! The correct answer is " + sum + ".");
}
private void questionTimer_Tick(object sender, EventArgs e)
{
timerRecord--;
tickLabel.Text = timerRecord.ToString();
}
private void sumTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
}
}
}
|
|
|
|
|
That's a real pleasure abollmeyer. To be honest, you had me with:
abollmeyer wrote: Hello,
I am working on a math program for my daughter in C#
It was absolutely impossible to avoid trying help.
Simon.
|
|
|
|
|
Hey! Just wanted to say i'm sorry for not reacting on your post for a while, i had problems accessing the site (something with a DNS server), but i see in the mean time you got help, so...congratulations on solving the problem.
Best regards
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Oh, and welcome to Code Project.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
My application is running fine in 32 bits. But in 64 bit my Graphics is not coming. It's a blank window appearing.
I have removed WIN32 definitions in the stdafx.h file please check it...
[code]
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN64_WINNT 0x0500 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#include <afxstr.h >
#include <atlimage.h>
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
[/code]
I have modifed this for 64 bit
[code]
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN64_WINNT 0x0500 // Change this to the appropriate value to target other versions of Windows.
#endif
[/code]
what should be done for this
[code]
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600 // Change this to the appropriate value to target other versions of IE.
#endif
Please help....Thanks Sujan
[/code]
|
|
|
|
|
You shouldn't have to do this to be able to run an application in 64bit. How are you attempting to run your application in the 64bit machine? From your development environment or did you just move the executable over?
|
|
|
|
|
There is no difference in the versions between 32-bit and 64-bit flavors of an OS.
Try running the 32-bit application on the 64-bit OS and check if you see the UI properly.
If this is working, then the problem is elsewhere in the code.
Think about what other changes you have made to port the code to 64-bit.
|
|
|
|
|
I have a array of
std::pair<string, string> , i.e.
X → Y
A → B
C → D
B → C
T → X
Y → T
We can see that A → B → C →D (D is the final target) and X → Y → T → X (X is the final target) in the arry, what I want to do is change the arry to this:
X → X (X is the final target in circuit)
A → D (D is the final target)
C → D (D is the final target)
B → D (D is the final target)
T → X (X is the final target in circuit)
Y → X (X is the final target in circuit)
I'm confused about how to implement this algorithm.
Any help would be greatly appreciated!
|
|
|
|
|
how is the first array of pair created ? manually ?
What is the relationship between the first array and what you want to achieve? is there a logical progression between the two?
Ok, I've seen what you have.
will think about it
Watched code never compiles.
modified 4-May-12 9:36am.
|
|
|
|
|
It could be something as shown below -
bool GetSecond(const string& first, string& second)
{
for (int i = 0; i < ARR_SIZE; ++i)
{
if (first == arr[i].first)
{
second = arr[i].second;
return true;
}
}
return false;
}
void GetDest(const string& src, string& dest)
{
string src2 = src;
while (GetSecond(src2, dest))
{
if (src == dest)
break;
src2 = dest;
}
}
For each element in the pair call GetDest with first as the first parameter and second as the second parameter.
You may need to add other conditions to satisfy your algorithm.
|
|
|
|
|
Thank you for your reply.
Your algorithm is great!
I made some modifications, so that it's perfect now!
typedef vector<pair<char, char> > _OWN_TYPE;
_OWN_TYPE vecKey2Name;
bool GetSecond(const char& first, char& second)
{
for (int i = 0; i < vecKey2Name.size(); ++i)
{
if(vecKey2Name[i].first == vecKey2Name[i].second)
continue;
if (first == (vecKey2Name[i].first))
{
second = vecKey2Name[i].second;
return true;
}
}
return false;
}
void GetDest(const char& src, char& dest)
{
char src2 = src;
while (GetSecond(src2, dest))
{
if (src == (dest))
break;
src2 = dest;
}
}
int main()
{
vecKey2Name.push_back(make_pair('X', 'Y'));
vecKey2Name.push_back(make_pair('A', 'B'));
vecKey2Name.push_back(make_pair('C', 'D'));
vecKey2Name.push_back(make_pair('B', 'C'));
vecKey2Name.push_back(make_pair('T', 'X'));
vecKey2Name.push_back(make_pair('Y', 'T'));
for(_OWN_TYPE::iterator itr = vecKey2Name.begin(); itr != vecKey2Name.end(); ++itr)
cout << (itr->first) << " --> " << (itr->second) << endl;
for(_OWN_TYPE::iterator itr = vecKey2Name.begin(); itr != vecKey2Name.end(); ++itr)
GetDest(itr->first, itr->second);
cout << "=============================================================" << endl;
for(_OWN_TYPE::iterator itr = vecKey2Name.begin(); itr != vecKey2Name.end(); ++itr)
cout << itr->first << " --> " << itr->second << endl;
}
modified 6-May-12 6:25am.
|
|
|
|
|
Why not have a simple look-up table? Specially if the number of cases is this small...
|
|
|
|
|
Can you explain a little deeper?
The size of the arry is under 5000 in most case.
|
|
|
|
|
In my opinion
Falconapollo wrote: T → X (X is the final target in circuit)
Y → X (X is the final target in circuit)
Should be instead
T → Y
Y → Y
Am I missing something?
Veni, vidi, vici.
|
|
|
|
|