Function to check if CWnd still created

Hi,
I'm looking fur a function to check if a CWnd pointer is still valid,
what means that he window has not been closed.
Thanks,
Markus
0
maka3 (15)
7/20/2004 9:29:07 AM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
973 Views

Similar Articles

[PageSpeed] 55

Hi,

you can try ::IsWindow (HWND)  or CWnd::GetSafeHwnd ()


"maka3" <maka3@punjabi.net> escribi� en el mensaje
news:9f73cf3f.0407200129.62d8a73@posting.google.com...
> Hi,
> I'm looking fur a function to check if a CWnd pointer is still valid,
> what means that he window has not been closed.
> Thanks,
> Markus


0
josema (4)
7/20/2004 11:10:51 AM
That is very difficult. You are faced with two questions here: (a) is the CWnd pointer
valid (very hard) and (b) is the window referenced by the CWnd object valid (very easy).

If the window is closed, under normal conditions the accompanying CWnd * object has also
been "destroyed", that is, the storage referenced by the CWnd * has been released to the
heap, and may either now represent free space, or have been reallocated for another
purpose. Therefore, the pointer is ALWAYS "valid", in that it points to valid storage. The
storage, however, may not be meaningful (there are rare cases in which the storage might
actually be freed back to the OS, but that doesn't happen often enough to matter. You
almost always end up with a valid pointer to meaningless storage). 

Therefore, it is best to code in ways that do not rely on knowing a window pointer is
valid.

The most common context comes up in the case of having to deal with threads, where a
thread wishes to PostMessage to a CWnd *. In this case, the answer is simple: the CWnd *
that is receiving the message is responsible for making sure the thread is shut down
before it allows itself to be closed. If this is your problem, post a followup and I'll go
into the more extensive discussion this requires. 

Otherwise, you should consider it a coding error that you can be holding onto a CWnd * to
a window that could be destroyed out from under you, and you will have to change your
program. There is no way to tell if a CWnd * pointer is valid.

OTOH, if you have a CWnd * you know CAN be valid, but the window can go away...a rare
condition, given the nature of MFC, then you can use ::IsWindow on the m_hWnd member to
see if it is still a window.  There are other tests, for example, CWnd::GetSafeHwnd() can
tell you during startup if a control has been initialized.
				joe

On 20 Jul 2004 02:29:07 -0700, maka3@punjabi.net (maka3) wrote:

>Hi,
>I'm looking fur a function to check if a CWnd pointer is still valid,
>what means that he window has not been closed.
>Thanks,
>Markus

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/21/2004 2:19:33 AM
Try ASSERT_VALID if you want to do it in debug mode. Other suggestions
should work as well.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"maka3" <maka3@punjabi.net> wrote in message
news:9f73cf3f.0407200129.62d8a73@posting.google.com...
> Hi,
> I'm looking fur a function to check if a CWnd pointer is still valid,
> what means that he window has not been closed.
> Thanks,
> Markus


0
ajaykalra (6842)
7/21/2004 2:23:22 AM
Joseph M. Newcomer <newcomer@flounder.com> wrote in message news:<e7krf01ef02l45akhc1kjv3ltrt753tngi@4ax.com>...

> Otherwise, you should consider it a coding error that you can be holding onto a CWnd * to
> a window that could be destroyed out from under you, and you will have to change your
> program. There is no way to tell if a CWnd * pointer is valid.

Hi Joseph,
Thanks for your detailed answer. I create a new window with
pMainFrame->CreateNewChild() and save a pointer to it. In the render
loop I draw to it with DirectDraw.
I could get in the WindowProc and draw in WM_PAINT. But how can I jump
in the Proc
with only having the pointer?
I'm very new to MFC and started programming with C#, where it is a
common way to call for example "Form.Created".
0
maka3 (15)
7/21/2004 11:21:21 AM
I've not used DirectAnything, so I can't answer that specific question. But if you create
the child window, you know when you are going to destroy it; all you have to do is make
sure you don't try to use it before it is created (e.g., set the pointer to NULL) and
don't try to use it after it is destroyed (which a correct program should be able to deal
with). 
				joe

On 21 Jul 2004 04:21:21 -0700, maka3@punjabi.net (maka3) wrote:

