|
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.
|
|
|
|
|
|
jschell wrote: you write 6 bytes to that you have a problem. Of course, but not an exception. Which is why you are always reminded to use the strxxx_s versions which include bounds checking. But you have to work quite hard to write past the beginning of a buffer.
|
|
|
|
|
#include <iostream>
#include <string>
#include <cstring>
#include <stdlib.h>
#define MAX_RESPONSE_LENGTH 5
using namespace std;
int main()
{
const float ENGLISH_MIDTERM_PERCENTAGE = .25;
const float ENGLISH_FINALEXAM_PERCENTAGE = .25;
const float ENGLISH_RESEARCH_PERCENTAGE = .30;
const float ENGLISH_PRESENTATION_PERCENTAGE = .20;
const float SCIENCE_MIDTERM_PERCENTAGE = .40;
const float SCIENCE_FINALEXAM_PERCENTAGE = .40;
const float SCIENCE_RESEARCH_PERCENTAGE = .20;
const float MATHS_MIDTERM_PERCENTAGE = .50;
const float MATHS_FINALEXAM_PERCENTAGE = .50;
float finalNumericGrade = 0;
char finalLetteredGrade;
char response [MAX_RESPONSE_LENGTH];
string moreGradesToCalculate;
short midtermGrade = 0;
short finalExamGrade = 0;
short researchGrade = 0;
short presentationGrade = 0;
cout << "Do you have a grade to calculate? \n";
cin >> moreGradesToCalculate;
for(int x = 0; x < moreGradesToCalculate.length();x++){
moreGradesToCalculate[x] = toupper(moreGradesToCalculate[x]);
}
while(moreGradesToCalculate == "YES" ){
cout << "Designate a student type to calculate.\n\n";
cout << "1.English 2.Science\n\n"
<< "3.Maths \n";
cin >> response;
if(strlen(response) == 0){
cout << "You must select a student type.\n" << endl;
return 0;
}
if((atoi(response) < 1) || (atoi(response) > 3)) {
cout << response << " - is not a valid student type.";
return 1;
}
switch (atoi(response))
{
case 1:
cout << "Midterm Grade : ";
cin >> response;
midtermGrade = atoi(response);
cout << "Final Exam Grade : ";
cin >> response;
finalExamGrade = atoi(response);
cout << "Research Grade : ";
cin >> response;
researchGrade = atoi(response);
cout << "Presentation Grade : ";
cin >> response;
presentationGrade = atoi(response);
finalNumericGrade = ((midtermGrade * ENGLISH_MIDTERM_PERCENTAGE) + (finalExamGrade * ENGLISH_FINALEXAM_PERCENTAGE) +
(researchGrade * ENGLISH_RESEARCH_PERCENTAGE) + (presentationGrade * ENGLISH_PRESENTATION_PERCENTAGE));
cout << endl << "**** ENGLISH STUDENT ****\n" << endl;
cout << "Midterm Grade : " << midtermGrade << endl;
cout << "Final Exam Grade : " << finalExamGrade << endl;
cout << "Research Grade : " << researchGrade << endl;
cout << "Presentation Grade : " << presentationGrade << endl << endl;
if((finalNumericGrade >= 92) && (finalNumericGrade <= 100)) {
finalLetteredGrade = 'A';
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n" ;
}
else
if((finalNumericGrade < 92) && (finalNumericGrade >= 85)) {
finalLetteredGrade = 'B';
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n\n";
}
else
if((finalNumericGrade < 85) && (finalNumericGrade >= 78)) {
finalLetteredGrade = 'C';
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n\n";
}
else
if((finalNumericGrade < 78) && (finalNumericGrade >= 70)) {
finalLetteredGrade = 'D';
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n\n";
}
else
if((finalNumericGrade < 70) && (finalNumericGrade >= 0)) {
finalLetteredGrade = 'F';
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n\n";
}
break;
case 2:
cout << "Midterm Grade :";
cin >> response;
midtermGrade = atoi(response);
cout << "Final Exam Grade :";
cin >> response;
finalExamGrade = atoi(response);
cout << "Research Grade :";
cin >> response;
researchGrade = atoi(response);
finalNumericGrade = ((midtermGrade * SCIENCE_MIDTERM_PERCENTAGE) + (finalExamGrade* SCIENCE_FINALEXAM_PERCENTAGE)
+ (researchGrade * SCIENCE_RESEARCH_PERCENTAGE));
if((finalNumericGrade >= 90) &&(finalNumericGrade <= 100))
finalLetteredGrade = 'A';
else
if((finalNumericGrade < 90) &&(finalNumericGrade >= 80))
finalLetteredGrade = 'B';
else
if((finalNumericGrade < 80) &&(finalNumericGrade >= 70))
finalLetteredGrade = 'c';
else
if((finalNumericGrade < 70) &&(finalNumericGrade >= 60))
finalLetteredGrade = 'D';
else
if((finalNumericGrade < 60) && (finalNumericGrade >= 0))
finalLetteredGrade = 'F';
cout << endl << "**** SCIENCE STUDENT ****\n\n";
cout << "Midterm Grade : " << midtermGrade << endl;
cout << "Final Exam Grade : " << finalExamGrade << endl;
cout << "Research Grade : " << researchGrade << endl << endl;
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n\n";
break;
case 3:
cout << "Midterm Grade :";
cin >> response;
midtermGrade = atoi(response);
cout << "Final Exam Grade :";
cin >> response;
finalExamGrade = atoi(response);
finalNumericGrade = (midtermGrade * MATHS_MIDTERM_PERCENTAGE) + (finalExamGrade* MATHS_FINALEXAM_PERCENTAGE);
if((finalNumericGrade >= 90) & (finalNumericGrade <= 100))
finalLetteredGrade = 'A';
else
if((finalNumericGrade >= 83 ) & (finalNumericGrade < 90 ))
finalLetteredGrade = 'B';
else
if((finalNumericGrade >= 76 ) & (finalNumericGrade < 83 ))
finalLetteredGrade = 'C';
else
if((finalNumericGrade >= 65) & (finalNumericGrade < 76))
finalLetteredGrade = 'D';
else
if((finalNumericGrade < 65) & (finalNumericGrade >= 0))
finalLetteredGrade = 'F';
cout << endl << "**** MATHS STUDENT ****\n\n";
cout << "Midterm Grade : " << midtermGrade << endl;
cout << "Final Exam Grade : " << finalExamGrade << endl << endl;
cout << "Final numeric grade is : " << finalNumericGrade << "\n";
cout << "Final lettered grade is : " << finalLetteredGrade << "\n\n";
break;
default:
cout << "Is not a valid student type:)\n" << endl;
return 1;
}
cout << "Do you have more grades to calculate?\n";
cin >> moreGradesToCalculate;
cout << endl;
for(int x = 0; x < moreGradesToCalculate.length(); x++){
moreGradesToCalculate [x] = toupper(moreGradesToCalculate[x]);
}
}
cout << endl << "Thanks for using my grade calculator.";
return 0;
}
PLEASE HELP ME EXAMINE THE LOGICAL ERROR IN THIS CODE....
1. THE STRLEN() FUNCTION THAT CHECK IF THE USER PRESS THE ENTER KEY WITHOUT PROVING A RESPONSE TO THE QUESTION.
2. THE DEFAULT KEYWORD IN THE SWITCH STATEMENT THAT CHECKS A NON-INTEGER RESPONSE FROM THE USER.
|
|
|
|
|
Compiling does not mean your code is right!
Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English, rather than German for example - not that the email contained the message you wanted to send.
So now you enter the second stage of development (in reality it's the fourth or fifth, but you'll come to the earlier stages later): Testing and Debugging.
Start by looking at what it does do, and how that differs from what you wanted. This is important, because it give you information as to why it's doing it. For example, if a program is intended to let the user enter a number and it doubles it and prints the answer, then if the input / output was like this:
Input Expected output Actual output
1 2 1
2 4 4
3 6 9
4 8 16 Then it's fairly obvious that the problem is with the bit which doubles it - it's not adding itself to itself, or multiplying it by 2, it's multiplying it by itself and returning the square of the input.
So with that, you can look at the code and it's obvious that it's somewhere here:
int Double(int value)
{
return value * value;
}
Once you have an idea what might be going wrong, start using the debugger to find out why. Put a breakpoint on the first line of the method, and run your app. When it reaches the breakpoint, the debugger will stop, and hand control over to you. You can now run your code line-by-line (called "single stepping") and look at (or even change) variable contents as necessary (heck, you can even change the code and try again if you need to).
Think about what each line in the code should do before you execute it, and compare that to what it actually did when you use the "Step over" button to execute each line in turn. Did it do what you expect? If so, move on to the next line.
If not, why not? How does it differ?
Hopefully, that should help you locate which part of that code has a problem, and what the problem is.
This is a skill, and it's one which is well worth developing as it helps you in the real world as well as in development. And like all skills, it only improves by use!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Member 15281733 wrote: PLEASE HELP ME EXAMINE THE LOGICAL ERROR IN THIS CODE....
1. THE STRLEN() FUNCTION THAT CHECK IF THE USER PRESS THE ENTER KEY WITHOUT PROVING A RESPONSE TO THE QUESTION.
2. THE DEFAULT KEYWORD IN THE SWITCH STATEMENT THAT CHECKS A NON-INTEGER RESPONSE FROM THE USER. You've failed to explain exactly what the problem is. How are we, therefore, to know what your program is supposed to do?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|