|
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.
|
|
|
|
|
Whatever works is the right method. There's no "not". Unless all one does is repost code they dug up from elsewhere and hasn't the foggiest idea what they're doing THAT for.

|
|
|
|
|
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.
|
|
|
|
|