Computing.Net > Forums > Programming > Win32 Applications C++

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Win32 Applications C++

Reply to Message Icon

Original Message
Name: livingdecay
Date: October 17, 2004 at 10:47:20 Pacific
Subject: Win32 Applications C++
OS: Windows XP Professional
CPU/Ram: AMD Athlon XP 1800+/512Mb
Comment:

I have just started learning to create Win32 Apps in C++. I am trying to make a program with a dialog box that displays the sum of the values (entered into 2 textboxes) in a static text. It works fine, except that I cant seem to join two strings together. I am using the SetText function, and I want to set the static text to <"Result: " + total>, but it gives me the error message "cannot add two pointers". I checked the help file, and '+' is the only concatenation operator i could find. Also, if i type

string total;

after I #include <string.h>, it tells me that "'string' is an undeclared identifier". The above code works perfectly for console apps, but not with win32.

Any help appreciated.

Athlon XP 1800+
512Mb DDR266 RAM
Leadtek Geforce 6800
Thermaltake 360W PSU
56X CD-ROM
52x24x52 Samsung CD-RW
20 GB Maxtor HDD
80 GB Hitachi HDD
Gigabyte GA-7DX+ mobo


Report Offensive Message For Removal


Response Number 1
Name: BlueRaja
Date: October 17, 2004 at 11:51:23 Pacific
Reply: (edit)

If you want to use the string class, include the standard string header:
#include <string>
...
string myString;

If you're using char*'s, use the strcat(char*,char*) function to concatenate.

AKhalifman@hotmail.com


Report Offensive Follow Up For Removal

Response Number 2
Name: livingdecay
Date: October 19, 2004 at 10:54:43 Pacific
Reply: (edit)

I tried what you said, but I still have the same problem: the debugger tells me that "string" [the one i used to declare the variable] is an undeclared identifier. It's as if it doesn't recognize <string.h>

Also, strcat causes my program to just crash, however i am using
LPTSTR total = new char [20];
to declare my string that i use to store the total, if this could be the problem.

Got any other suggestions up your sleeve please?

Athlon XP 1800+
512Mb DDR266 RAM
Leadtek Geforce 6800
Thermaltake 360W PSU
56X CD-ROM
52x24x52 Samsung CD-RW
20 GB Maxtor HDD
80 GB Hitachi HDD
Gigabyte GA-7DX+ mobo


Report Offensive Follow Up For Removal

Response Number 3
Name: BlueRaja
Date: October 19, 2004 at 14:57:43 Pacific
Reply: (edit)

It would help to see some code...

AKhalifman@hotmail.com


Report Offensive Follow Up For Removal

Response Number 4
Name: livingdecay
Date: October 20, 2004 at 10:37:42 Pacific
Reply: (edit)

Here is the code you wanted..sorry, didn't figure you'd want to have to sit and read it:

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include "resource.h"


LRESULT CALLBACK add(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);


INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGADD), NULL, reinterpret_cast<DLGPROC>(add));
return false;
}

LRESULT CALLBACK add(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
LPTSTR val1 = new char[20], val2 = new char[20], total = new char[20];
HWND hwndVal1, hwndVal2, hwndTotal;
double fVal1 = 0, fVal2 = 0, fTotal = 0;

switch(Msg)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
hwndVal1 = GetDlgItem(hWndDlg, IDC_EDIT1);
hwndVal2 = GetDlgItem(hWndDlg, IDC_EDIT2);
hwndTotal= GetDlgItem(hWndDlg, IDC_OUT);

GetWindowText(hwndVal1, val1,20);
GetWindowText(hwndVal2, val2,20);

fVal1 = atof(val1);
fVal2 = atof(val2);
fTotal= fVal1 + fVal2;

total = _gcvt(fTotal,12,total);
SetWindowText(hwndTotal, total);
break;
case IDEXIT:
EndDialog(hWndDlg, 0);
break;
case WM_DESTROY:
EndDialog(hWndDlg, 0);
break;
}
}
return false;
}


Athlon XP 1800+
512Mb DDR266 RAM
Leadtek Geforce 6800
Thermaltake 360W PSU
56X CD-ROM
52x24x52 Samsung CD-RW
20 GB Maxtor HDD
80 GB Hitachi HDD
Gigabyte GA-7DX+ mobo


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software