|
Thanks alot Joaquin that was that one single error that I had referred to earlier that I had not fixed. I appreciate you bringing that to my attention. I guess right now what I am trying to do is actually get my data into the 2 different stacks. I understand how to do post fix and evaluate but as of right now I am wanting to just get it to recognize what kind of data it is that is being sent in whether it is an operand or numerical data and convert it to what is needed to evaluate it.
|
|
|
|
|
I apologize if I did not say this earlier but if you run this you must put a space in between each number and operand for the getline to pick it up and also one at the end.
|
|
|
|
|
So, after fixing this problem are you still stuck somewhere else? Are you experiencing any problematic behavior?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
I am just kind of stumped as where to go next. I am just wondering do I need to read into a string or what kind of data I should read into but once I cna figure that out then I should be able to figure it out from there. I was also wondering would there be a better way than using a switch for my precedence. I am very sorry for my ignorance and I hope to get in depth into this sucker tonight. I have one week to complete it.
|
|
|
|
|
Well, I cannot solve your homework, so I hope some advice can put you on the right track.
First of all, this kind of problem is usually solved with one stack, not two. By inserting the numbers into one stack and the operands into another, you're losing crucial information about the orifinal postfix expression. For instance, consider the two expressions:
1 2 + 3 * [3 * (1 + 2) = 9]
1 2 3 + * [(3 + 2) * 1 = 5] According to your schema, these two expressions would be stored just the same:
number stack: 3 2 1
operation stack: * + so you're clearly doing it the wrong way. Ok so far? What you have to do is store everything into one single stack. As the stack can have to types of elements (numbers and operations), create a <ode>struct capable of storing both things, like for instance:
struct stack_element
{
bool is_operation;
} Now you have your stack with the given postfix expression conveniently stored in reverse order. You have to devise an algorithm to evaluate the contents of the stack. You can rely on the following two reduction policies:- If the top element of the stack is a number, this is what the stack evaluates to.
- If the top element is an operation then:
- Extract it from the stack.
- Recursively evaluate the first operand, yielding a number and leaving the expression for the second operand in the stack.
- Evaluate the second operand the same way.
- You have your operation and your two operands, calculate this and you're done.
I hope this is of some help. If you make some progress in your program and get stucked again, repost here trying to be specific about the particular problem you've run into.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
I really appreciate all of the help guys and the speedy responses. That is just amazing at how fast all of these responses have been accumulated. I am now on the right track and hopefully I can devulge myself into it in depth tonight and if I have any more problems I will be sure and let you know . Thanks
James
|
|
|
|
|
I would like to start an MFC application that would look at the arguments (like main(argv, argc) and launch an option for me. Any help would be appreciate it. Thanks
|
|
|
|
|
If you look at the InitInstance function in your app class you should see something similar to:
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
Command line processing is handled here. What you want to do is create a new class derived CCommandLineInfo and replace the declaration of cmdInfo with your new class instead.
Override the ParseParam function in your CCommandLineInfo class and set whatever variables you need based on the input.
void CYourCmdLineInfo::ParseParam(const TCHAR* pszParam,BOOL bFlag,BOOL bLast)
{
if( bFlag )
{
if( lstrcmpi(pszParam, _T("MyFlag")) == 0 )
{
bMyFlag = true;
}
else if( lstrcmpi(pszParam, _T("MyOtherFlag") == 0 )
{
bMyOtherFlag = true;
}
}
CCommandLineInfo::ParseParam(pszParam, bFlag, bLast);
}
|
|
|
|
|
I used Paul DiLascia's class for this:
http://www.microsoft.com/msj/1099/c/c1099.aspx
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
The CRT sets up the __argc and __argv variables for you, which have the same contents as argc /argv in a console mode app.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
My process use COMCTL32.dll and COMCTL32.DLL use USER32.DLL, I want to hook APIs in USER32.DLL, how can I do this?? Demo source code is welcome.
|
|
|
|
|
Hi All
i have a modeless dialog which i use as a wait screen.
this appears ontop of a dialog that is called
for example you click "Ok" the wait dialog appears
then once the function is completed the modless(wait) dialog disappear,
my problem is, if the user clicks away from the modless dialog, although
its still there focus can go somewhere else
how can i set the focus, on the modless dialog so that i cant click elsewhere
and that the modless dialog stays in focus until it disapears
ta
si
|
|
|
|
|
I think you want a modal dialog. Try looking into CWnd::DoModal()
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
There are several possible solutions. One solution is to handle the different window focus messages and process them according.
Kuphryn
|
|
|
|
|
Hi All
i have a modeless dialog which i use as a wait screen.
this appears ontop of a dialog that is called
for example you click "Ok" the wait dialog appears
then once the function is completed the modless(wait) dialog disappear,
my problem is, if the user clicks away from the modless dialog, although
its still there focus can go somewhere else
how can i set the focus, on the modless dialog so that i cant click elsewhere
and that the modless dialog stays in focus until it disapears
ta
si
|
|
|
|
|
I have an edit control that is placed inside a custom popup window that I wrote. The popup appears, and then transfers fopcus to the edit control. When the user hits an Esc or Tab key something makes the computers internal speaker "beep", I presume through a call to Beep(). Is there any way to prevent this, as it's really annoying.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
ESC and TAB are handled by the default Dialog Procedure, and the beeping usually indicates something is wrong with the styles set for the popup window (don't ask me what's valid and what not, though...)
we are here to help each other get through this thing, whatever it is Vonnegut jr. boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Hello guys,
I used to print the content of a RichEditText control with following code.
But now I would like to print it in landscape and with paper specifications (12cm x8.5cm).
All articles I read are talking about the famous DEVMODE, but I have no clue how to insert this DEVMODE in my existing code.
Can you hep me ?
Thanks in advance
DD
void CTestRichEditText::OnPrint()
{
// lance l'interface pour l'imprimante
CPrintDialog printDialog(false);
bool bShowPrintDialog = TRUE; //FALSE lance directement l'impression
if (bShowPrintDialog)
{
int r = printDialog.DoModal();
if (r == IDCANCEL)
return;
}
else
{
printDialog.GetDefaults();
}
// recently added to try to print in landscape on special paper
DEVMODE *MyPrintMode;
MyPrintMode = printDialog.GetDevMode();
MyPrintMode->dmFields |= DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH;
MyPrintMode->dmOrientation = DMORIENT_LANDSCAPE;
MyPrintMode->dmPaperSize = 0;
MyPrintMode->dmPaperLength = 120;
MyPrintMode->dmPaperWidth = 85;
// end of new added code
HDC hPrinterDC = printDialog.GetPrinterDC();
FORMATRANGE fr;
int nHorizRes = GetDeviceCaps(hPrinterDC, PHYSICALWIDTH),
nVertRes = GetDeviceCaps(hPrinterDC, PHYSICALHEIGHT),
nLogPixelsX = GetDeviceCaps(hPrinterDC, LOGPIXELSX),
nLogPixelsY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
LONG lTextLength; // Longueur total du document
LONG lTextPrinted; // Longueur du document edite
// Ensure the printer DC is in MM_TEXT mode.
SetMapMode ( hPrinterDC, MM_TEXT );
// Rendering to the same DC we are measuring.
ZeroMemory(&fr, sizeof(fr));
fr.hdc = fr.hdcTarget = hPrinterDC;
// Set up the page.
fr.rcPage.left = fr.rcPage.top = 0;
fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440;
fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440;
// Set up 1" margins all around.
fr.rc.left = fr.rcPage.left + 570; // 1440; // 1440 TWIPS = 1 inch.
fr.rc.top = fr.rcPage.top + 570; 1440;
fr.rc.right = fr.rcPage.right - 570; // 1440
fr.rc.bottom = fr.rcPage.bottom - 570; // 1440
// Default the range of text to print as the entire document.
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
// Set up the print job (standard printing stuff here).
DOCINFO di;
ZeroMemory(&di, sizeof(di));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "(Untitled)";
// Do not print to file.
di.lpszOutput = NULL;
// Start the document.
StartDoc(hPrinterDC, &di);
// Find out real size of document in characters.
lTextLength = m_RichTextCtrl.SendMessage ( /*hRTFWnd,*/ WM_GETTEXTLENGTH, 0, 0 );
// do {
// Start the page.
StartPage(hPrinterDC);
// Print as much text as can fit on a page. The return value is
// the index of the first character on the next page. Using TRUE
// for the wParam parameter causes the text to be printed.
#ifdef USE_BANDING
lTextPrinted = m_RichTextCtrl.SendMessage(/*hRTFWnd,*/
EM_FORMATRANGE,
FALSE,
(LPARAM)&fr);
SendMessage(hRTFWnd, EM_DISPLAYBAND, 0, (LPARAM)&fr.rc);
#else
lTextPrinted = m_RichTextCtrl.SendMessage(/*hRTFWnd,*/
EM_FORMATRANGE,
TRUE,
(LPARAM)&fr);
#endif
// Print last page.
EndPage(hPrinterDC);
// If there is more text to print, adjust the range of characters
// to start printing at the first character of the next page.
if (lTextPrinted < lTextLength) {
fr.chrg.cpMin = lTextPrinted;
fr.chrg.cpMax = -1;
}
// Tell the control to release cached information.
SendMessage(/*hRTFWnd,*/ EM_FORMATRANGE, 0, (LPARAM)NULL);
EndDoc (hPrinterDC);
DeleteDC(hPrinterDC);
// recently added to try to print in landscape on special paper
GlobalUnlock(MyPrintMode);
// end of new added code
}
|
|
|
|
|
Something like this should get you away ...
Do this to prepare the printer DC before you start printing. (pDC is a pointer to the printer DC).
CString csPrinterName = printDialog->GetDeviceName();
_TCHAR *szPrinterName = csPrinterName.GetBuffer(0);
DWORD dwRet;
HANDLE hPrinter;
if (!OpenPrinter(szPrinterName, &hPrinter, NULL))
return;
LPDEVMODE lpDevMode;
dwRet = DocumentProperties(m_hWnd, hPrinter, szPrinterName, NULL, NULL, 0);
lpDevMode = (LPDEVMODE)malloc(dwRet);
dwRet = DocumentProperties(m_hWnd, hPrinter, szPrinterName, lpDevMode, NULL, DM_OUT_BUFFER);
if (dwRet != IDOK)
{
free(lpDevMode);
ClosePrinter(hPrinter);
return;
}
if ((lpDevMode->dmFields & DM_ORIENTATION))
lpDevMode->dmOrientation = DMORIENT_LANDSCAPE;
dwRet = DocumentProperties(m_hWnd, hPrinter, szPrinterName, lpDevMode, lpDevMode, DM_IN_BUFFER|DM_OUT_BUFFER);
ClosePrinter(hPrinter);
if (dwRet != IDOK)
{
free(lpDevMode);
return;
}
pDC->ResetDC(lpDevMode);
free(lpDevMode);
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Hello,
Thanks for your answer but I have some additionnal questions for you :
1) compared to my code, what do you mean by "before you start printing" ? at which moment exactly should I do this ?
2) is the way I set my paper length and height ok?
3) I tried to insert your code in mine, just before my "HDC hPrinterDC = printDialog.CreatePrinterDC();" line and I get the following compil errors : OpenPrinter, DocumentProperties and ClosePrinter are considered as undeclared identifiers ... Do I need an special include or what ?
4) pDC is a pointer to the printer DC ? How do I get this ?
5) "// add in here any other changes to the DEVMODE you need"
something like :
lpDevMode->dmPaperSize = 0;
lpDevMode->dmPaperLength = 120;
lpDevMode->dmPaperWidth = 85;
and what about the dmFields ?
Thanks in advance for extra explanations
DD
|
|
|
|
|
My answer was intended to set you on the right track so that you could solve the problem for yourself and learn something aliong the way. I did not and do not intend to write the code for you.
However...
1) "before you start printing" means beofre you start outputting anything to the printer DC.
3) The code is intended to prepare the printer DC so include it AFTER you create the printer DC.
Work out the rest for yourself. Don't be afraid to press F1 occasionally and read the documentation. It takes a little longer the first time but you will have learned something instead of blindly using code you don't understand.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Hello,
<<my answer="" was="" intended="" to="" set="" you="" on="" the="" right="" track="" so="" that="" could="" solve="" problem="" for="" yourself="" and="" learn="" something="" aliong="" way.="">>
If I asked you for more details, it is simply because I don't see any link between your code and mine and, as it is, it does not help me at all. I don't see how I can use it. Evermore, I received compilation errors.
<>
It is not what I expected from you, I just need some explanations that I could understand and, if possible, linked to the code I wrote . This will probably help me to understand this function usage
<<1) "before you start printing" means before you start outputting anything to the printer DC.>>
Is this answer supposed to help me ... really ??
<<work out="" the="" rest="" for="" yourself.="">>
Work is what I am doing almost every nights until 2am when I write my (quite big) application after my normal work day. I can't offer me the luxury to loose 2 days in searching and trying without success.
<<don't be="" afraid="" to="" press="" f1="" occasionally="" and="" read="" the="" documentation.="">>
I spend 2 days to "play" with MSDN documentation and search thru codeproject and codeguru articles to find a basic article that explains how to use this DEVMODE easily in a context that matches my type of program. I also wrote a lot of code to try it. Ok. I can retrive the current DEVMODE, but when I change the content, how do I precise that I want to use it ?? ResetDC is a CDC method, I have no CDC, just a HDC, so ... And it is because I did not find the correct way to use it, that I finally post my question ...
<<it takes="" a="" little="" longer="" the="" first="" time="" but="" you="" will="" have="" learned="" something="" instead="" of="" blindly="" using="" code="" don't="" understand.="">>
I am trying to find a solution that suits my code, I am not copying your code without trying to understand it, it is not very funny.
Nevertheless, thanks for your time and your example I can't understand.
DD
|
|
|
|
|
I have set up an application hook procedure. This hook is looking for WM_INITMENUPOPUP, WM_MEASUREITEM and WM_DRAWITEM messages so that I can make all menus shown by the application ownerdrawn.
The hook does catch these as required, but its the actual processing of the message I am having trouble with.
For example. My WM_MEASUREITEM handler correctly measures the menu item and returns the correct size, yet when I get to the WM_DRAWITEM message to draw it, the size comes through as 12 * 16, which is the default size of a menu item which has not been measured (not processed WM_MEASUREITEM).
It looks like I cannot modiy the MEASUREITEM struct members in the hook procedure and have the application use these values.
I have tried both the WH_CALLWNDPROC and WH_CALLWNDPROCRET hook methods for before/after porcessing of the message, but regardless the system is not using the sizes I measure for the items.
Anyone know of this problem or how to get around it? The docs on hooks are pretty sparse.
I would also like to know whether is possible from within the hook procedure to stop the application processing the message as I have already done the work in the hook procedure.
If you vote me down, my score will only get lower
|
|
|
|
|
Are you assigning lpMeasureItemStruct->itemHeight the new height?
void CMyView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
...
...
...
lpMeasureItemStruct->itemHeight = nNewHeight;
...
...
...
}
|
|
|
|
|
Yes I am. I TRACE out the values in the hook function after the OnMeasureItem() has been called. This is a variation of my owner drawn menu plug-in article so I know all the measureitem/draw item stuff works. I am just chaning it from a plug in to a hook so that it will work for all standard WIN32 programs.
If I get it working it will become another article.
Here is some of the code:
LRESULT CALLBACK CODMenu::HookFunction(int code, WPARAM wParam, LPARAM lParam)
{
CWPSTRUCT * cwpStruct = (CWPSTRUCT*)(lParam);
ASSERT(m_activeObject != NULL);
switch (cwpStruct->message)
{
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT lpMIS = (LPMEASUREITEMSTRUCT)(cwpStruct->lParam);
m_activeObject->OnMeasureItem(cwpStruct->wParam, lpMIS);
TRACE("Measure Item is %1d by %1d\n", lpMIS->itemWidth, lpMIS->itemHeight);
}
break;
case WM_DRAWITEM:
{
m_activeObject->OnDrawItem(cwpStruct->wParam, (LPDRAWITEMSTRUCT)(cwpStruct->lParam));
TRACE("WM_DRAWITEM\n");
}
break;
}
return ::CallNextHookEx(m_hookHandle, code, wParam, lParam);
}
LRESULT CALLBACK CODMenu::HookFunctionAfter(int code, WPARAM wParam, LPARAM lParam)
{
CWPRETSTRUCT * cwpretStruct = (CWPRETSTRUCT*)(lParam);
ASSERT(m_activeObject != NULL);
switch (cwpretStruct->message)
{
case WM_INITMENUPOPUP:
{
m_activeObject->OnInitMenuPopup(CMenu::FromHandle((HMENU)cwpretStruct->wParam), LOWORD(cwpretStruct->lParam), (BOOL)HIWORD(cwpretStruct->lParam));
TRACE("WM_INITMENUPOPUP\n");
}
break;
case WM_MEASUREITEM:
{
LPMEASUREITEMSTRUCT lpMIS = (LPMEASUREITEMSTRUCT)(cwpretStruct->lParam);
TRACE("After Measure Item is %1d by %1d\n", lpMIS->itemWidth, lpMIS->itemHeight);
}
break;
}
return ::CallNextHookEx(m_hookHandleAfter, code, wParam, lParam);
}
And the TRACE output is
WM_INITMENUPOPUP
Measure Item is 99 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE100.
After Measure Item is 0 by 16
Measure Item is 116 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE101.
After Measure Item is 0 by 16
Measure Item is 66 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE102.
After Measure Item is 0 by 16
Measure Item is 102 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE103.
After Measure Item is 0 by 16
Measure Item is 94 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE104.
After Measure Item is 0 by 16
Measure Item is 0 by 3
Warning: unknown WM_MEASUREITEM for menu item 0x0000.
After Measure Item is 0 by 16
Measure Item is 111 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE107.
After Measure Item is 0 by 16
Measure Item is 110 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE109.
After Measure Item is 0 by 16
Measure Item is 110 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE106.
After Measure Item is 0 by 16
Measure Item is 0 by 3
Warning: unknown WM_MEASUREITEM for menu item 0x0000.
After Measure Item is 0 by 16
Measure Item is 93 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE110.
After Measure Item is 0 by 16
Measure Item is 0 by 3
Warning: unknown WM_MEASUREITEM for menu item 0x0000.
After Measure Item is 0 by 16
Measure Item is 56 by 19
Warning: unknown WM_MEASUREITEM for menu item 0xE141.
After Measure Item is 0 by 16
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
Draw Item is 12 by 16
WM_DRAWITEM
If you vote me down, my score will only get lower
|
|
|
|
|