|
Why don't you just add a member function that creates a formatted string containing the structures's data? That way, you only have to write code once and call it when needed.
struct MYSTRUCT
{
int nMyInt;
double dMyDouble;
CString sMyString;
CString GetDataString(CString sVarName)
{
CString sData;
sData.Format("Contents of %s\n"
" nMyInt = %d\n"
" dMyDouble = %lf\n"
" sMyString = %s",
sVarName, nMyInt, dMyDouble, sMyString);
return sData;
};
};
Instead of writing a function that returns a value, you could make the function set an additional value in the struct, but that would make the struct variable use more memory.
struct MYSTRUCT
{
int nMyInt;
double dMyDouble;
CString sMyString;
CString sDataString;
void SetDataString(CString sVarName)
{
sDataString.Format("Contents of %s\n"
" nMyInt = %d\n"
" dMyDouble = %lf\n"
" sMyString = %s",
sVarName, nMyInt, dMyDouble, sMyString);
};
};
At this point, it may be better to write a real live class instead of using a struct, but since I don't know your requirements, that's a call you'll have to make.
Of course, you could just write a global external function to do all that as well.
So many choices, so little time...
|
|
|
|
|
I am using Micrisoft Visual C++ 6.0 compiler in Windows 2000 and I keep getting problems. It sometimes says 'File being used by another process' etc.
Sometimes it even deletes the CPP file when working in the Header. Does anyone know anything about this..
This is causing a lot of probs for me
Thank in advance.
|
|
|
|
|
Hello
How can I get version of MDAC installed on my comp?
Ernst
|
|
|
|
|
file version of "X:\Program files\Common Files\System\ado\msado15.dll"
|
|
|
|
|
I am currently working on a control system application and want to change the priority of the application on starting (dialog based). I could not find any way other than CreateProcess (which is not being used) to change the priority of the process.
Pease guide me with the same (a small example shall be very much helpful).
thanks in advance,
-------------------------------------------
Dashmesh A. Singh
Tata Consultancy Services,
INDIA
e-mail: visions_next@yahoo.co.uk
dashmesha_singh@tcscal.co.in
|
|
|
|
|
|
Thanks Tomasz for your help.
I was able to solve the problem with your help.
//To Set the Priority of the process from within the app
HANDLE hProcess;
DWORD pid;
pid = GetCurrentProcessId();
hProcess = OpenProcess(PROCESS_SET_INFORMATION,true,pid);
if(hProcess == 0)
AfxMessageBox("Invalid Process handle");
else
{
SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS);
CloseHandle(hProcess);
}
-------------------------------------------
Dashmesh A. Singh
Tata Consultancy Services,
INDIA
e-mail: visions_next@yahoo.co.uk
dashmesha_singh@tcscal.co.in
|
|
|
|
|
Hi,
What is parity in modem setting ?
For example in modem setting: 9600,n,8,1
In this setting i don't use of parity, but if i use of it, what will happend ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
When using 7 bit transfers, you have an eighth bit that can be used for a parity check. The sender can set the bit according to whether the number of bits in the data part of the byte is odd or even. This allows a simple sanity check on the receiving side.
Both sides need to agree on the parity setting (high bit signals odd or high bit signals even), or you'll have problems. Typically, a receiver with 8,n,1 will see a senders 7,E,1 data as partial garbage, since it will be getting some chars with 128 added to them, and some without.
|
|
|
|
|
I'm sure this has already been answered around here somewhere, but I can't find it.
I'll preface this with telling you that I am a long-time VB programmer (amateur) who is
learning VC just for fun.
I want a program with menu and toolbars with multiple different dialogs within it --
i.e. an MDI with multiple child dialogs (which is a total breeze to set up in VB).
I've got the MDI with a child CFormView OK. But where do I load any additional dialogs?
And for that matter, where exactly is the first dialog view being loaded? -- I've wandered
around in the code and don't see where it is happening. I have fiddled with loading
subdialogs in a dialog-based app, but that's not quite what I'm going for here.
Sub-question is: do I want or need to be using the Doc/View architecture? It seems to me
that I don't, but I'm really new to this (and admittedly don't understand the Doc/View
architecture yet). The program will be accessing a MS Jet database (but I don't mind
handling the DB access myself).
Thanks in advance for any suggestions/help.
David.
|
|
|
|
|
I found the info I needed in a book.
(Essential Visual C++ by Mickey Williams, SAMS publishing -- in case you are curious).
|
|
|
|
|
Hi,
That would be interesting for me, since I'm facing the same problem. I tried to find this book here in Brazil but unfortunatelly it will take too long to get it by bying from Amazon or other place.
I'd like to know how to implement this, if you could send me something I'd really apreciate that.
My email is crercio@osite.com.br
Thanks a lot.
Crercio O. Silva
|
|
|
|
|
I'm still learning MFC,
I want to be able to have the program read the PCs regional settings for the language and then use the approriate string table.
|
|
|
|
|
You must make dlls with the resources for each idiom
Then into the program you set the source of the resources with void AfxSetResourceHandle.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Let's say you know for sure what a process's ID is. How would you go about getting a window handle (hwnd) from that process ID? Thanks in advance
Sincerely,
Kanoo
|
|
|
|
|
The thing is that the process can have any number of windows open.
The only thing that comes to mind is that you could walk the window list and compare the process id's of all parent windows to the process id that you have.
It's a bit rough but here's an idea. Note, the I haven't tried it myself.
void GetProcessWindows(DWORD dwProcID)
{
DWORD dwWndProcId;
HWND hwndDesktop, hwndParent;
// start with the desktop
// all parent windows will be a child of the dekstop
hwndDesktop = GetDesktopWindow();
// get first parent window
hwndParent = GetWindow(hwndDesktop, GW_CHILD);
// go through this and all subsequent parent windows comparing their
// process id's with the one we are seeking info on
while(hwndParent) {
GetWindowThreadProcessId(hwndParent, &dwWndProcId);
// does window handle belong to the process we are checking?
if(dwWndProcId == dwProcID) {
// report the handle (or do something meaningful)
TRACE("Process window handle = %08x\n", dwWndProcId);
}
hwndParent = GetWindow(hwndDesktop, GW_HWNDNEXT);
}
}
|
|
|
|
|
I agree with the approach, but not sure app windows will show up as children of the desktop. (er, no I haven't tried it either).
I'd loop by enumerating all the top level windows, starting with HWND hwnd = ::GetTopWindow(NULL); and continuing with hwnd = ::GetNextWindow(hwnd, GW_HWNDNEXT);.
Then, as you say, comparing the process IDs found. The problem remains that apps tend to have more than one top level window, which means more work if you want the 'main' one.
|
|
|
|
|
This is code ripped from one of my apps. I think I got everything.
In the header file, I have this:
const int UWM_FOUNDHWNDADMIN = WM_APP + 1;
class CDlg : public CDialog
{
afx_msg LRESULT OnFoundHwnd(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
private:
PROCESS_INFORMATION* m_pProcessInfo;
HWND m_hwnd;
void RunComponent();
void GetAppHWnd();
};
static BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam);
In the CPP file, I have this:
void CDlg::RunD2RemoteAdmin()
{
CString sFileName = GetProgramPath();
AddBackSlash(sFileName);
sFileName += "MyProgram.exe";
if (FileExists(sFileName))
{
char cmdLine[1024];
strcpy(cmdLine,(const char*)sFileName);
m_pProcessInfo = new PROCESS_INFORMATION;
if (!m_pProcessInfo)
{
CString sMsg;
sMsg = "Could not allocate memory for component process info (not critical)";
AfxMessageBox(sMsg);
return;
}
STARTUPINFO StartupInfo = {0};
StartupInfo.cb = sizeof(STARTUPINFO);
if (::CreateProcess(NULL, cmdLine, NULL, NULL, FALSE,
0, NULL, NULL, &StartupInfo, m_pProcessInfo))
{
WaitForInputIdle(m_pProcessInfo->hProcess, 15000);
GetAppHWnd();
}
}
else
{
CString sMsg;
sMsg = "Could not find executable component";
AfxMessageBox(sMsg);
}
}
void CDlg::GetAppHWnd()
{
DWORD pid = m_pProcessInfo->dwProcessId;
HANDLE ps = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid);
EnumWindows(EnumWindowsProcGetHwnd, pid);
CloseHandle(ps);
}
LRESULT CDlg::OnFoundHwnd(WPARAM wParam, LPARAM lParam)
{
wParam;
lParam;
m_hwnd = (HWND)wParam;
DWORD dwPID = (DWORD)lParam;
if (dwPID == m_pProcessInfo->dwProcessId)
{
}
else
{
}
return 1L;
}
BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam)
{
CString sTitle;
CWnd::FromHandle(hwnd)->GetWindowText(sTitle);
DWORD wndPid;
::GetWindowThreadProcessId(hwnd, &wndPid);
if (wndPid == (DWORD)lParam && !sTitle.IsEmpty())
{
if (sTitle.Find("Remote Admin Monitor") >= 0)
{
theApp.m_pMainWnd->SendMessage(UWM_FOUNDHWNDADMIN, (WPARAM)hwnd, lParam);
}
return FALSE;
}
else
{
return TRUE;
}
}
|
|
|
|
|
I'm using a CListCtrl to display logged data and it can come into the view
quickly. The scroll bar however will jump to the previously highlighted postision or to the 0th Sel each time new data comes in. I would like for the
scroll bar to default to the 0th position but remain where the user left it
if its position changed.
Thankz,
Tim
|
|
|
|
|
Firstly, thanks for all who gave me some ideas in the previous posting. I know it is because there is some problem in GDI resource or something.
Here is the problem...(say again...)
Everything fines in NT...but when i move to Win9x, strange things happened. After the program runs for awhile, fonts change, cannot display colour when i do drawing.....even the Windows system message box font change(i know it because later Windows force me to terminate the program....so u know.....liked some memory problem..)...but everything fines in NT
I didn't use CreateDC. I just use the OnDraw() function provided by MFC in View.cpp file to do drawing(mainly), and i use a GLOBAL CDC pointer to let other file to do drawing too:
CDCPointer->m_hDC = pDC->m_hDC;
CDCPointer->m_hAttribDC = pDC->m_hAttribDC;
And i delete the CDCPointer in the destructor in View.cpp (delete CDCPointer;)
So....i really need a solution...because I need to implement some graphic codes now.
Again...thanks for all giving me advice......thanks alot.!!!!
|
|
|
|
|
What you're describing seems like major GDI resource leak. I'm not sure it's related to your global device context variable. You should get rid of the global variable - just pass CDC pointer as function parameter.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hello:
I built a map<...> in the way showed below. After running program, I do not know if
data was loaded correctly. To verify this, I wanted to use "cout", but I do
not know how to reference, for example, to the content of dMonto[3] that is in
mpCont.
Is there a charitable codeguru soul by there?
Thanks in advance!!!!
#include <iostream>
#include <string>
#include <utility>
#include
using namespace std;
const int tam=10;
struct stTot {
string stLey;
double dMonto[tam];
};
stTot myTot;
map<string, sttot=""> mpCont;
int main()
{
myTot.stLey = "Text one";
for(int i=0; i<tam; i++)
="" mytot.dmonto[i]="i+11;
" mpcont["one"]="myTot;
" map<string,sttot="">::iterator it = mpCont.find("one");
// I want to put the "cout" here
return 0;
}
|
|
|
|
|
The folowing should do the trick;
cout << (*yourIterator).second << endl;
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
So far I've seen two examples using the syntax:
(*iter).second
to look at the content of a map. Is there something
wrong with using the -> operator as in:
iter->second
Thanx
|
|
|
|
|
My STL book ("The C++ Standard Library: A Tutorial and Reference" by Nicolai Josuttis) tells that:In some older environments, operator -> might not work yet for iterators MSVC's STL implementation seems to be an "older environment", using (*iter).member is always safe.
|
|
|
|
|