views:

148

answers:

1

I'm in the process of learning C++. I've created a boilerplate Win32 app within VC++ 2008. I've studied through the code and am ready do do a bit of experimenting. I thought it would be cool to print all the windows messages received in the message loop to the form created via the boilerplate code. I for the life of me, can't figure out the method of getting text onto that form. I can't seem to identify and named object that I can use to reference that damn form. The best I can figure is I need to use the handle to reference the form somehow. Still, even if I did know how to reference the form, I'm not sure I know how I would create a label to display the text. Anyway, if someone could just point out what methodology I need to learn to make this happen it would be much appreciated.

Thanks, Donovan

A: 

If you've created a label using resources, use its resource ID and

HWND *pWnd = ::GetDlgItem(mainDialogHwnd, IDC_YOUR_RESOURCE_ID);
::SetWindowText(pWnd, "Your Updated Text");

There are MFC equivalents for those too, should get you in the right direction. Note that posting message loop means lots and lots of information... might not want to do that. Check Spy++ if that's still available and in use today to see how many messages an app gets!

DulabCMS
I guess if you overwrite the message every time it doesn't really matter, just as long as you aren't trying to write it all out and keep it all in a single window object... would consume a lot of memory very quickly
DulabCMS
I noticed the boilerplate code doesn't store the handle for the main window into a global variable. Its only in scope for the creation of the window then gone. I figure I would need to know the handle globaly to make use of your example code right?
Donovan
My last experience with VC++ was with VS 6, so I don't know what exactly the boilerplate code looks like unfortunately... but assuming it's a standard MFC project it probably creates a single, global CWinApp, and creates a CWnd somewhere... the function calls I used were old-style C WinAPI (which MFC wraps), you can get a pointer to an HWND by calling CWnd::GetSafeHwnd(), or you can find the equivalent MFC function for GetDlgItem and SetWindowText, they're probably similarly named, and wrapped in nice MFC classes.
DulabCMS
For my code, you would do something like:HWND *pMainWnd = mainApp.m_pMainWnd->GetSafeHwnd();HWND *pCntrlWnd = ::GetDlgItem(pMainWnd, IDC_YOUR_RESOURCE_ID);//use pCntrlWndAlso you should be able to "bring in" a control into your main window class... from the resource editor right click the control and see if you can 'attach to class' or something, that should create a member variable of the class it's contained in, for instance a CEdit member variable for an edit control.
DulabCMS
I think I see where I might be getting hung up. I'm using VC++ 2008 express. In the express edition you don't get to do resource editing. I would have to create the label by hand.
Donovan