>Joseph M. Newcomer <newcomer@flounder.com> wrote in message news:<e7krf01ef02l45akhc1kjv3ltrt753tngi@4ax.com>...
>
>> Otherwise, you should consider it a coding error that you can be holding onto a CWnd * to
>> a window that could be destroyed out from under you, and you will have to change your
>> program. There is no way to tell if a CWnd * pointer is valid.
>
>Hi Joseph,
>Thanks for your detailed answer. I create a new window with
>pMainFrame->CreateNewChild() and save a pointer to it. In the render
>loop I draw to it with DirectDraw.
>I could get in the WindowProc and draw in WM_PAINT. But how can I jump
>in the Proc
>with only having the pointer?
>I'm very new to MFC and started programming with C#, where it is a
>common way to call for example "Form.Created".

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
7/21/2004 10:56:15 PM
Reply:

Similar Artilces:

ROUND Function with other function
Hi, I have this formula: =IF(R8>0,CONCATENATE("+",R8),R8) and the results shows me for example: +11.6 but what I really want t show is +12. I've been trying to put the "Round" function at a few places in th formula but it doesn't work. The closest I got was with this formula: =ROUND(IF(R8>0,CONCATENATE("+",R8),R8),0) where it showed me 12, without the "+" sign before.... Can anyone help me ? Thank -- Outapi ----------------------------------------------------------------------- Outapin's Profile: http://www.excelforum.com/member...

Returning a range from an inner function
I have a range of data, which has had the DOLLAR() function performed on it. I would like to get the total of this range using the SUM() function. doing SUM(F1:F4) will not work, so I need to convert the data into values that will work. The VALUE() function is perfect for converting the data into values that will work for SUM(), but the formula SUM(VALUE(F1:F4)) does not work because VALUE() will not accept a range as a parameter (and also does not return a range). I need to perform the VALUE() function on each cell before submitting it to SUM(). There must be some way to do this, cons...

JustifyString function problem
Hi, I'm using the "JustifyString" function (from Stephan Lebans) to right justify three columns in a ListBox. Two of them are working fine ... one's a simple number (long integer) and the other's currency. The third causes an Access 2003 crash! That third column is a long integer which is a link to the autonumber field in another table. Both tables are in the query as I need columns from both tables in the ListBox. If I change the JustifyString to reference the autonumber field in the other table, I still get an Access crash. I didn't review the Access er...

How do I create custom postcards in Word 2007?
I want to create my own postcards using the right size and type of paper for mailing. This depends entirely on your printer. Can it handle the heavy weight of card used in postcards, and can it handle the unusual size of a postcard? On Apr 18, 2:54=A0pm, Create Custom Postcards <Create Custom Postca...@discussions.microsoft.com> wrote: > I want to create my own postcards using the right size and type of paper = for > mailing. Perhaps the easiest way to start is to get some Avery (or similar) postcard stock, which will have two postcards per sheet. Then find the a...

Check Box in Excel #2
Dear All, I need to create a check box in excel so that when I click on the box, a tick mark should come in the box. Can anyone please help. Regards, Jaipal You can show the Forms toolbar and click on the checkbox and draw it where you want it on the worksheet. jaipal1@gmail.com wrote: > > Dear All, > > I need to create a check box in excel so that when I click on the box, > a tick mark should come in the box. > > Can anyone please help. > > Regards, > Jaipal -- Dave Peterson Hi, Please check your other post for multiple answers. We discourage multi...

How do I check to see if still internet / ftp connected
I am using wininet library to download data from the internet. I am using the CInternetSession class and the CFtpConnection class to perform ftp. My question is I would like to know how can I check to see ofthe CInternetSession instance one used is still connected to the internet, and how to check to see if the CFtpConnection instance that is till connected to an ftp site? Are there simple function I can call on each instance to see if each is still connected? Thanks Steve Sun_water_snow@hotmail.com is this helpful ...... CInternetSession::OnStatusCallback "steve" <ste...

automating functions
I am a complete novice at CRM 1.2, but want to be able to create, for example, a workflow process that will monitor the CSR's and the queues and automatically assign a new case to the least busy CSR. Any input would be appreciated. Thanks in advance Jim Please tell me what I would have to do and with what tools in order to create such a workflow process. "jmb" wrote: > I am a complete novice at CRM 1.2, but want to be able to create, for > example, a workflow process that will monitor the CSR's and the queues and > automatically assign a new case to the lea...

Pivot Table Creating New Columns that Subtract Two Existing Columns
I have a pivot table that has rows for account numbers and columns that represent months. The data section has the year to date amount for each account number. Is there a way to create a new column that subtracts one months year to date value from the previous month year to date value in order to come up with the monthly value? Also, is it possible to have this only apply to certain rows? For instance, the balance sheet accounts are year to date amounts but income statement accounts are monthly amounts. Any help or advice is appreciated. One way: Click on one of your months. Then, go to...

