|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I saw an article about this on the codeproject by
Nish Nishant and it seems pretty simple first let me post his code
BOOL CPreTransTestApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if(m_haccel)
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
return(TRUE);
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
Now let me expain my scenrio I am running a client server TCPI /IP program the server is a z/os mainframe and the client is a MFC C\C++ windows based program which displays data from the mainframe
I can have up to 4 modeless dialog boxes which display data in a rich edit their pointers live are my derived CWinApp
CDBGRApp
I did all the front end work created the accelarator in my resource file had it as selection in my menu "MENUITEM" and put the appropriate message map and message handler in derived CDialog CProgDebug
I then inserted the following code into my derived CWinAppp CDBGRApp
OOL CDBGRApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if (m_haccel)
{
if (debugger[0] == NULL);
else
{
if (debugger[0]->m_hWnd == NULL);
else
{
::TranslateAccelerator(debugger[0]->m_hWnd, m_haccel, lpMsg);
return(TRUE);
}
}
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
}
debugger[0] is the first of an array defined as
CProgDebug *debugger[4];
After I created the CProgDebug with it rich edit the window didnt seem to take any input mouse or keyboard
Nish in his code didnt specify that after doing TranslateAccelrator and would have to do TranslateMessage and DispatchMessage from the msg structure as I assume that is being taken care of somewhere down the line by the frameWork
|
|
|
|
|
You missed out a test - you should only return TRUE if TranslateAccelerator() succeeds.
By the way, your if(something); else is quite confusing.
|
|
|
|
|
I am changing that so if I get a zero from from
TranslateAccelerator( that means (and can you confirm this) it wasnt one the key strokes I defined right not necessarly an error I would get a zero from TranslateAccelerator maybe thats the problem in my logic
|
|
|
|
|
Here's the Windows docs page: TranslateAcceleratorA function (winuser.h) - Win32 apps | Microsoft Docs[^]
The function returns nonzero when it successfully translates the accelerator, which is when you should not pass the message through to the default handler. Your code is bypassing the default handler entirely when your h_accel and debug variables are set (without checking if the message was a translated keycode).
|
|
|
|
|
thanks if so this code by Nish
BOOL CPreTransTestApp::ProcessMessageFilter(int code, LPMSG lpMsg)
{
if(m_haccel)
{
if (::TranslateAccelerator(m_pMainWnd->m_hWnd, m_haccel, lpMsg))
return(TRUE);
}
return CWinApp::ProcessMessageFilter(code, lpMsg);
} is incorrect
this code from Microsoft docs is correct
MSG msg;
BOOL bRet;
while ( (bRet = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
}
else
{
if (!TranslateAccelerator(
hwndMain,
haccel,
&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
as it has not TranlateAccelterator wouldnt you agree
|
|
|
|
|
They are both correct.
The first one skips the default handler if the accelerator has been translated.
The second one calls the default handler if the accelerator has not been translated.
|
|
|
|
|
thank you so much for your patience me However the way mine is set is INCORRECT as I dont have an IF testing for the validity of the TranlateAccelarator and that is why my keyboard gets locked becasue I havr return TRUE for all
|
|
|
|
|
|
if (debugger[0] == NULL);
else
{
What is wrong with
if (debugger[0] != NULL)
{
|
|
|
|
|
got a compile error when it I did that but I had semi colon after the open paren so the logic should work regardless I'll work to change it
thanks
|
|
|
|
|
ForNow wrote: I had semi colon after the open paren

|
|
|
|
|
Not to mention the semi-colons on the end of the if line, essentially making it entirely useless.
|
|
|
|
|
Yes, I have never seen that done deliberately before.
|
|
|
|
|
hi
I want to create CtoolBar dynamically, without the resource( RC file) entries.
Load image to Toolbar and set size based on certain condition.
RC file entries makes it predefined.
your help is much appreciated.
|
|
|
|
|
|
Hello,
I am trying to adjust the color balance (CYMK) of an image like this is in photoshop or some other applications.
From examples, i tried changing the current RGB to CMYK (for each pixel) using the below code.
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
tmpbmp->GetPixel(i, j, &clr);
R = clr.GetR();
G = clr.GetG();
B = clr.GetB();
c = _cyanclr / 255.0;
m = _magentaclr / 255.0;
y = _yellowclr / 255.0;
k = _blackclr / 255.0;
rr = c * (1.0 - k) + k;
gg = m * (1.0 - k) + k;
bb = y * (1.0 - k) + k;
rr = (1.0 - rr) * 255.0 + 0.5;
gg = (1.0 - gg) * 255.0 + 0.5;
bb = (1.0 - bb) * 255.0 + 0.5;
R += rr;
G += gg;
B += bb;
R = R < 0 ? 0 : (R > 255) ? 255 : R;
G = G < 0 ? 0 : (G > 255) ? 255 : G;
B = B < 0 ? 0 : (B > 255) ? 255 : B;
output->SetPixel(i, j, Gdiplus::Color(R, G, B));
}
}
With this code, i am not getting the same result like in photoshop and other applications.
I am not sure whether I am doing in right method or not.
Please suggest.
I am using C++ and gdi+.
Regards,
Gopinath.
|
|
|
|
|
It is not clear exactly what your problem is or what adjustments you are trying to make to your colours. Maybe you could explain with some examples.
|
|
|
|
|
I'm looking for a way to catch exceptions due to software or hardware errors and prevent my solution from breaking brutally, but I can't find anything complete.
I have read the two main ways of handling exceptions, C ++ and SEH, but it seems to me that both do not include all cases that can happen.
Can anyone help me ?
|
|
|
|
|
|
Drugodrf wrote: include all cases that can happen. There is no way to handle all cases. For example, what it the power cord is pulled? Or the OS crashes?
Follow best practices and you'll get most all of the likely happenings.
|
|
|
|
|
Greg Utas, thanks for article: i read it as soon as possible.
DevParty: ok, all cases is too much, but most of the cases?
I've tried both ways (exception C++ and SEH), but, for example, they catch division by zero, but not a string copy error.
|
|
|
|
|
Drugodrf wrote: they catch division by zero, but not a string copy error.
What is a "string copy error"?
|
|
|
|
|
In C/C++ you can copy a buffer to another, often a char array but not always, and unintentionally write past the end of the target. Less often but still possible you can write past the beginning as well.
So for example if you have a char[5] and you write 6 bytes to that you have a problem.
The impact of this depends on where the buffer actually lives in the memory space and often what processing has been happening up to that point.
|
|
|
|