|
Nononono.
Kids, kids, haven't had to learn Windows programming the hard way...
You trap the WM_NCHITTEST message, and if it's in the area you want to act as the caption (which is where you usually click to drag the window) you respond HT_CAPTION, else you call DefWindowProc (or equivalent).
|
|
|
|
|
I need some help with Ini files as I am going to parse them in my application .
I have the following questions:
1. THis file is not going to be placed in the Windows directory . How should i Access it using the GetProfileString method ?
2. This File is a bit different . tags [] are going to be placed as
[main]
detail1=0
detail2=1
detail3=1
[detail1]
param_a=val1
param_b=val2
param_c=val3
[detail3]
.
.
Which is the best method to extract these details ?
|
|
|
|
|
Use GetPrivateProfile...() instead of GetProfile...() . You should have no problems with the format.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Use GetPrivateProfileXXX functions to access .ini files located anywhere. GetProfileXXX family of functions works only with win.ini.
act_x wrote:
2. This File is a bit different . tags [] are going to be placed as
SO where's the difference? Square brackets are used to mark sections. Are you going to use them in other context?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I am a student trying hard to learn the language and seem to be doing pretty well....for the most part. I have a small project I have been working on the past 2 weeks and am really stuck. If someone could possibly lend me some guidence I'd REALLY appreciate it.
My project has to include a FlexGrid Control with 7 Rows (one fixed) and 7 columns (one fixed). I've got this done and all the labels set. I have created my array, and used a switch statement to populate the fields that aren't fixed. For some reason that data seems to be entering into my FlexGrid purely at random. I've done all I can possibly think of and it isn't making any sense to me why this is happening.
Could someone please help me get pointed in the right direction?
Thank you for your time,
Garry
|
|
|
|
|
how do you populate fields in your Grid ?
Id use
grid.SetRow(desired_row);
grid.SetCol(desired_col);
grid.SetText(value);
|
|
|
|
|
I have a Child Frame that I need to minimize and maximize but not destroy . i.e I dont want the Frame to be destroyed when one clicks on the "X" button on the top. Please help
|
|
|
|
|
Add WM_CLOSE handler and do nothing in it. Especially, *do not* call base class.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
You could remove WS_SYSMENU from the window style for the child window. Then there wouldn't be an "X" button.
|
|
|
|
|
i have a file that have a string:
%4d%4d
then i want to format %4d to string./
let say.. %4d is 3425 and second %4d is 876. ( they could be any number, i dont know. if you open the file and see you only see %4d%4d not a number.)
first can i format them? how should i???
|
|
|
|
|
maybe this is what you want:
char buffer[10];
sprintf(buffer, "%4d", myInt);
file.Write(buffer, strlen(buffer));
|
|
|
|
|
no i know that. but that is not what i want...
there is a %4d.. but i have to read it or convert it to string or int
not int to string.
|
|
|
|
|
I am sorry, but not clear with your requirement. Anyway, this is what I understand so far:
If there is a 4-character field in your file, and you want to extract it, you can use this:
nRet = fscanf(fp, "%4d", &myInt);
if ( nRet == 0 )
{
nRet = fscanf(fp, "%4s", &myStr);
if ( nRet == 0 )
TRACE("Cannot extract this field\n");
}
|
|
|
|
|
your question is not very clear - does the file have two numbers, say
3425
876
?
If so, you can reformat them using the CString::Format(...) function and rewrite them back to the file.
ashish
|
|
|
|
|
no.. here what the file has
hello, hi, 5s%4d%4d
and i have to convert %4d -> number ( eg. 342)
|
|
|
|
|
I pretty much have no knowledge of MFC's other than the few tutorials I read here. Anyway, would the program below be simple to convert into a GUI? I tried to create a dialog based application to no avail.
------------------------
// Inventory System
/*
LOGIN/PW:
admin/admin
power/power
end/end
*/
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
vector<string> vitem;
vector<int> vquantity;
void arecord() {
string name;
int quantity = 0;
cout << endl;
cout << "Enter item name: ";
cin >> name;
cout << "Enter quantity: ";
cin >> quantity;
vitem.push_back(name);
vquantity.push_back(quantity);
}
void dblist() {
cout << endl;
cout << "-----------------------------------------------" << endl;
for (int i=0; i < vitem.size(); i++) {
cout << i << " : " << vitem[i] << " " << vquantity[i] << endl;
}
cout << "-----------------------------------------------" << endl;
}
void drecord() {
int rnumber = 0;
cout << endl;
cout << "What record do you wish to delete: ";
cin >> rnumber;
vitem.erase(vitem.begin() + rnumber);
vquantity.erase(vquantity.begin() + rnumber);
}
void erecord() {
int rnumber = 0;
int nquantity = 0;
vector<string>::iterator n = vitem.begin();
vector<int>::iterator a = vquantity.begin();
string nname;
cout << endl;
cout << "Which record do you wish to modify: ";
cin >> rnumber;
cout << "What will be the new item name: ";
cin >> nname;
cout << "What will be the new quantity: ";
cin >> nquantity;
n[rnumber] = nname;
a[rnumber] = nquantity;
}
void srecord() {
string tsearch;
cout << endl;
cout << "What item do you wish to search for: ";
cin >> tsearch;
for (int i = 0; i < vitem.size(); i++) {
if (vitem[i] == tsearch) {
cout << endl;
cout << i << " : " << vitem[i] << " " << vquantity[i] << endl;
}
}
}
void power() {
int option = 0;
while (option != 4) {
cout << endl;
cout << "USER: POWER" << endl;
cout << "1) Add records." << endl;
cout << "2) List records." << endl;
cout << "3) Search records." << endl;
cout << "4) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, 3, or 4: ";
cin >> option;
if (option == 1)
arecord();
else if (option == 2)
dblist();
else if (option ==3)
srecord();
}
}
void end() {
int option = 0;
while (option != 3) {
cout << endl;
cout << "USER: END" << endl;
cout << "1) List records." << endl;
cout << "2) Search records." << endl;
cout << "3) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, or 3: ";
cin >> option;
if (option == 1)
dblist();
else if (option == 2)
srecord();
}
}
void admin() {
int option = 0;
while (option != 6) {
cout << endl;
cout << "USER: ADMIN" << endl;
cout << "1) Add records." << endl;
cout << "2) List records." << endl;
cout << "3) Delete records." << endl;
cout << "4) Edit records." << endl;
cout << "5) Search records." << endl;
cout << "6) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, 3, 4, 5, or 6: ";
cin >> option;
if (option == 1)
arecord();
else if (option == 2)
dblist();
else if (option ==3)
drecord();
else if (option == 4)
erecord();
else if (option == 5)
srecord();
}
}
int loginpw() {
string login;
string pw;
cout << endl;
cout << "Enter Login: ";
cin >> login;
cout << "Enter Password: ";
cin >> pw;
if (login == "power") {
if (pw == "power")
power();
else
cout << "Wrong password!" << endl;
return -1;
}
else if (login == "end") {
if (pw == "end")
end();
else
cout << "Wrong password!" << endl;
return -1;
}
else if (login == "admin") {
if (pw == "admin")
admin();
else
cout << "Wrong password!" << endl;
return -1;
}
else {
cout << "Invalid login!" << endl;
return -1;
}
}
int load() {
string litem;
int lquantity;
ifstream fin("is.txt");
if (!fin)
return 0;
while (false == fin.eof()) {
fin >> litem >> lquantity;
vitem.push_back(litem);
vquantity.push_back(lquantity);
}
vitem.pop_back();
fin.close();
}
void save() {
ofstream fout("is.txt");
for (int i = 0; i < vitem.size(); i++)
fout << vitem[i] << " " << vquantity[i] << endl;
fout.close();
}
int main() {
load();
loginpw();
save();
return 0;
}
|
|
|
|
|
at first look .. very simple
put a button / menu option for each of the options in the main code and write a handler that does whatever it should do
cant see a problem here myself
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" sonork: 100.18128 8028finder.com
|
|
|
|
|
Thanks for replying. Is a handler the equivalent of int main() in C++?
|
|
|
|
|
I think your main problem is that cout writes to stdout, and there is no stdout in windows. THere are ways to redirect the stdout to a window, you may want to search for that here on CP.
Also, the paradigms between a GUI and a console app are different, therefore you may have to restructure how you want your program to look in a dialog. Maybe it would make more sense to have different fields that are filled with data, rather than having one large text display.
Other than that you should have no problem porting the logic between the two programs.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanks for the reply. The paradigm of Windows programming is what really gets me confused. Although the program I posted above is procedural, I do have a pretty good understanding of OOP but this MFC stuff just goes right over my head. Do you recommend any beginner's books?
|
|
|
|
|
Charles Petzold's books on Win programming are a worthy read.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Will look into it, thanks.
|
|
|
|
|
Chson wrote:
Do you recommend any beginner's books?
A good start is also the Scribble tutorial that comes with MSDN. Give it a try!
Best regards,
Alexandru Savescu
|
|
|
|
|
I've set up a class in my project that is based on the CTreeCtrl class and am trying to handle messages in the class. It will handle some, but for messages like WM_RBUTTONUP or WM_LBUTTONUP, for example, it doesn't handle those messages when the action is performed on one of the Tree items. They only work if you execute the action in the blank area of the control. Any thoughts on why this is the case and how I can get it to handle these messages?
|
|
|
|
|
Stew wrote:
They only work if you execute the action in the blank area of the control.
Probably tree control enters into modal loop when you click on items and move the mouse a little bit. In such case, messages are processed internally by routine deep inside comctl32 - you'll be unable to process them without hook.
You should handle NM_CLICK and NM_RCLICK instead.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|