Returning a CHAR[] from a function
I have the following function that returns the path of where the program was run from. However I cant seem to return the butter as a CHAR. The code works if I use it in a procedure but not where I need to return the variable CHAR buffer. char CAutoRunDlg::GetProgramPath(void) { char buffer[_MAX_PATH]; //declares maimum path //opens window maximized //_getcwd(,)gets the current working directory // #include <direct.h> //needed for current working directory /* Get the current working directory: */ if( _getcwd( buffer, _MAX_PATH ) == NULL ) perror( "_getcwd error" )...

Downloads checking account information into my Money 2006 Savings
I purchased and installed Money 2006 today. I have a problem. Everytime I import from my internet checking. It puts it into my Money savings account. Any way I can redirect the imported information into my checking file?-- Grasshopper In microsoft.public.money, New Money 2006 user wrote: >I purchased and installed Money 2006 today. I have a problem. Everytime I >import from my internet checking. It puts it into my Money savings account. >Any way I can redirect the imported information into my checking file? Is the problem you have the one described in http://support.microsoft....

Voided payables checks
A payables check that is voided today for a check written in a prior month should stay in the bank reconciliation until the month(date) that the void posts. If you have prior month bank reconciliations to do the check will not be in bank reconciliation but the check amount will stil be deducted from general ledger. This difference may be very difficult to find if this check goes back a few months. The only thing you can do now is to manually keep track of all voided checks. Thanks for the suggestion. This feature was added in the last release (version 9) of Microsoft Dynamics GP. T...

Complex functions
Hi All, Suppose you have a very complex and long function that is also subject to a condition, then you will/can have something like: =if(condition(complex function), complex function, other complex function) It can have more lines in the formula bar, so readability below 0 Kelvin. Is there a way to 'name' a function? =If(condition(myfunc = complex function), myfunc, other complex function) With kind regards, JP Yes you can put a formula into an Excel Name (the same as you can give a range an Excel Name. Very powerful it can be too. Do a Google fo...

Turning Off Error Reporting using API Functions and VB
We want to automatically turn off the error reporting options using Windows API functions for the following functions area Click on Start, Settings, Control Panel, System, the Advanced tab and Error Reporting (at the bottom of the screen), which launches the Error Reporting screen. Another way to get to that screen: Open My Computer, right-click on Properties, click on Advanced tab and Error Reporting. Any assistance would be welcome. It's not a program's call. It's the user's decision. --=20 -------------------------------------------------------------------------= --...

Match Function
Hi, I have put together a spreadsheet to find codes, states, descriptions. It finds the data by dates. Columns are: Dates, Codes, States, Descriptions If I put in a date it matches the code, state and description. My problem is that if I have 2 dates that are the same it will only match the first date it can find. What kind of formula do I need so that it will output the second or third date data. Thanks for your help. If you need a copy of the spreadsheet please let me know. How many rows of data do you have? -- Biff Microsoft Excel MVP "Melanie" <Melanie@discussio...

Obtain MICROSOFT and CISCO Certificaitons Without Exams(Pay After Check Results)100% Passing Gaurantee
Get Microsoft...Cisco....Comptia.....Oracle......Solaris......Certificaitons Without Exam.......P{ay After Check Result.......100% Passing Gaurantee In First Attempt.......Need Not Tto Give Exams By Urself I m going to tell you the fastest way to get MICROSOFT,CISCO,COMPTIA,ORACLE,SOLAIS certified without efforts...... friends i have five vue and prometric testing sites here in INDIA.......so, i will do the exams on the behalf of the candidates, make them pass and charge some extra amount from them......... see i need ur some details then i will book ur exam on my testing site, make u pas...

If Function Function
okay. So I am trying to workout a formula to compute a commision earning. Basically, if X amount of new business is made, then X*Y (corresponding Commision rate percentage), but if new business =<X, then X*Y (Commision rate percentage that is true). Problem is, it's super confusing...anyone have any suggestions? See if this helps: http://mcgimpsey.com/excel/variablerate.html -- Biff Microsoft Excel MVP "aetejada" <aetejada@discussions.microsoft.com> wrote in message news:AA4E55F7-9435-4BB6-837A-416A59BB72A0@microsoft.com... > okay. So I am...

DateDiff function throwing error in Where clause
I have a set of queries that generate dates and want to use DateDiff to select those records with certain dates are greater than others. The following clause keeps giving me an incompatible data type error: WHERE DateDiff('d',[From date],[DatumStvoreni])>0 I have the exact expression in the SELECT clause and it show positive and negative integers just fine, but when I add this test, I get the error. There are no bad values in the dataset, I've looked, and when I export the DateDiff column to a temp table and run a query on that, it works fine. Only when I use t...

Creating a dynamic IF statement
I have data in two sheets. I want to create an IF statement in the second sheet that has the ability to scan the first sheet for a value. If it finds a match to a value in the second sheet, deposit the value into the corresponding cells of sheet two. My example: Sheet 1 User B 12/10 User C 12/15 Sheet 2 User A User B In this example, I will have the IF statement in column B of Sheet 2. I want the IF statement to scan column A in sheet 1 for matches to column A of sheet 2. If it finds a match, place the corresponding value in column B (in this case, it wou...

Create Org. Problem
I want to add a new organization to my enteprise server. After i go through the create organization wizard, the new company shows a pending status. After I click on refresh it disappears. How can i resolve this issue?? Hi, I have had a similar problem (in my case though the wizard told me that the creation of the new org. failed...) and it seem to have appeared after applying RollUp4. The problem seems to be that the wizard can't add new users to the AD OU, so you might have to turn of this feature. You can turn it off by changing the reg entry "AutoGroupManagementOff"...

Outlook 2002 Change Password function
I want users to be able to change password from the Outlook Login Page, but it does noet seem to work. Outlook 2002 Sp1 and Windows Server 2003 (AD) and Exchange 2003 SP1 Important: Outlook client is not member of the domain... There are not many Microsoft Articles about this. Anyone? -- Regards, Menko den Ouden Netherlands Menko den Ouden schreef in deze nieuwsgroep op 23-6-2005 15:28: > I want users to be able to change password from the Outlook Login Page, but > it does noet seem to work. > > Outlook 2002 Sp1 and Windows Server 2003 (AD) and Exchange 2003 SP1 > ...

timing a function
Good Morning All, I've writen an MFC C++ application, under VC++6.0 . How can I check how much time it takes for a specific function to complete? I need to know how many miliseconds one of my function call takes. Thanks very much in advance, Dudu Arbel If your accuracy requirement is in ms - use GetTickCount. -- Regards, Nish [VC++ MVP] http://www.voidnish.com http://blog.voidnish.com "dududuil" <dududuil@discussions.microsoft.com> wrote in message news:C0167B90-33D2-4A4F-A73D-DC4EBEF81946@microsoft.com... > Good Morning All, > > I've writen an MFC C++ ...

Creating Profiles
For some reason, I just cannot work out how to create profiles. I'm using Win 98, Outlook 2002, have gone into control panel, Mail, added three profiles and ticked "When Starting Microsoft Outlook, use this profile: Prompt for a profile to be used" But when I open Outlook it only goes to my main profile. Am I confused as to what Outlook can do, is the same as Outlook Express, where you can have three profiles, choose which one to use, and all email goes to the correct/different email inbox, all folders are different depending on what each different profile user has set ...

Check box on continuous form
I have a continuous form listing available parts. I need to be able to select a part from the list using a check box (or something that will give a true if selected). I tried an unbound check box, but when clicked, it selects all of the records in the form instead of only the one record. Am I missing a setting? or what can I do to create this selection capability. (which I am then using code to complete the action I need) Thanks Sue On Dec 19, 1:13 pm, Design by Sue <Designby...@discussions.microsoft.com> wrote: > I have a continuous form listing available parts. I need to...

Charts created in Excel 2003 are not showing up in excel 2007
I have several charts that are displayed as their on worksheets in excel 03 but don't show up in excel 07 how can i fix it so that these charts will display? "RLang07" wrote: > I have several charts that are displayed as their on worksheets in excel 03 > but don't show up in excel 07 how can i fix it so that these charts will > display? I had this exact problem when I upgraded from Excel 2003 to Excel 2007 on my Vista (Home Premium) system. I couldn't work out what the problem was and had given up trying to solve it... However, I somehow managed to fix...

fully depreciated Fixed assets still have book value
We had some assets that were imported in at incorrect life. These assets are now showing the fully depreciated flag of Yes but still have a net book value (we use SLM for depreciation). How do I book the remaining depreciation for these assets? I had a client that had this problem because they hadn't calculated the depreciation correctly in Excel before we imported the assets. I believe what we did to correct the situation was to just change a depreciation sensitive value on the "Book" record and then change it back. This caused the application to recalculate the deprec...