|
Hello,
I've been asked to help create a pretty GUI, and have a jpg to work with. Unfortunately I'm not generally a GUI developer, so have no idea if this is a standard problem or not.
Has anyone tackled a similar problem in the past, converting a typical win 95 style interface into a sleek and stylish iPhone style interface, in MFC?
I expect the easiest way will be to set the JPG as the window background, then shift things around and change graphics objects until they look the same.
Does anyone have any advice they can give me, or reading material that might be useful?
Thank you!
|
|
|
|
|
Codling2020 wrote: reading material that might be useful
Take a look in the articles section here on CodeProject; there are lots of useful samples.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
CDHtmlDialog[^]. There are many articles on how to use it, here on code project
With the addition of HTML and javascript you can do a great GUI, though it is also possible with Qt library, if you wish to use it.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
modified 16-Mar-12 0:54am.
|
|
|
|
|
Hey,
I am searching for some small c++ projects with documentation . can some one help? , where i can find such projects. My programming level is not very good.I know all the functions and syntax use in c++, now i want to look some small projects with documentation.
thank you
johan
|
|
|
|
|
My advice is: read some C++ tutorials (or better a good book) first.
You may find many many open source projects on the web.
You may also have a look at Microsoft Visual C++ code samples[^].
Veni, vidi, vici.
|
|
|
|
|
Hi,
I am reading the following code example returning char* from function:
http://www.java2s.com/Tutorial/Cpp/0140__Function/Returnapointerfromafunction.htm
How is that safe? Should the returned pointer not be invalid when the function goes out of scope? I keep reading from everywhere that it is not safe to do that.
Also, this works for me:
const char* Convert(int val)
{
std::stringstream ss;
ss << val;
return ss.str().c_str();
}
Could someone explain?
Thanks
modified 15-Mar-12 9:51am.
|
|
|
|
|
Dont know much about the std::stringstream but I would have thought the buffer used for storage, ahose first member is returned by c_str() should go out of scope when the funtion returns although reference counting can change this of course.
==============================
Nothing to say.
|
|
|
|
|
Gday.
Looking at the tute you've linked to, one can see that yes indeed! A pointer is returned from a function. However, we can also see that the memory that is pointed to by this pointer is actually owned by main. - in so far as they are const char* strings.
I'm dubious about this example, since string constants are used. Had "three" & "one two three four" been assigned to variables, I'd be a lot happier about what I thought the compiler may do with them - as it stands, my understanding is that the compiler is free to do with these _temporary_ string constants as it pleases once they've been used. (once the function has been called)
You example, on the other hand - that does exhibit the problem you spoke of. As soon as the Convert function returns, the ss variable goes out of scope. At the same time, it loses ownership of the memory that it put a copy of the string into. While you still have a pointer to this memory, the ss object no longer owns it.
You should be able to demonstrate this quite easily.
1) assign the return value of the function to a variable
2) do a whole bunch of stuff involving memory allocation/deallocation
3) now try to print the string that you got earlier and stored a pointer to.
|
|
|
|
|
elelont2 wrote: I am reading the following code example returning char* from function:
http://www.java2s.com/Tutorial/Cpp/0140__Function/Returnapointerfromafunction.htm Here the scope of the variable (that is the string) is controlled by the caller.
In your code the scope of the string is NOT controlled by the caller, it ends when the function exits. Hence your function cannot work.
Veni, vidi, vici.
|
|
|
|
|
Thanks for whe replies.
So it is not even safe to return ss.str() since stringstream goes out of scope?
|
|
|
|
|
elelont2 wrote: So it is not even safe to return ss.str() since stringstream goes out of scope?
That would be safe, since the return value would be a copy of the string object. Of course, to make it working you should accordingly change the function signature:
string Convert(int val)
{
}
BTW the original function is not unsafe, is wrong.
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: since the return value would be a copy of the string object.
Ever wondered why C++ can be so heavy on the stack?
What he can do of course is pass a SS as a pinter to the func, which allocates enough storage, does its thing, and returns success or fail. Then the caller can free the storage when it has to.
This uses a much less stack than putting an entire SS object on it.
==============================
Nothing to say.
|
|
|
|
|
Erudite_Eric wrote: Ever wondered why C++ can be so heavy on the stack?
Yes, I know. However the code would be correct (in may opinion correct code id much better than wrong one ).
Erudite_Eric wrote: What he can do of course is pass a SS as a pinter to the func, which allocates enough storage, does its thing, and returns success or fail. Then the caller can free the storage when it has to. Passing a reference it is usually better.
In any case, now C++ has the move semantics[^].
Veni, vidi, vici.
|
|
|
|
|
Would it be safe to use .c_str() in a class initialization list? Constructor would take a std::string and it would be assigned to a const char* member variable.
For example:
TestClass(std::string name) : charVar(name.c_str())
|
|
|
|
|
Nope.
It would be safe if your member variable were a string (Why don't you use a string ?).
Veni, vidi, vici.
|
|
|
|
|
Yes, i will use a string, just trying to get smarter about char*
I can't quite figure out why this isn't safe either:
<pre lang="c++">
func()
{
const char* test = "hello";
MyClass* my = new MyClass(test);
return my;
}
Trying to initilize the MyClass class with const char* but it does not work like this either.
|
|
|
|
|
String literals (like "hello" ) never go out of scope, hence MyClass may safely store a pointer to it.
Veni, vidi, vici.
|
|
|
|
|
I updated and changed the literal to a function which is what i have:
<pre lang="c++">
func()
{
const char* test = GetString().c_str();
std::cout << test << std::endl;
MyClass* my = new MyClass(test);
return my;
}
For some reason the initialization does not work.
|
|
|
|
|
That's wrong.
Event if 'Here test prints correct value' you shouldn't rely on it.
Veni, vidi, vici.
|
|
|
|
|
Why is it wrong? As i understand test is in func() scope and it should not go out of scope before func() exits, which is AFTER the class has been initialized with it.
|
|
|
|
|
indeed test does not go out of scope there. However the temporary (created by the string object) test points to does. So temp is a valid variable pointing to garbage.
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: Passing a reference it is usually better.
AKA, pointer. Ever seen C++ code disassembled?
==============================
Nothing to say.
|
|
|
|
|
Erudite_Eric wrote: Ever seen C++ code disassembled?
Yes, of course.
However this is not a point: the same you may say comparing a C++ program with a C one.
Veni, vidi, vici.
|
|
|
|
|
From some while, I try to setup an subitem image to an virtual listview, but I don't get it ... to setup an item image I get in follow way :
if(pItem->mask & LVIF_IMAGE)pItem->iImage = 0;
but for subitem image ? I have to mention that I set LVS_EX_SUBITEMIMAGES listview style ... thank you.
|
|
|
|
|
See here[^] for details of setting the subitem.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|