|
OK, I understand. So I don't need to include "Form.h" to have access to Controls of Another Form?
So if Form1 has Form1.h and Form2 has Form2.h and I declare a class let say "person" inside Form1.h. Then I create Form2 and in Form2 I change properties of person, I must declare somewhere in Form2.h that "person" class exist. In other case how Form2 will notify Form1 that properties of "person" were changed. How do I declare 'existence' of "person" in Form2??? Are you able to put some code?
Thank you
Szymon
|
|
|
|
|
You have a seperate "person.h" that defines the class "person".
Both form1 and form2 include person.h.
Form1 also includes form2.h, since it will have to create one, but it never needs to know more than the constructor.
Form2 updates itself from person, and from change events from person. Form1 does the same. So again, they have no knowledge of the internals of the other.
Bear with me on this, I have not done c++ in a while, and not without an IDE in an even longer time, so this is more psuedo code than code, or maybe it is a hybrid with c#.
person.h
class person<br />
{<br />
public person(string name, DateTime birthday);
void SetName(string name);<br />
string GetName();<br />
void SetBDay(DateTime birthday);<br />
string GetBDay();<br />
void AddBDayChangeCallBack(callBackType callBack);<br />
void DelBDayChangeCallBack(callBackType callBack);<br />
}
person.cpp
class person<br />
{<br />
private string m_name = "";<br />
private DateTime m_birthDay = new DateTime();<br />
private callBackTypeList m_bDayChangeCallbacks = new callBackTypeList();<br />
<br />
public constructor person(string name, DateTime birthday)<br />
{<br />
SetName(name);<br />
SetBDay(birthday);<br />
}<br />
void SetName(string name){}<br />
string GetName(){}<br />
void SetBDay(DateTime birthday)<br />
{<br />
m_birthDay = birthday;<br />
foreach(callBackType event in m_bDayChangeCallbacks)<br />
{<br />
invoke(event(this)); <br />
}<br />
}<br />
string GetBDay(){}<br />
void AddBDayChangeCallBack(callBackType callBack)<br />
{<br />
bDayChangeCallbacks.Add(callBack);<br />
}<br />
void DelBDayChangeCallBack(callBackType callBack)<br />
{<br />
bDayChangeCallbacks.Remove(callBack);<br />
}<br />
}
So form1 and form2 both include person.h.
form1.h and form2.h do not expose any of the components of the forms, just constructors/destructors.
The form2 constructor takes a person as a parameter, and that is how it is notified of the person, though you could also have a "void SetPerson(person perp);" definition somewhere.
Wow. That is too bad they flatten indentation.
I want to die like my Grandfather.
Peaceful, Sleeping.
Not screaming like his passengers.
|
|
|
|
|
Person exists in its own right, it has no relationship to any form, hence its class
is not inside Form1, it is in a separate file, say Person.h
Form1 and Form2 are ways to interact with Person, they are separate classes in separate
files.
Doing so, both Form1 and Form2 need to know about Person, but not about each other.
|
|
|
|
|
MUCH more condensed and readable than what I said.
I want to die like my Grandfather.
Peaceful, Sleeping.
Not screaming like his passengers.
|
|
|
|
|
That is because Luc is the MAN. (congrats on the MVP by the way, Luc!)
It has become appallingly obvious that our technology has exceeded our humanity. - Albert Einstein
|
|
|
|
|
Thanks. I try and help where I can.
|
|
|
|
|
And no code at all, since I don't speak C++ fluently...
|
|
|
|
|
(shaking head)
If you look at what I wrote, it's probably obvious I don't, as well.
I want to die like my Grandfather.
Peaceful, Sleeping.
Not screaming like his passengers.
|
|
|
|
|
RichardM1 wrote: it's probably obvious I don't, as well
I truely can't tell, at least until I pass it to the compiler.
I did not really study your post, we both were replying concurrently.
BTW: you can (and should) preserve formatting by using PRE tags
(CODE tags are good for single-line captions, PRE is useful for multi-line).
|
|
|
|
|
Thank you Sir, you are a scholar and a gentleman.
I want to die like my Grandfather.
Peaceful, Sleeping.
Not screaming like his passengers.
|
|
|
|
|
Had to look that up, the saying was unknown to me. Thank you kindly.
|
|
|
|
|
I dont' have any C++ code. I haven't touched it so long.
|
|
|
|
|
I have C# app whose main window can be hidden (there's a NotifyIcon tray icon to allow it to be shown). In the FormClosing() function I check whether a shutdown is in progress and don't cancel that event if it is. If the PC is not shutting down the form is simply hidden.
Here's the problem: When I logoff/shutdown the PC, the mainforms FormClosing() function does not get called if it is hidden (i.e. in the tray) and thus the app never ends.
If the main form is visible it exits just fine.
I've looked high and low, but am unable to figure out what to trap in order to exit gracefully when the user logs off.
Any ideas/pointers?
Thanks,
- Lutz
|
|
|
|
|
Hi,
have a look at SystemEvents.SessionEnding and SystemEvents.SessionEnded events then.
|
|
|
|
|
|
Actually, it turns out this one was dev error.
So when my form was minimized/hidden to tray, it did in fact get the Form_Closing event. But that method was checking System.Environment.HasShutdownStart() which returned false, even when I was in fact trying to logoff/shutdown.
However, it turns out that the FormClosingEventArgs for the closing handler tells you in the CloseReason why it's wanting to close, so once I removed that call and changed it to see whether e.CloseReasons was CloseReason.WindowsShutDown it worked fine.
The SystemEvent handlers you mentioned only get called once FormClosing allows the form to close. It wasn't getting called before I made the above fix.
Thanks for making me actually sit down and write a test app to see how this works
- Lutz
|
|
|
|
|
Thanks for reporting and clarifying this; I was unaware of the details.
Clutchplate wrote: Thanks for making me actually sit down and write a test app
Upright programming is not good for coder/app stability.
|
|
|
|
|
Hi.
I have a web services and i don't see him wen i create a web reference in my windows application, its in the local host. how I get it?
why i dont see the web services?
thanks.
|
|
|
|
|
Make sure you have compiled the web service on that machine.
|
|
|
|
|
hi guys ;
I have couple of Qustion for whom create User Control using C# I want to create a plug for VS 2008 to read the comment and do the spill checker i used the COM Interoperability form MS word Office I used this Article in MSDN
http://msdn2.microsoft.com/en-us/library/ms173188(VS.80).aspx
but I didn't used the text box I used the rich text box control and add a button to check the comment but my main problem is how to make it read the comment after the "// or /* */ " charater can any body guide me to complete task
and thank you
|
|
|
|
|
I need to hide all open active forms in my application (and be able to bring them back later to their exact state). This is a security function for which there is an external requirement, and I can do nothing to manage.
My first test was to use the Application.OpenForms to iterate through all open forms and then hide them (by setting Visible = false). This gives a problem if I have a modal dialog open at the time - it gets closed (with DialogResult getting set to Cancel). I just want to hide it temporarily, and bring it back later, so this doesn't help.
My second idea was, rather than close the forms, to resize them to 0,0, move them off screen, and remove them from the taskbar. If I remove them from the taskbar, then they disappear from the OpenForms collection, and do not get re-added if I add turn the taskbar back on. This appears to be a "known issue" with using OpenForms.
So, has anyone got any ideas how to achieve this?
If I could iterate through all open forms for my process without using Application.OpenForms (any win32 way?) perhaps I could manipulate the showintaskbar without worrying? Or perhaps there is an alternative way to hide the window and restore it that someone can think of that doesn't result in a model dialog form getting closed rather than just becoming invisable
Best wishes
James
|
|
|
|
|
Here are some ideas:
- you could change the window location to large negatives, without changing size
or visibility;
- you can keep your own list of windows together with their original properties;
- if necessary, you can get a complete list of all windows by using P/Invoke to
win32 functions, as in:
public static ArrayList GetVisibleWindowHandles(bool withChildren) {
list=new ArrayList();
int parm=0;
if (withChildren) parm=1;
LP_User32.EnumWindows(new LP_EnumWindowsProc(CollectVisibleWindows), parm);
log(env.DETAIL1, "There are "+list.Count+" visible windows");
return list;
}
private static bool CollectVisibleWindows(IntPtr hWnd, int lParam) {
if(IsWindowVisible(hWnd)) {
list.Add(hWnd);
if (lParam==1) {
EnumChildWindows(hWnd,
new LP_EnumWindowsProc(CollectVisibleChildWindows), 0);
}
}
return true;
}
[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)]
public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)]
public static extern int EnumChildWindows(IntPtr hParent,
LP_EnumWindowsProc ewp, int lParam);
public delegate bool LP_EnumWindowsProc(IntPtr hWnd, int lParam);
BTW: You may want to use a List instead of an ArrayList.
|
|
|
|
|
Luc
I'll give this a go - you have a callback function defined "CollectVisibleChildWindows" which you haven't given the code for.
The only reason I didn't want to just move to an off-screen location was that the windows would still exist within the taskbar, and (probably) users could interact with them through a right click - to maximise them and bring them back on screen for example. If I could remove them from the taskbar as well then this would be solved.
Best wishes
James
|
|
|
|
|
sorry about that, the stuff is spread over several files here.
private static bool CollectVisibleWindows(IntPtr hWnd, int lParam) {
if(LP_User32.IsWindowVisible(hWnd)) {
list.Add(hWnd);
if (lParam==1) {
EnumChildWindows(hWnd,
new LP_EnumWindowsProc(CollectVisibleChildWindows), 0);
}
}
return true;
}
private static bool CollectVisibleChildWindows(IntPtr hWnd, int lParam) {
if(IsWindowVisible(hWnd)) list.Add(hWnd);
return true;
}
[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)]
public static extern bool IsWindowVisible(IntPtr hWnd);
|
|
|
|
|
I have made some progress with this, but have hit a barrier. My win32 knowledge is probably not good enough
Since hiding a dialog box closes the dialog box, which doesn't allow me to restore state I have looked at moving the windows.
I enumerate through the windows with EnumThreadWindows to get the window handles.
Foreach window:
1. call GetWindowPlacement to get the current details (and store them)
2. change the normal position to off screen
3. call SetWindowPlacement with the showcommand set to SW_RESTORE twice
I have to call SetWindowPlacement to get the window to move properly if it is in a maximised state.
On restore:
I call SetWindowPlacement with the stored details
This is all fine, except the window remains in the taskbar. A user can just right click and move, maximise etc then window to bring it back.
So I need to get it off the task bar - or at very least disable all of these functions.
To remove it from the task bar, I have tried this code to remove the WS_EX_APPWINDOW style and set the WS_EX_TOOLWINDOW style. However, whilst the window changes its style it does not get removed from the taskbar. Any clues?
int istyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
istyle = istyle & (~WS_EX_APPWINDOW);
int lResult = SetWindowLongW(hWnd, GWL_EXSTYLE, istyle);
//istyle = GetWindowLongW(hWnd, GWL_EXSTYLE);
istyle = istyle | WS_EX_TOOLWINDOW;
SetWindowLongW(hWnd, GWL_EXSTYLE, istyle);
Best wishes
James
|
|
|
|