Basic C++ GUI – TextOut trouble

Written by

So, I’m making a small and simple (at least it is right now) program.. at present, it is designed to have 3 items in it… 2 push buttons, and text.

The buttons start a 5 and 10 minute count-down, respectively, and the text is the remaining time.

I’m using CreateWindowEx for the buttons (in my WM_CREATE), and handling the time via SetTime and WM_TIMER messages (basically once every second taking down my time value).

Now for the problem.. my time shows as 0:0 (which is of course what it should be)… however it shows it all the time. It won’t update.

Please see the stripped down WndProc, and be so kind as to tell me what I’m doing wrong.

I appologise for the lack of indentation.. it appears that the forum trims it out.

LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hDC;
HWND FiveTimer,TenTimer,Panic;
HWND EditBox;
char time[]="xx:xx";
char mins[]="00";
char secs[]="00";

switch(Message) {
case WM_CREATE:
FiveTimer = CreateWindowEx(
NULL,
TEXT("Button"),
TEXT("5 MIN"),
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
10,10,
100,50,
hWnd,(HMENU)ID_BUT_FIVE,
ghInstance,NULL);
if (FiveTimer==NULL){
MessageBox(hWnd,TEXT("Error – Could not create FiveTimer Button"),TEXT("Error"),MB_OK);
}
TenTimer = CreateWindowEx(
NULL,
TEXT("Button"),
TEXT("10 MIN"),
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
10,70,
100,50,
hWnd,(HMENU)ID_BUT_TEN,
ghInstance,NULL);
if (TenTimer==NULL){
MessageBox(hWnd,TEXT("Error – Could not create TenTimer Button"),TEXT("Error"),MB_OK);
}
break;
case WM_PAINT:
itoa(MyMins,mins,10);
itoa(MySecs,secs,10);
strcpy(time,mins);
strcat(time,":");
strcat(time,secs);
hDC = BeginPaint(hWnd,&ps);
TextOutA(hDC,160,10,time,strlen(time));
EndPaint(hWnd,&ps);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_BUT_FIVE:
MyMins=0;
MySecs=4;
SetTimer(hWnd,ID_BUT,1000,NULL);
break;
case ID_BUT_TEN:
MyMins=0;
MySecs=9;
SetTimer(hWnd,ID_BUT,1000,NULL);
break;
default:
;
}
break;
case WM_TIMER:
if (MySecs==0){
if (MyMins==0){
KillTimer(hWnd,ID_BUT);
MessageBox(NULL,TEXT("TIMER EXPIRED!!"),TEXT("ALERT"),MB_OK);
}
else {
MyMins–;
MySecs=59;
SetTimer(hWnd,ID_BUT,1000,NULL);
}
}else if (MySecs>=1){
MySecs–;
SetTimer(hWnd,ID_BUT,1000,NULL);
}

break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, Message, wParam, lParam);
}
return 0;
}

Here is the original:
Basic C++ GUI – TextOut trouble

Sep
30

Need help with practice test i have a test tomorrow and i need to know this

Written by

Please help me with this test it is only a practice and i must know everything on it. And i have no way of checking to see if i get the answers right so thats why im asking ya’ll so i can tell weather i got the answer right.There is also an attachment if you would prefer that. Thank you

1)In this course, we have discussed several basic types of loops. Name two of these and state two ways they differ from each other. (Hint: The "Batch Processing Loop" is not one of them.) (3 points)

2)We have discussed a special case of one of these that we called the "Batch Processing Loop". Write or draw a simple diagram of this loop showing the important points. I.e.: where do the reads happen; where does it process; what and where is the test?

3)Show what is output by the following. (16 Points)

int main()
{

int x = 0, y = 5, z = 10;

if( x>y && z>x || y=z ) // Output?_______________
cout<<"True";
else cout<<"False";

x = 0; y = 5: z = 10;
if( ! ( x<y || z>x ) && y!=z ) // Output?_______________
cout<<"True";
else cout<<"False";

x = 0; y = 5: z = 10;
if( x<y && y<z && x=10 ) // Output?_______________
cout<<"True";
else cout<<"False";

x = 0; y = 5: z = 10;;
if( (y+z)<20 && y<=z ) // Output?_______________
cout<<"True";
else cout<<"False";
}

4)Write a C++ Program that will open a file of integers in A:numbers.txt, read all of the numbers from the file, and output the sum of the even numbers; ignore odd numbers. This is an EOF (or batch processing) loop. Assume that the last line ends with a new line; this means that you don’t have to deal with the possible OBO at the end. (20 points)

You will need two integer variables. I will call these in_val and sum.

Open the file and zero the variables
Read in_val
while not EOF
if in_val MOD 2 is zero
sum = sum + in_val
read in_val

print the sum

Please write on this page and use the back if you need to do so.
5)Consider the following program:

int main() // program begins
{
int i, j, k, mid;
cout<<"Enter three different integers.n";
cin>>i>>j>>k;

cout<<"The middle number entered was "<<mid<<".n"
return 0;
}// end of program.

Assume that the user enters 3 different integers. Write the “if” logic that will assign the middle value to the variable “mid”. (Hint: It’s the 3 shells logic.). (20 points)

6)Write a C++ program that will read three integers from the keyboard. If any integer is odd, then your program will add one to it and make it even.

(Hint:)
if (i%2 == 0)
i++;

Calculate and print the average of the three to the monitor. (Hint: add them up and divide by 3.) (20 points)

Example:

Enter an integer.
4
Enter an integer.
7
Enter an integer.
12
The Average is 8

Just take the default number of decimal places… don’t bother rounding. The numbers shown are examples only. Do not code 4, 7, and 12 into your program. Use variables!

Please write on this page and use the back if you need to do so.
7)What is output by the following loop? (10 points)

i = 21; // assume i is an int

while( i > 10 )
{
cout<<i<<’n';
i-=2; // means i = i – 2
}

19
17
15
13
11

8)Show the value of the following statements. Some of these statements may perform variable coersion. If the statement would produce a compiler ERROR (not a warning), then indicate this condition with the word: "error". If the result is of type float, then be sure to put the decimal in your answer even if it’s zero! (Example: f3 equals 5.0! An answer of 5 would not be correct.) (1 point each)

(Note: the ASCII code of ‘A’ is 65, ‘B’ is 66, ‘C’ is 67 and so on.)

char ch1 = ‘A’, ch2 = ‘B’, ch3 = ‘C’;
int i = 10, j = 50, k = 5;
float f1 = 2.0, f2 = 2.2, f3 = 5.0;

(a) j % i _____________

(b)f3 / f1 _____________

(c)i = j + k / (int) f3 + (int) ch1 % k _____________

(d)f1 + f2 _____________

(e)i / k _____________

(f)i / f3 _____________

(g)i = f2; (What will i get?) _____________

(h)i = ch1; (What will i get?) _____________

Attached Files
File Type: docx 1436 Test 1.practice.docx (18.2 KB)

View post:
Need help with practice test i have a test tomorrow and i need to know this

Sep
30