How do you access a public variable from another class?

 I have a public variable which I declare in the myapp.h file:

public:
CSystemTray m_TrayIcon;
 I use it just fine in myapp.cpp but I want to access it from another class.
I don't want to create a new instance of the class I want a handle or a
pointer to the original instance which gets fired off in BOOL
cmyapp::InitInstance(). How do you do this? I've include myapp.h in the .cpp
file that i am trying to use it in. I've tried:

myapp::m_TrayIcon (it says i don't have access to protected member? It's
public)

myapp* app;

app->mymethod (that is stupid since it's a null pointer.)

How am I supposed to call it?

Bill


0
bill (8)
10/1/2003 10:18:09 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
357 Views

Similar Articles

[PageSpeed] 14

"Bill Levis" <bill@voicenet.com> wrote in message
news:%23SvsmnGiDHA.1688@TK2MSFTNGP10.phx.gbl...
> I have a public variable which I declare in the myapp.h file:
>
> public:
> CSystemTray m_TrayIcon;
>  I use it just fine in myapp.cpp but I want to access it from another
class.
> I don't want to create a new instance of the class I want a handle or a
> pointer to the original instance which gets fired off in BOOL
> cmyapp::InitInstance(). How do you do this? I've include myapp.h in the
..cpp
> file that i am trying to use it in. I've tried:
>
> myapp::m_TrayIcon (it says i don't have access to protected member? It's
> public)
>
> myapp* app;
>
> app->mymethod (that is stupid since it's a null pointer.)
>
> How am I supposed to call it?

Not entirely sure what's going on, but see if you can make use of AfxGetApp.

Jeff...


0
jeffp (1712)
10/2/2003 12:27:01 AM
Bill Levis wrote:

>  I have a public variable which I declare in the myapp.h file:
> 
> public:
> CSystemTray m_TrayIcon;
>  I use it just fine in myapp.cpp but I want to access it from another class.
> I don't want to create a new instance of the class I want a handle or a
> pointer to the original instance which gets fired off in BOOL
> cmyapp::InitInstance(). How do you do this? I've include myapp.h in the .cpp
> file that i am trying to use it in. I've tried:
> 
> myapp::m_TrayIcon (it says i don't have access to protected member? It's
> public)
> 
> myapp* app;
> 
> app->mymethod (that is stupid since it's a null pointer.)
> 
> How am I supposed to call it?
> 
> Bill
> 
> 

If the wizard did not do it already, put this line somewhere before you 
want to access the variable.  (Putting it at the end of app.h is a good 
place:)

   extern cmyapp theApp;

Now you can access your variable with:

   theApp.m_TrayIcon
or,
   theApp.mymethod();

-- 
Scott McPhillips [VC++ MVP]

0
scottmcp (342)
10/2/2003 2:26:11 AM
Thanks Jeff, that did the trick. I ended up casting it like:
((myapp*)AfxGetApp())->m_TrayIcon

Bill
"Jeff Partch" <jeffp@mvps.org> wrote in message
news:%239ZGSwHiDHA.1680@TK2MSFTNGP12.phx.gbl...
>
> "Bill Levis" <bill@voicenet.com> wrote in message
> news:%23SvsmnGiDHA.1688@TK2MSFTNGP10.phx.gbl...
> > I have a public variable which I declare in the myapp.h file:
> >
> > public:
> > CSystemTray m_TrayIcon;
> >  I use it just fine in myapp.cpp but I want to access it from another
> class.
> > I don't want to create a new instance of the class I want a handle or a
> > pointer to the original instance which gets fired off in BOOL
> > cmyapp::InitInstance(). How do you do this? I've include myapp.h in the
> .cpp
> > file that i am trying to use it in. I've tried:
> >
> > myapp::m_TrayIcon (it says i don't have access to protected member? It's
> > public)
> >
> > myapp* app;
> >
> > app->mymethod (that is stupid since it's a null pointer.)
> >
> > How am I supposed to call it?
>
> Not entirely sure what's going on, but see if you can make use of
AfxGetApp.
>
> Jeff...
>
>


0
billl1 (2)
10/2/2003 10:03:46 AM
Reply:

Similar Artilces:

Outlook Web Access AutoSignature
I would like to know if it's possible to have autosignature in Outlook Web Access, and if so how to implement it. If anyone can help, it would be greatly apreciated. Thank You. It depends on the version of Exchange - Outlook Web Access is a function of Exchange, not Outlook. Exchange 2003 does this natively, previous versions may have a third party add-in that will allow users to do this. For better information, post in an exchange group such as microsoft.public.exchange.admin. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due t...

Restricting access to note attachments
Hi all, is there a way to restrict access to attachments on notes to specified users. I know we can, using the Security Roles, define who can and can't read/ write the notes fields but we would like our users to be able to view the note, but not open the attachment(s) unless they are the owner of that note (or at least in the business unit, etc.). I know this could be done for Word/ Excel files in Office (Password protection) but are looking for something more encompassing for all attachments inside CRM. Thanks, -- Matt Pring On Oct 21, 3:54=A0pm, Matt Pring <MattPr...@discus...

Public Folders - Using as a mailbox
Hi I have set up a public folder and have set it up so the people can read and reply to the emails, and tell when others have read them. What is the best way to track the replies? CC them to the public folder? Any other ideas? Many thanks in advance William ...

Access 2003 and Access 2007 Synchronization
I'm setting up a new business relationship with a company in Portugal. They use Access 2003. I have just bought MS Office Professional 2007 (with Access 2007). Our plan is that they will send, once a month or so, their Access db then we will update and add to that db and then return it after another month or so. There probably won't be a lot of updates on our end so the monthly cycle should work. After they synchronize, they will send a new version of the db and we will start over. My goal is to keep everything as simple as possible partially because I don't know how skillf...

Excel Row to Access Columns
Hi, I have a single row in Excel with a lot of data, what I need to do is move that to a column in Access. I need some way to automate that. I know the easiest way to do that would to just transpose it in excel and then import in access.But I cant do that as I just get that excel file with one row and I need some way to automate the process in Access. thanks m -- mk389 ------------------------------------------------------------------------ mk389's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=15272 View this thread: http://www.excelforum.com/showthread.php?...

Help displaying a random record in a form--Access newbie
Hello, I am new to Access, so if anyone can help me, please assume I know absolutely nothing! I currently have a table with two columns, ID and CHORE. In each row, the ID number corresponds to a chore that I have entered. I would like to create a form with a button and a text field such that when I press the button, a random chore is displayed in the text field (supposed to make chores more "fun" for my son). There is no need to remove this record from future clicks (the same record can come up over and over without any problem for me) Can anyone explain to me (in pai...

Access
Hi My form takes a few moments to load up as it is fairly substantial SQL statement is there a way to get something to display a graphic or 'loading...' message to appear why it calculate the contents? Steve ...

Public variable
using vba in excell how do I create a variable in one work sheet so that it can be seen by all the other worksheets in the same workbook. I have tried public x as interger but this does not seem to work. -- Jack Allen You need to declare the variable in a regular code module, NOT the worksheet's code module. However, if you do declare it in a sheet's code module, you can refer to it with the worksheet's codename as a qualifier. E.g., [in Sheet1] Public MyVar As Long [in Sheet2] Sheet1.MyVar = 123 -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulti...

Public folder contents keep deleting automatically
I am using one Exchange 2003 Enterprise back end server and one Exchange 2003 Standard front end server. I have tried to change the Age Limit from 0 to any larger numbers, but the public folder contents just keep deleting automatically after a certain period. Do you know the reason and any solutions so that the public folder contents can be kept permanently? Thanks. Let me clarify my problem, I mean no matter how many days I entered in Age Limit, the public folder contents would be deleted automatically after around 7 days. How can I disable this automatic deletion. Thanks. "B...

access mail on WEB
Is there a way i can check emails from exchanger server 5.5 from an internet browser. I have Exchange 5.5 in win NT 4.0. Thanks! Yes - install OWA (Outlook Web Access) and open up the needed ports in your firewall (80 for http; better to use SSL and port 443 instead). disk0nek wrote: > Is there a way i can check emails from exchanger server > 5.5 from an internet browser. > > I have Exchange 5.5 in win NT 4.0. > > Thanks! ...

access or mount mirrored hard disks
Hi, is it possible to access a mirrored harddrive? or mount the mirrored volume by using api or mfc commands? Thank you in advance Wimpi ...

can you make one worksheet update another
I have two similar worksheets within the same workbook. One sheet is sorted by name and the other sheet is sorted by a date for a speicfic name. Is there a way to change the date on the sheet, sorted by name, and that will automatically find the name on the other sheet(sorted by date) and change the date to the second sheet? Jaime, The normal way is to have one table, and sort it as needed when needed. -- Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------------------- "Jaime S." <Jaime S.@discussions.microsoft.com> wrote in mess...

Access Database In Great Plains
I was wondering if anyone knew how to have the databases that are stored in access transfered over to great plains. I'm current running version 8.0 any help would be greatful. thanks Search Customer Source for integration Manager. MS Access databases can be used as a data source. Vincev "jake" wrote: > I was wondering if anyone knew how to have the databases that are > stored in access transfered over to great plains. I'm current running > version 8.0 any help would be greatful. thanks > > Hi Jake, Is this something you need to do regularly or is it ...

CRM v4 Accessibility Improvements
Hi all: Does anyone know if any improvements have been med to CRM v4 in the area of accessibility for handicapped users? One of my customers has a user who is blind and they need to make the software accessible to him. Thanks in advance for any and all help. John. Hi John, We have added following Accessibility features in CRM 4.0 : 1) High Contrast Mode (Tools --> Options --> General Tab --> Enable high contrast settings) 2) All the Form input elements have <LABEL FOR> to aid in screen readers. 3) All the Images have a ALT tag (for non text elements) etc. Thanks! Ma...

Upsizing Access to SQL Server 2000
Hello, I am new to SQL Server. I am trying to use the Database upsizing wizard to upsize a Access 2000 database into SQL Server 2000. They are both on the same machine (running Win 03 Server). I cannot connect to the SQL Server. Error as below: Connection failed: SQLState: '01000' SQL Server Error: 14 [Microsoft][ODBC SQL Server Driver][Shared Memory] ConnectionOpen(Invalid Instance()). SQLState: '08001' SQL Server Error: 14 [Microsoft][ODBC SQL Server Driver][Shared Memory]Invalid connection. ...

Hide Rows in one W/S Based on a cell value in Another W/S
Hide Rows in one W/S Based on a cell value in Another W/S I have the following code in an excel spreadsheet (see below). The code correctly hides the rows when C98 in one worksheet = "Dog" but when C98 does not = "Dog" it does not unhide the cells on Sheet Blue. Why? Select Case UCase(Range("C98").Value) Case "Dog" Sheets("Blue").Rows("94:113").EntireRow.Hidden = False Case Else Sheets("Blue").Rows("94:113").EntireRow.Hidden = True End Select Maybe your have your true/false mixed up -- Don Guillett SalesAid ...

Outlook Web Access #19
We have have OWA at my work and I would like to configure Outlook 2003 to synchronize with my desktop at work, is this possible Thanks B ...

Public Folders on 2nd server through OWA #2
HI I'm reposting it with new information. A client is running two exchange 2000 SP3 servers. One for mailboxes/outlook web access and 2nd sever dedicated for public folders. None of the servers is designated as front end server. Users can access mail through OWA using http://exchange.domain.com fine but when they tries to access public folders on the second server the browser points to http://server2.domain.com/public/foldername which is not accessible from outside. 2nd exchange server hosting pubic folders does have IIS installed and within LAN i can acess public folders on second se...

Queue Data to another thread
Hi, I have two threads thread1 and thread2. Thread1 will give queue some data so that Thread2 will process the queued data. What mechanisms are available in c# for doing this? Thanks! Maanu wrote: > Hi, > > I have two threads thread1 and thread2. Thread1 will give queue some data so > that Thread2 will process the queued data. > > What mechanisms are available in c# for doing this? There is nothing built-in per se. But, a basic implementation will make use of the System.Collections.Generic.Queue<T> class, the Monitor class, and the "lo...

Have a user account accessible to multiple users
I have an issue where there is a user account that has multiple alias emails.(reservations@domain.com, info@domain.com, CustomerService@domain.com) I have an exchange 2003 server. My issue is that i need to have muliple users access these emails so they are never missed. What is the best way to accomplish this? I was thinking a public folder. But i want to know the best way to do this? On Sat, 12 Jun 2010 21:37:04 -0500, "Dan V" <dvalenti54athotmail.com> wrote: >I have an issue where there is a user account that has multiple alias >emails.(reservati...

Going offline without write access to registry
I suggest that POS doesn't go offline if it can't write into registry, displaying a message box instead telling that it couldn't access the registry. What happens if the POS machine goes offline without having access to edit the registry? This typically happen when the user is a normal user (not a power user) 1. The POS application will try to connect to the server main database within the pre-configured ‘Connect Timeout’ in the RMS Administrator (Typically 15 seconds) 2. The application will then try to connect to the pre-defined offline database (which is usually stored loc...

Is there away to link something on one page to another?
Hello i was wondering if anyone could help me. Im doing a project for my NVQ4 course and before i can start i would like to know if there is anyway that using excel you can type one thing say on sheet 1 but link it so it comes on automacially on say sheet 4? Many thanks for all replies! Nickle 3 methods to choose from. 1. On sheet 4 select a cell and enter an = sign. Switch to sheet 1 and select the cell to link. Hit ENTER key. 2. In cell on sheet 4 enter =sheet1!cellref 3. Select a cell on sheet 1 and copy then switch to sheet 4 and select a cell then Paste Special>...

Access 2000 problem if opened with Access 2007
Dear all, I'm running Access 2000 MDE in Access 2007. I find several header-details form (such as invoice transaction), the details form is displayed as white box without any record displayed. Is there any solution for this matter ? Thanks. Chlaris. you need to move to Access Data Projects if you want a reliable, predictable environment "Chlaris" <chlarrissa_nospam@yahoo.com> wrote in message news:ON0rS1NsHHA.3884@TK2MSFTNGP04.phx.gbl... > Dear all, > > I'm running Access 2000 MDE in Access 2007. I find several header-details > form (such as inv...

Accounting with Ms Access
Hello all I have been working on a database for are small retail Tile company (we do everything by pen and paper now). I have been able to setup a working Orders/Invoice table and forms, CreditMemo table and forms, and PurchaseOrder table and forms all based on the Northwind Sample Database. "Thanks to all the help here". I have been searching for a sample database with accounting. With A/R, A/P, Billing Statements and so on. I am not a programmer or accountant so the chance of me doing something wrong is pretty good. I am hoping that someone has a add-in MsAccess database for ...

BP3 Site Settings access
I've installed BP3 on web server as domain admin, with sep. SQL 2005 server for SPS and GP databases. On SQL2005 have given BusinessPortalUser full db rights. Site admin is sts_user, with domain admin rights in AD. When login to BP3 Home Page from domain admin, most features work 100%. However on Site Settings I get "the server (server) at Digest requires a username and password". Cannot login as domain admin, continually asks for username / pwd. When login as sts_user, Site Settings Center displays, with Registered Users section shows as below. Also cannot go to Users / Site...