Solved

How to access Variables in different dialog box

Posted on 2013-06-14
3
281 Views
Last Modified: 2013-06-16
My application is a Dialog box. Within my app, there is a button, which when pressed another dialog appears.

My questions is, am I able to access Global Variables from here, and can I access controls as I normally would?

For instance, from the second dialog, I want to check the contents of an edit field in the first one.

Thank you
0
Comment
Question by:edvinson
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39249102
If you have the window handle and the control IDs, you can just gather or set the data like in your own dialog. E.g.

#define ID_TEXTFIELD 1234 // finding that is the tricky part
HWND hwnd = FindWindow(NULL,_T("Dialog Title"));

TCHAR acText[256];

GetDlgItemText(hwnd,ID_TEXTFIELD,acText,256);

Open in new window

0
 
LVL 1

Author Comment

by:edvinson
ID: 39250888
Ok, let me elaborate a bit...

My main dialog is defined as IDD_DIALOG1

I have another dialog ( which is not shown until a button is pressed ) defined as IDD_DIALOG2

Inside of IDD_DIALOG2 is a textfield, defined as IDC_PRINT.

Question:

How do I retrieve IDC_PRINT from IDD_DIALOG1?

Could I copy the value of IDC_PRINT to a global variable, and simply access it that way from IDD_DIALOG1? If so, how?

Thanks!
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39251347
Just like in the above - if you have the definitions ready (which I assume you have, since both are in your app) all you need is the 2nd dialog's windoe handle:

TCHAR acText[256];

GetDlgItemText(hwndDlg2,IDC_PRINT,acText,256);
                                            

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question