|
I am using this code example to get more familiar with "connect".
I am at 3rd attempt to write easy to understand way to process menu / submenu code.
I had it working at one time, for one menu. Now I am adding more menu and now my submenus are "multiple selection" instead of single submenu.
This code example seems to have that "fixed" , but now it is using lambda...
|
|
|
|
|
hi,
VS=2015
in my mfc dialog class that is inherited from CDialogEx, i can find PreTranslateMessage method?.
I select the myDlg class, and there is no such method. Need it for some char exclusions inside edit box.
There is no Onchar method for edit box either.
|
|
|
|
|
Open ClassWizard and and add virtual method PreTranslateMessage.
Then select the message WM_CHAR to handle it in OnChar
|
|
|
|
|
How to? I know the basic printing functions and using the CPrintDialog plus PRINTDLG pd,
a little sample that only prints a statement but shows what I am using:
CPrintDialog dlg(FALSE, pd.Flags);
if (dlg.DoModal() != IDOK)
{
AfxMessageBox("Abort or Unknown Printer or Printer device error");
return;
}
pd.hDC = dlg.CreatePrinterDC();
ASSERT(pd.hDC !=0);
CDC * dc = new CDC;
dc = CDC::FromHandle(pd.hDC);
int cxPage = ::GetDeviceCaps (pd.hDC, HORZRES) ;
int cyPage = ::GetDeviceCaps (pd.hDC, VERTRES) ;
sizePrn.cx = cxPage;
sizePrn.cy = cyPage;
memset(&lf, 0, sizeof(lf));
lf.lfHeight = -MulDiv(12, dc->GetDeviceCaps(LOGPIXELSY), 72);
lf.lfWeight = FW_BOLD;
lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
lf.lfQuality = PROOF_QUALITY;
lstrcpy(lf.lfFaceName, "Times New Roman");
VERIFY(font.CreateFontIndirect(&lf));
dc->SetMapMode (MM_ISOTROPIC) ;
dc->SetWindowExt ( 1000, 1000) ;
dc->SetViewportExt (cxPage / 2, -cyPage / 2) ;
dc->SetViewportOrg (cxPage / 2, cyPage / 2) ;
dc->SetTextAlign(TA_BASELINE | TA_CENTER);
dc->SetBkMode(OPAQUE);
dc->SetMapMode(MM_TEXT);
dc->PatBlt(0, 0, sizePrn.cx, sizePrn.cy, WHITENESS);
dc->LPtoDP(&sizePrn);
dc->SelectObject(&font) ;
CSize extentChar = dc ->GetTextExtent("M",1);
int nCharHeight = extentChar.cy+4;
int nCharWidth = extentChar.cx+10;
BeginWaitCursor();
CString printDate = GetMyCurDateTime();
DOCINFO docinfo;
memset(&docinfo, 0, sizeof(docinfo));
docinfo.cbSize = sizeof(docinfo);
docinfo.lpszDocName = _T("Calif Lottery Winnings");
docinfo.fwType = 0;
rc = dc->StartDocA(&docinfo);
if (rc < 0)
{
sprintf(temp, "Unable to Begin printing - Error[%d]", rc);
MessageBox(temp, NULL, MB_OK);
dc->ReleaseAttribDC();
dc->ReleaseOutputDC();
dc->DeleteTempMap();
EndWaitCursor();
DeleteDC(pd.hDC);
if(pd.hDevMode != NULL)
GlobalFree(pd.hDevMode);
if(pd.hDevNames != NULL)
GlobalFree(pd.hDevNames);
dc = 0;
return;
}
szTitle=CString("California Lottery System Printout ") + printDate;
dc -> StartPage();
dc -> SetTextAlign(TA_LEFT | TA_TOP);
dc -> TextOut(0, 0, szTitle, szTitle.GetLength() );
dc -> MoveTo( 0, nCharHeight );
dc -> LineTo(dc -> GetTextExtent(szTitle, szTitle.GetLength()).cx, nCharHeight);
nStart =1;
And goes on to print 1 page.
What I want to do is to place a non-character on a ticket but not like an 'X' but a block like a pencil fill-in mark at a specific place on the paper. I need to supply the coordinates for the mark and do that for the full page. Has anybody done something like this before? if so, give me some hints.
Thanks
Craig
|
|
|
|
|
When things get too complicate (re: printing), I create "forms" / pages / windows that match the required output; then "capture" the visual and print that in one go (as an "image" or whatever). Total WYSIWYG. Users can even "update" the "report" (if you let them).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
That is a good idea, will look into it.
|
|
|
|
|
I am debugging / modifying my working loop code and like to insert test code and "skip " the rest of large loop.
What would be a cool way to accomplish that...?
I have been "commenting out " temporary unwanted code , but that is pretty clumsy when large code blocks are commented out.
for (index = 0; index < list.size(); ++index)
{
... working code
{
...insert test block
}
... skip this working code
} loop end
|
|
|
|
|
If I find I need to do something like this I do something like
#ifdef DEBUG
void foo( ... )
{
}
#endif
In debug mode, then I can call foo(arg, arg, arg, ... ) when I need to. Usually this would do something like print all the elements of a collection, for example.
As far as I know, you can't skip over code. You can set a break point at the top of the loop, and continue to that point. If you really want to omit portions of the loop in your debug testing the best I could suggest would be to wrap that in an #ifdef DEBUG/#endif. Alternatively, you might
#if DEBUG == 2
...
#endif Of course, you could use #if DEBUG <= 2 , etc to get different debug levels of code when you compile.
If you go that route, check with your IDE. It probably does not add a -DDEBUG to the compile command line in debug mode, so you'd have to do that yourself. If you want to have different debug levels you would pass -DDEBUG=2 (e.g.) (Linux - its probably different, but similar for windows)
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
modified 28-Jan-24 15:44pm.
|
|
|
|
|
Do you mean this (skip to next iteration)
for (int n=0; n<10; ++n)
{
cout << "working code A\n";
{
cout << "debug code, iteration = " << n << "\n";
continue;
}
cout << "working code B\n";
}
Or, possibly, this (skip the loop)
for (int n=0; n<10; ++n)
{
cout << "working code A\n";
{
cout << "debug code, iteration = " << n << "\n";
n=10; continue;
}
cout << "working code B\n";
}
?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
In C++
Macros
- As noted you can remove the code entirely
- You can also use a macro that resolves to a different value
For code
- Add a flag.
- Add a class that manages flags
Larger apps would use the second.
Your code then tests the flag. There are various ways the flags can be set: command line, config file, database. There are various ways to manage the class itself. Could be static or use a builder pattern.
Example of flag usage
if (myFlagClass.IsSet("TestFlag131")) ....
For systems (not just an app) can use special values in an API. The code of the target service looks for those special values and returns a fixed, or even variable, result. This is somewhat useful in verifying end to end enterprise functionality.
|
|
|
|
|
Voluntarily removed - wrong forum.
modified 27-Jan-24 16:00pm.
|
|
|
|
|
Salvatore Terress wrote: To make sure for people who "do not get it" - if you are not wiling to help,
please do not respond..
Kindly stop giving orders. As you have been repeatedly told, just post the question. If the answer is not to your exacting requirements, then you have two choices:
1. Politely ask for clarification.
2. Ignore it.
|
|
|
|
|
I tried placing the UpdateGame() function inside the window message processing loop but the execution never reaches that spot
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
UpdateGame();
}
}
I`m trying to mix code from two different tutorials which might be the cause of the problem. Bellow is what the initial message processing loop looked like.
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
|
|
|
|
|
At a guess PeekMessage() is always returning true. If you want UpdateGame() to always be called then remove it from the else block:
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UpdateGame();
}
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Thanks for advice, I’ll give it a try
modified 27-Jan-24 11:28am.
|
|
|
|
|
I was told that if I want to call invalidate rectangle the space between begin paint and end paint is not a good place to set the dimensions of rectangles, hence I`m trying to create an update function for my game, a place where I can set the position and dimension of rectangles and also compute all sorts of other things required in the game. I borrowed this code from a DirectX tutorial
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
UpdateGame();
}
}
but the execution never reaches UpdateGame(). Could you please help me out find a place for UpdateGame()?
modified 26-Jan-24 6:35am.
|
|
|
|
|
You need to provide more details about what you are trying to do here. Calling UpdateGame in the message loop as you show, will only work if there are no messages in the queue. And given the way Windows operates, this is not very likely. The only thing you should do in your WM_PAINT handler, is to update the screen. All calculations and measurements should be performed elsewhere.
|
|
|
|
|
Original post edited, I hope it makes sense now
|
|
|
|
|
I just ran a quick test and the call to UpdateGame does indeed get called many times in a simple Window. You need to do some more debugging to find out why that does not happen in your code.
|
|
|
|
|
Wow, you're a game developer, now!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
void UpdateGame()
{
MessageBox(hWnd, "Doing the update", "Game", MB_OK);
}
|
|
|
|
|
|
The second line of code does not compile and I get a ton of "helpful" messages.
I am asking the forum to help me to understand the messages.
I am not asking for RTFM...
If somebody is willing to help I will post the errors.
QAction tempAction;
subMenu[index]->addAction(" test ");
subMenu[index]->addAction(tempAction.setCheckable(true));
|
|
|
|
|
Posting such a question without the error message is not very helpful. Please make sure you post all the relevant information.
|
|
|
|
|
Don't make a post with a teensy bit of code and no errors, then ask "is someone willing to help?" Because if you don't supply ALL of the information on the problem, the answer is going to be NO. All you're doing is wasting time because now you have to wait for an answer of "Sure!" before you post the rest of the information required to solve the problem, then wait some more for an actual answer.
|
|
|
|
|