|
Hello.
I would like to create an owner-drawn CMenu class, and therefore i override DrawItem and MeasureItem, like this:
<br />
class MyMenu : public CMenu {<br />
public:<br />
virtual void DrawItem(LPDRAWITEMSTRUCT lpDis);<br />
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMis);<br />
};<br />
<br />
void MyMenu::DrawItem(LPDRAWITEMSTRUCT lpDis)<br />
{<br />
}<br />
void MyMenu::MeasureItem(LPMEASUREITEMSTRUCT lpMis)<br />
{<br />
}<br />
And then I add a menu to my app's CMainFrame:
<br />
MyMenu TopMenu;<br />
<br />
TopMenu.LoadMenu(IDR_MAINFRAME);<br />
for(int i = 0; i<3; ++i)<br />
TopMenu.ModifyMenu(ID_DAWS_HEJ+i, MF_OWNERDRAW, ID_DAWS_HEJ+i);<br />
SetMenu(&TopMenu);<br />
But the problem is that DrawItem and MeasureItem are never called! I do receive WM_DRAWITEM and WM_MEASUREITEM, but they are just not handled by my class. What do I do?
|
|
|
|
|
I want to use some shortcuts in my App written in VC++6, but the accelerators do not seem to work by any chance. I made exactly what is written in MSDN, but still no result?
Could you give me some suggestions, or something?
10x alot
|
|
|
|
|
I am having a few issues with va_list. I'm trying to build a class that builds XML statements. Yeah, I know some exist here, but I don't need anything complex and I wanted to try this on my own. I'm running into a problem with variable function length using va_list. Basically I want va_list to be a list of values of any type.
<br />
CString CXMLParser::CreateTag(bool End, CString TagName, COleVariant Value, ...)<br />
so what I have here is something that creates a Tag where the ellipse will represent a list of possible attributes for XML. i.e.
<br />
<XMLTag attrib="hello" attrib2="again">Value</XMLTag><br />
As we know attributes could be anything from dates, to numbers to strings, etc. so I wanted a COleVariant to hold these values. However I don't think it is working properly. I keep getting an exception when I run va_arg. To further give you a clue as to my code here is the .cpp
<code>
#include "stdafx.h"
#include "XMLParser.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CXMLParser::~CXMLParser()
{
}
CString CXMLParser::CreateTag(bool End, CString TagName)
{
return FormatTag(End, TagName, _T(""), _T(""));
}
CString CXMLParser::CreateTag(bool End, CString TagName, COleVariant Value)
{
return FormatTag(End, TagName, Value, _T(""));
}
CString CXMLParser::CreateTag(bool End, CString TagName, COleVariant Value, ...)
{
va_list argList;
CString ArgumentsList = ProcessArgumentList(Value, argList);
return FormatTag(End, TagName, Value, ArgumentsList);
}
CString CXMLParser::FormatTag(bool End, CString TagName, COleVariant Value, CString ArgumentsList)
{
ASSERT(!TagName.IsEmpty());
CString strValue = ConvertValueToString(Value);
CString returnVal = "<"+TagName+" " + ArgumentsList;
if(strValue.IsEmpty() && !End)
returnVal += ">";
else if(strValue.IsEmpty() && End)
returnVal += "/>";
else
returnVal += ">" + strValue + "</"+ TagName +">";
return returnVal;
}
CString CXMLParser::ProcessArgumentList(COleVariant lpList, va_list argList)
{
CString returnVal = _T("");
va_start(argList, lpList);
for(;;)
{
COleVariant pVar = va_arg(argList, VARIANT);
CString AttributeName = ConvertValueToString(pVar);
if(AttributeName.IsEmpty()) break;
pVar = va_arg(argList, VARIANT);
CString AttributeValue = ConvertValueToString(pVar);
returnVal += AttributeName +"=\""+ AttributeValue +"\" ";
}
va_end(argList);
return returnVal;
}
CString CXMLParser::CreateTailTag(CString TagName)
{
return "</" + TagName+">";
}
CString CXMLParser::ConvertValueToString(COleVariant Value)
{
COleVariant vtFld(Value);
CString strValue;
switch(vtFld.vt)
{
case VT_EMPTY:
case VT_NULL: strValue = _T(""); break;
case VT_I2:
case VT_UI1: strValue.Format("%i", vtFld.iVal); break;
case VT_INT: strValue.Format("%i", vtFld.intVal); break;
case VT_I4: strValue.Format("%i", vtFld.lVal); break;
case VT_R4: strValue.Format("%f", vtFld.fltVal); break;
case VT_R8: strValue.Format("%d", vtFld.dblVal); break;
case VT_DECIMAL:
{
double val = vtFld.decVal.Lo32;
val *= (vtFld.decVal.sign == 128)? -1 : 1;
val /= pow(10, vtFld.decVal.scale);
strValue.Format("%d", val);
}
break;
case VT_DATE:
{
COleDateTime dt(vtFld);
CString strDateFormat = _T("%Y-%m-%d %H:%M:%S");
strValue = dt.Format(strDateFormat);
}
break;
case VT_BSTR : strValue = vtFld.bstrVal; break;
case VT_UI4: strValue.Format("%d", vtFld.ulVal); break;
case VT_BOOL: strValue = ((bool)Value) ? "1" : "0"; break;
default: strValue = _T("");
}
return strValue;
}
</code>
And the .h
<code>
#if !defined(AFX_XMLPARSER_H__5B8FC25A_FBDE_4714_A35C_E1018053C660__INCLUDED_)
#define AFX_XMLPARSER_H__5B8FC25A_FBDE_4714_A35C_E1018053C660__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define _ENDLINE "/n"
class CXMLParser
{
public:
CXMLParser(){};
virtual ~CXMLParser();
public:
CString CreateTag(bool End, CString TagName);
CString CreateTag(bool End, CString TagName, COleVariant Value);
CString CreateTag(bool End, CString TagName, COleVariant Value, ...);
CString FormatTag(bool End, CString TagName, COleVariant Value, CString ArgumentsList);
CString ProcessArgumentList(COleVariant lpList, va_list argList);
CString CreateTailTag(CString TagName);
CString ConvertValueToString(COleVariant Value);
};
#endif // !defined(AFX_XMLPARSER_H__5B8FC25A_FBDE_4714_A35C_E1018053C660__INCLUDED_)
</code>
I'm hoping I made sense here. I simply want to have CreateTag take in the fixed first three, plus any possible attributes of any type. Does this seem right or have I missed something. Does va_list work this way? Can it work this way? Is there another way if not?
Thanks!
|
|
|
|
|
|
I have a problem with this code
I want to change the path to the program,
im wondering why i cant make this work
<br />
STARTUPINFO l_StartupInfo = {0}; <br />
PROCESS_INFORMATION l_ProcessInfo = {0}; <br />
<br />
l_StartupInfo.cb = sizeof(l_StartupInfo); <br />
if (CreateProcess(NULL, "AnyFile.exe", NULL, NULL, FALSE, 0, <br />
NULL, NULL, &l_StartupInfo, &l_ProcessInfo)); <br />
}<br />
Thanx for helping
Greets Jeroen
|
|
|
|
|
STARTUPINFO has a size member, you need to init that to sizeof(STARTUPINFO)
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
i am working on a project where i need to have a time delay to slow a while loop down, i tried to use the Sleep function but it seems to do all the sleeping at the very begining of the function instead of little chunks in the while loop, could anyone tell me what i may be doing wrong??
thank you!
|
|
|
|
|
Give use a sampel of your code . . .
i have no idea, what your doing wrong
Sleep (3 * 1000);
|
|
|
|
|
this is a depth first search algorithm, where it takes a grid on a picturebox with a back buffer, and an array of ints(cells) (the grid behind the grid), chooses a random cell and makes a maze out of the grid. a great example and psudocode of the project is on www.mazeworks.com[^]
the stuff in bold is the code in question.
<br />
void Form1::makeit(void)<br />
{ <br />
<br />
int visitedCells = 1;<br />
cell location_x;<br />
cell location_y;<br />
int choices = 0;<br />
int next = 0;<br />
int directions[4];<br />
{<br />
}<br />
cstack* MyStack = new cstack();<br />
<br />
location_x = chooseNum(this->gridH);<br />
location_y = chooseNum(this->gridW);<br />
<br />
while(visitedCells < this->totalCells)<br />
{<br />
choices = 0;<br />
if((location_y-1)>=0)<br />
{<br />
if (((mygrid[location_x,location_y]& 16)==0)&&((mygrid[location_x,location_y-1] & 15)==15))<br />
{<br />
directions[choices++] = 0;
}<br />
}<br />
<br />
if((location_x+1)<=(this->gridW-1))<br />
{<br />
if (((mygrid[location_x,location_y]&32)==0)&&((mygrid[location_x+1,location_y]&15)==15))<br />
{<br />
directions[choices++] = 1;
}<br />
}<br />
<br />
if((location_y+1)<=(this->gridH-1))<br />
{<br />
if (((mygrid[location_x,location_y]&64)==0)&&((mygrid[location_x,location_y+1]&15)==15))<br />
{<br />
directions[choices++] = 2;
}<br />
}<br />
<br />
if( (location_x-1)>=0)<br />
{<br />
if (((mygrid[location_x,location_y]&128)==0)&&((mygrid[location_x-1,location_y]&15)==15))<br />
{<br />
directions[choices++] = 3;
}<br />
}<br />
<br />
if(choices != 0)<br />
{ <br />
next = directions[rand() % choices];<br />
MyStack->push(next);<br />
<br />
switch (next) <br />
{<br />
case 0:<br />
this->mygrid[location_x,location_y] &= ~1; <br />
this->drawline((location_x*this->cellS)+1, location_y*this->cellS, ((location_x+1)*this->cellS)-1, location_y*this->cellS, System::Drawing::Color::White, this->size);<br />
this->mygrid[location_x,--location_y] &= ~4;<br />
break;<br />
<br />
case 1: <br />
this->mygrid[location_x,location_y] &= ~2; <br />
this->drawline((location_x+1)*this->cellS, (location_y*this->cellS)+1, (location_x+1)*this->cellS, ((location_y+1)*this->cellS)-1, System::Drawing::Color::White, this->size);<br />
this->mygrid[++location_x,location_y] &= ~8;<br />
break;<br />
<br />
case 2: <br />
this->mygrid[location_x,location_y] &= ~4; <br />
this->drawline((location_x*this->cellS)+1, (location_y+1)*this->cellS, ((location_x+1)*this->cellS)-1, (location_y+1)*this->cellS, System::Drawing::Color::White, this->size);<br />
this->mygrid[location_x,++location_y] &= ~1;<br />
break;<br />
<br />
case 3: <br />
this->mygrid[location_x,location_y] &= ~8; <br />
this->drawline(location_x*this->cellS, (location_y*this->cellS)+1, location_x*this->cellS, ((location_y+1)*this->cellS)-1, System::Drawing::Color::White, this->size);<br />
this->mygrid[--location_x,location_y] &= ~2; <br />
break;<br />
}<br />
visitedCells++;<br />
if(this->checkBox1->Checked)<br />
{ <br />
this->pictureBox1->Invalidate();<br />
} <br />
}<br />
else<br />
{
next = MyStack->pop(); <br />
switch(next)<br />
{<br />
case 0:<br />
{<br />
location_y++;<br />
break;<br />
}<br />
case 1:<br />
{<br />
location_x--;<br />
break;<br />
}<br />
case 2:<br />
{ <br />
location_y--;<br />
break;<br />
}<br />
case 3:<br />
{<br />
location_x++;<br />
break;<br />
}<br />
}<br />
}
}
}<br />
|
|
|
|
|
Anonymous wrote:
//for(int y = 0; y <1000000; y++){}
//Sleep(1);
this->pictureBox1->Invalidate();
This does nothing 1000000 times, then waits 1ms, then calls your invalidate function.
What are you actually trying to achieve? Why not simply 'Sleep' for the appropriate number of milliseconds?
Paul
|
|
|
|
|
Hi.
I want to use some .Net components from System::Xml and System::Xml::Xsl. But I can't seem to access these from my MFC application. I have set up the compiler options, and other options to allow use of .Net components, but when I write the code I dont manage to access these objects... Can anyone tell me what I have to do in order to do this. Any tutorials / articles on the subject are highly appreciated too
Thanks.
J.
|
|
|
|
|
how do i get around this?
using pow() from math.h:
-1 raised to a fraction power should return undefined (-1.#INF or whatever) when the
denominator is even, yet it should return -1 when the denominator is odd
e.g. -1 ^ 1/3 = -1, while -1 ^ 1/2 = undef
so how can i get it to return -1 instead of undef for all fractional powers?
r -€
|
|
|
|
|
Which are you asking about? How to change the behavior of pow() with an even denominator, or the return value of pow(-1, 0.3333333333) not being what you expect?
For the former, you'll need to write your own wrapper around pow() since you want to change the behavior of pow() .
For the latter, 0.3333333333 is not 1/3 so I don't know how pow() will handle it. The answer to that probably lies in the depths of the floating point number representation, which I don't know enough about to give a good answer.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Actual sign at the laundromat I go to: "No tinting or dying."
|
|
|
|
|
thanks... my problem is that im making a calculator program and when someone types "(-1)^(1/3)" it returns undefined... which is wrong, the answer is 1
i guess i can't get around that issue unless i represent fractions as numerator/denominator instead of the actual ratio value
oh well
thanks for the help though
r -€
|
|
|
|
|
Um, no. (-1)^(1/3) = 0.5+0.866i (as one of many roots. -1 is another root).
"pow" only supports real numbers, not imaginary.
FYI: 1^3 != -1, thus your answer is obviously in error.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
well, the cube root of -1 is -1 (right?) and a number to a fraction power (a/b) is the b'th root of the funtion to the a'th power... am i not correct?
r -€
|
|
|
|
|
Is "the" cube root of -1, -1?
No.
It is one of at least two cube roots. That is part of problem. Probably the real problem is that you can probably only compute a root when 1/x and x is an integer. As someone already pointed out, due to floating point limitations, it is next to impossible to get 1/x and have x an integer.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
>Is "the" cube root of -1, -1?
>No.
>It is one of at least two cube roots.
By that logic, pow(1, 1/3) should return undefined too, since -1/2 + j * sqrt(3)/2 and -1/2 - j * sqrt(3)/2 are also solutions. (It doesn't. It returns 1, as you would expect.)
For what it's worth, the calculator in Windows XP returns "Invalid input for function" when you try to do (-1)^(1/3). I think that's what most calculators that don't handle complex numbers do.
|
|
|
|
|
Read the second half of the message please. I amended my response long before you posted your message where I talk about the problem of detecting the 1/x where x is an integer.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Sorry. I didn't mean to offend you. I guess I should have worded that more carefully.
I was just trying to point out that his question was a little deeper than people were giving it credit for. As you said, the floating point representation of 1/3 is not exact. Yet, pow(1,1/3) correctly returns 1, even though there are two equally valid complex solutions. Why, then, shouldn't pow(-1,1/3) return -1? It is, after all, the only real-valued solution. I guess the ANSI C developers opted for efficiency rather than completeness.
Again, sorry if I offended you. That wasn't my intention.
|
|
|
|
|
Hi there
Tim is absolutely right.
The easiest way to calculate a power is using logarithms, so let say we have this
r = x ^ y
so to calculate r will be something like this
r = e ^ (y * log x)
where e^ and log can be obtained using the Taylor Polynomial
f(x) = f(a) + f'(a) * (x-a)/1! + f"(a) * (x-a)^2/2! + ...+ fN(a) * (x-a)^n/n!
where f', f" ... fN are the first n derivatives of f, and a is a value with which all the funcion can be calculated, for e^ can be 0 for ln, 1.
Anyway, like I was saing the use of logarithm is the reason you are not geting the real root you are looking for, as you can see in your case you would have something like this
r = e ^ ( 1/3 * log -1)
and as we all know log -1 has no solution on the domain of real numbers, the solution is an imaginary number, -PI i, and there is your problem.
So you have some options here, one is to do some analitical preprocessing before the actual calculations, the other one is to redefine pow and/or log to handle complex numbers.
Fabian
|
|
|
|
|
I think it is because of this reason:
a^x = y
ln(a^x) = ln(y)
x.ln(a) = ln(y)
e^(x.ln(a)) = y
ln(a) is undefined for a <= 0
it should work for a,x,y are of type complex. I have done such a thing many years ago. It works also for -1 ^ 1/2 (which is the complex number "i" or "j") written as y.re=0 and y.im=1 .
I am not sure if pow can be called as "complex y = pow( complex a, complex x )", if not, you need to overload it in some way. That's a challenge!!
Wish it helps some.
Michel
|
|
|
|
|
thanks, i get what you're saying
i think maybe i will implement sets and complex numbers into my calculator program to get around this..
i've never heard of the "complex" class, though.. is it STL?
so far i'm only using STL classes and would like to keep it to a bare minimum of external libraries
r -€
|
|
|
|
|
Hi,
Yes Complex is a class of STL, but it won't help you either, try this
complex<double> x, y, r;
x.real(-1.0);
x.imag(0.0);<br> <br>
y.real(1.0/3.0);
y.imag(0.0);<br> <br>
r = pow(x, y);<br>
r = exp(y * log(x));
So as I said, you will have to do some preprocessing or redefine pow yourself
Fabian
|
|
|
|
|
thanks for the info... ill leave the fix for a later date
r -€
|
|
|
|
|