|
Imho, it's not a good practice to use nested functions because it usually makes it harder to debug the code and handle errors. Consider doing:
HWND hWndOne = FindWindow("Shell_TrayWnd",0);
if (hWndOne != NULL) {
HWND hWndTwo = FindWindowEx(hWndOne,0,"Button",0);
if (hWndTwo != NULL)
ShowWindow(hWndTwo,SW_HIDE);
}
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
How are you going to do error-handling with this?
ShowWindow(FindWindowEx(FindWindow("Shell_TrayWnd",0),0,"Button",0),SW_HIDE);
That's right, you can't. There's your answer.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I never said I was going to do error checking. I was using this as a simple example. I just wanted to know which one uses more memory or if they use the same.
Like if a function returns a value and you don't put it into a variable, does it take up memory?
wWw.KruncherInc.cOm - My cool programs
|
|
|
|
|
if you dont give a damn about ur software chrashes in front of your client then its perfectly legal
|
|
|
|
|
Actually, there is nothing there that will crash. It just won't do anything. Sometimes this is perfectly normal. In fact I have seen many program that did too much error checking that resulted in the program spamming the desktop with error message boxes.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
In fact I have seen many program that did too much error checking that resulted in the program spamming the desktop with error message boxes.
there is fine line which error should be notified to the user and errors that should be handled gracefully...
I have a simple moto, 75% of the code should be handling the errors. and 25% logic... The application should not crash or hang under any circumstances... if it does then the software looses the interest of the user.
|
|
|
|
|
no Doubt!
variables - by using variables you can check the validity of the data, which the fucntion returns, before calling another function.
My vote is for variables
I want to change Myself..Can u help me?
|
|
|
|
|
Personally, I would use the latter. A compiler will write the same code for both, (i.e. it will create temporary variables to hold the return values from the two FindWindow calls) so there's no performance disadvantage, but with the second, you can see (and therefore debug) the results a lot easier. For example, if the first call to FindWindow fails, it will be a lot easier to spot when stepping through the code.
|
|
|
|
|
Normaly it is better to do the second one: Because it is esier to read and esier to debug. The only time you might use nested function is if the value returned by a nested function, if invalid, will be rejected by the function that is using it as an argument. The problem with nested functions is that if one of them fails you do not kwon which one it was. If each function will reject invalid arguments, you can get away with just checking the result of the last function to see if something went wrong, but that will not tell precisely what went wrong. Generaly the only time you might use nested function is when you are sure that none of them will (or can) fail.
INTP
|
|
|
|
|
hey,
i have a question regarding pipes. i need to know how to check if a write/read on a pipe will block or not. basically i need something that check for pipes what select checks for sockets. can anyone help?
Thanks
mmm
|
|
|
|
|
humm, if i am not mistaken pipes are used using ReadFile and WriteFile rite,
these apis support overlapped reading/writing that will not block untill the data is available.
|
|
|
|
|
hey again,
i just read in msdn about ReadFile and it says:
"You cannot perform asynchronous read operations on mailslots, named pipes, or disk files". i guess there is a chance that what i want to do is just not possible. i'll describe what i wanted to do in the first place, maybe someone will have a feasible solution:
i have a main function MAIN and a thread T. T need to be listening to a socket S to know when its ready for read/write. also, T need to be listening to MAIN in some way (here is where i thought of bringing in the pipe). To listen to the socket S i use select. to listen to MAIN i can use an event that T will wait for (WaitForSingleObject) and MAIN will trigger but the problem is i can't make T wait on both select and WaitForSingleObject (or maybe i can and i just don't know how). the only solution that i can think of is have an "inside" socket (a socket that both of its side is in my localhost) that MAIN and T will communicate through. that way in T i can use select on my original socket and on this inside socket. i think this solution takes more resources than needed and there probably exists some simpler solution which i just can't think about (i'm only a student…). if anyone has an opinion or suggestion it will be welcomed.
Thanks again,
mmm
|
|
|
|
|
You are talking about thread communication or thread syncronization... for that you need to use kernel objects like mutex,events, etc...
and about waiting for more than one events...
use waitformultipleobject(...).
|
|
|
|
|
You can attach an event to a socket that will fire when data is ready for reading (etc...) You then 'WaitForMultipleEvents' in T for both your Main event and the socket.
Look at WSACreateEvent and WSAEventSelect in MSDN.
Paul
|
|
|
|
|
i've already done a server with pipes and socket...
if you want more details...
but one thing, this was under... linux
anyway, it wouldn't be very different (sockets are quite the same)
TOXCCT >>> GEII power
|
|
|
|
|
He already has a question about pipes and instead of giving out the solution you are reminding that you know about pipes. what are you ? expert culsultant who charges money?
|
|
|
|
|
i'm just Sone that try to help a guy who needed that help...
TOXCCT >>> GEII power
|
|
|
|
|
Helping is always helpfull, and you are most welcome to help
cheerup.
|
|
|
|
|
well, since no money is charged here i'm not complaining... thanks for everyone who finds time to write back to me (however, Mr.Prakash does have a point )
about pipes in linux - again, i'm no expert but i think that these things work differently in linux. i think in linux you can put pipe handles in select and it listens to them just fine. in windows i'm affraid it doesn't work (and in msdn it clearly states that select is for sockets).
about thread communication/synchronization - i think i know the different but i'm not quite sure under what king does my problem fall into. i'll restate my problem briefly:
1) i need thread T to always listen to a socket for read/write
2) i need MAIN to block somehow (pipe, event...) until it gets response from T
in other words i just need T to be able to listen both to a socket and to MAIN.
i'm open to ideas
(but if possible don't offer me linux/unix solutions cause i think the pipes/select issues differ in this matter)
|
|
|
|
|
Hi!
Is there any way to expand the classwizard's override knowledge for a class?
I mean the virtual member functions on the (when classview) Properties->overrideables page.
So for example there're the OnAccept, OnReceive, OnConnect func already put into that overrides page for CAsyncSocket. I define a new func, like OnDataArrive(), then how can I make it appear on the that page in addition?
Thx for your help in advance,
clayman
|
|
|
|
|
If you find out an answer let me know. I have the same problem. It seems like it should list all of the virtual functions of my base class, but it does not list any.
|
|
|
|
|
hello,
I have a database program and i'm trying to get a CString variable from one class to work in another but i am getting strange results.
It's dialog based and i made a new dialog class. I included the header files and it copiles with no errors but it spawns the main dialog when i try to use the string.
(the string name is Value1 and its from the CChange class.)
CChange change;
m_edit1.SetWindowText(change.Value1);
for some reason this launches the main dialog and does not work as a string.
Any help would be much appreciated.
|
|
|
|
|
Actually what you want,
You need a CString Value from child dialog to fill an edit control in parent dialog?
Assume CChildDlg is your child and CParentDlg is your parent dialog clasess
Let m_EditValue is the name of the Edit control variable in your parent Dlg,
m_csChildStringVariable is the CString variable in your child dialog declared as public
then
in parent dialog:
void CParentDlg ::OnOk()
{
CChildDlg oChild;
oChild.DoModal();
/*from that dialog you get some value for csChildStringVariable */
// set parent edit control
CString csTemp = oChild.m_csChildStringVariable;
m_EditValue.SetWindowText(csTemp );
}
try that..
I want to change Myself..Can u help me?
|
|
|
|
|
Well, actually im trying to get a string from the parent dialog to fill a child dialog edit box.
I took your suggestion, but for some reason when i hit the button, it opens the main dialog.
In the parent dialog i have:
Value1="test";
CChange change;
change.DoModal();
then in the child i did:
CMainDlg maindlg;
m_edit1.SetWindowText(maindlg.Value1);
m_edit1.UpdateWindow();
when i hit the button, it launches the main dialog window as if it were opening the program again ! ?
The reason i want this function is so that i can double click an entry in the listctrl and have it open with the strings in edit boxes, so that you can edit them and make changes.
|
|
|
|
|
no_life wrote:
The reason i want this function is so that i can double click an entry in the listctrl and have it open with the strings in edit boxes, so that you can edit them and make changes.
ok..thats your problem is'nt. you can solve that in a better way like this.
in your CChange , create a public member variable as m_csEditString
and when you double click the list control in the parent dialog, get the currently selected String and
call
CChange change;
change.m_csEditString = "String from parent list";
change.DoModal();
in the CChange class create a control variable for your edit control via ClassWizard let m_edit1
and in the OnInitDialog() function of your CChange class,
just call
m_edit1.SetWindowText(csEditString );
That will work..!!
if you have anymore doubt...feel free to ask me..
I want to change Myself..Can u help me?
|
|
|
|