Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
I have two question here .

I have created a form using c++ and send an exe file to my friend when i send it the form size varies and picture is alignment is not proper . How to keep the form constant even when you send it to other people .

Second question . I have created a form using c++ with tab contols . In the tabpage1 contains 5 buttons and textbox when you click on button it will open form2 which contains button . When the button in form is pressed textlike"you have clicked on form2" should be displayed on textbox in form1 . When i add form1. in the form2 code . It shows error . Help needed for both problems
Posted
Updated 29-Jun-11 22:27pm
v3

Use form1.height and for1.width methods you can keep your forms constantly.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jul-11 0:56am    
No, OP only think the size was changed (why, would you think?). The problem is different.

Please see my answer.
--SA
It's been a long time since I last did GUI stuff myself, but I do remember that before creating a window you can set its parameters to be not resizable. I'm pretty sure you cannot do this after the window is created, so you'll have to check the documentation on the Create() function (or however it's called).

With regard to the second problem, each of the two tabs is a child of the parent window. The parent does know all of its children, but the children do not know of their siblings, and they only got a pointer to their parent whose type is anonymized as CWnd*, so they don't know about any special functions that your actual parent window class may possess.

One clean way to solve this would be to use a callback mechanism. Here is a short outline of what you need to do:
// file IButtonCallback.h
class IButtonCallback {
public:
   virtual void OnForm2Button1Pressed() = 0;
};

// file mainwnd.h
#include "IButtonCallback.h"
class MainWnd : public CWnd, IButtonCallback {
   // ...
   void OnForm2Button1Pressed();
};

// file mainwnd.cpp
MainWnd::MainWnd(/*...*/) { // constructor
   form2.SetCallback(this);
   // ...
}
void MainWnd::OnForm2Button1Pressed() {
   form1.SetText(_T("Button pressed!"));
}

// file form1.h
class Form1 : public CWnd {
   // ...
   void SetText(TCHAR* text);
};

// file form2.h
#include "IButtonCallback.h"
class Form2 : public CWnd {
   // ...
   void SetCallback(IButtonCallback* cb);
   void OnButtonPressed();
private:
   IButtonCallback* m_cb;
};

// file forms.cpp
void Forms::SetCallback(IButtonCallback* cb) {
   m_cb = cb;
}
void Form2::OnButtonPressed() {
   m_cb->OnForm2Button1Pressed();
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jul-11 0:55am    
There is much better way, please see my answer.
Also, the problem of the size is different -- it's not the size.
--SA
Stefan_Lang 1-Jul-11 3:30am    
Regarding form communication: Your solution is easier as long as only one other form requires a notification, but the moment you have more than one inter-form communication, my design is more flexible and easier to maintain. technically it would be even better if I put the implementation of the callback functions into a seperate class and turned this into a true observer pattern.

Regarding size I agree that the best solution is to make your forms resizable. But unfortunately VS provides very little help here, so without the help from some GUI library it's simply more practical to ensure fixed size of your window. I consider it a failure of Windows that changing screen resolution or using different font sizes tends to break GUIs. But the moment you use a decent library the need to program around that shortcoming diminishes. Therefore I consider it more appropriate to help someone get his display right than have him make it right at dynamical resolutions.
Sergey Alexandrovich Kryukov 3-Jul-11 1:38am    
Well, not exactly. My method does exactly the same in terms of flexibility, maybe you just missed it. You can implement different interfaces in different pointers and exchange interface references. The point is: not giving any extra access for one form to another, only the interfaces. Everything else can be the same. Interfaces can be as powerful as needed but not more than that is strictly required.
--SA
Stefan_Lang 4-Jul-11 7:35am    
Hm, I'm confused. I've looked at your method again to see if I indeed missed something, but I found that whatever I had in mind when writing my response, it wasnt that! Maybe I've looked at something else and wrongly credited you for it.

Nevermind then.
Sergey Alexandrovich Kryukov 5-Jul-11 1:44am    
Sorry, I don't completely understand. Are you talking about size-tolerant UI or about form collaboration. My comment above was about comparison your form collaboration and mine and flexibility. I maintain the with interfaces you can have the same flexibility; the only difference is abstracting out only interface, not passing wider reference to the form instance itself, which provides less isolation (potentially pass too much access). What does it mean "wasn't that"?

As to resize -- I think I explained. This is not just about benefits of size-tolerant design, which are apparent. I simply say OP did not really experienced problem of size; but some reason it only seemed so.

Thank you.
--SA
First, on the follow-up question: communication between forms. This is a popular question about form collaboration. The most robust way is implementing appropriate interface in a form class.

Please see the details in my past answer:
How to copy all the items between listboxes in two forms[^].

As to the form size: I don't thing the form size you deliver to someone else has changed. It only seems so because of different system, screen resolution in particular. You don't want to keep the form size. Instead, you should learn resolution-tolerant form design.

See my recommendations in my past answer: Zom Out malfunctions when Screen resolution changes[^].

See also another one: GUI Apperance - C#.Net[^].

One more, with a simple code sample: how to dock button so that it can adjust with the form[^].

Good luck,
—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jul-11 0:57am    
Please, never post questions as solutions. 1) they will be removed, 2) nobody will get e-mail notification.
Instead, use "Improve question", "Add comment" or reply to existing comment.
--SA
steven8Gerrard 1-Jul-11 9:22am    
I'm using vc++. I tried to translate c# into c++ but failed any c++ examples would be helpful
Sergey Alexandrovich Kryukov 3-Jul-11 1:52am    
Sorry, I don't have C++ samples. Indeed you cannot translate C# to C++ in most cases -- it would rather be re-writing. By my material is mostly design ideas which can be implemented in C++. Would you expect writing a whole example of resolution-tolerant application? I don't have one and cannot afford writing one for you, sorry. If you have a concrete difficulty, I'll try to answer.
--SA
steven8Gerrard 5-Jul-11 4:33am    
Tried docking method and it works so far . Another question i have added two pic in my forms when i maximise right pic stays where it is doesn't move so form looks different any method to solve that problem
Sergey Alexandrovich Kryukov 5-Jul-11 5:01am    
First, if you think my advice makes sense, please formally accept it (green button). I already answered your main and follow-up questions.

As to picture layout, could you post a different question and make is way more descriptive, as right now it is not clear. Create a new question page, don't forget to tag platform/language and Forms. Just in case, notify me by replying the this comment after you post it.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900