|
Override the PreTranslateMessage virtual function for the dialog class that contains your CEdit-derived control:
BOOL CMyDlg::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
CWnd *pFocus = GetFocus();
if (pFocus == GetDlgItem(RESOURCE_ID_OF_CEDIT_DERIVED_CONTROL))
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
-Sean
----
Shag a Lizard
|
|
|
|
|
Hi, i am beginner to visual c++, and some problems with list control and hope that somebody can help me out. Currently i have made a WebBrowser using active x. I want to capture the navigation when i surf the net with the WebBrowser.
So far i know that
void CIETEST2Dlg::OnNavigateComplete2Explorer1(LPDISPATCH pDisp, VARIANT FAR* URL)
{
CString strURL = m_WebBrowserCtrl.GetLocationURL();
SetDlgItemText(IDC_XXX, strURL); //IDC_XXX whereby is what tool control you use
}
i tried "SetDlgItemText(IDC_EDIT, strURL);" //whereby IDC_EDIT is edit box. And it works but it can display 1 URL at a time...
i tried creating a list control named IDC_LIST but it can't work. Now i have no idea on how to display the captured navigation to display out on the List control.
I hope that sombody could kindly help me with this problem. Thanks a million
-Desperate for help
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
you can't use SetDlgItemText to set the text in a list control. You need to actually add the string to the list box. If you have an actual CListCtrl object you can call the InsertItem function. If you don't have the CListCtrl object already you can also do a
<br />
CListCtrl* pListCtrl = ( CListCtrl* ) GetDlgItem( IDC_LISTCTRLIDGOESHERE );<br />
pListCtrl->InsertItem( );<br />
Hope that helps.
Note: A simpler alternative to a ListCtrl object would be to use a list box. When using a list box you can use a similar method to get it if you don't have CListBox object but the functions are a bit simpler to use ( but provide less functionality ). Either way you can't use SetDlgItemText. You can use AddString() for a CListBox.
Cheers!
Joseph Dempsey
joseph_r_dempsey@yahoo.com
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."
--anonymous
|
|
|
|
|
I see. Thanks Joseph for responsing. I am kind of don't understand what you meant by
//If you have an actual CListCtrl object you can call the InsertItem function. If you don't have the CListCtrl object already you can also do a
CListCtrl* pListCtrl = ( CListCtrl* ) GetDlgItem( IDC_LISTCTRLIDGOESHERE );
pListCtrl->InsertItem( /*Fill This Stuff*/ );
erm, what do you mean by actual CListCtrl object? Sorrie about it. I'm new to visual c++ and seems to have shallow understanding. Thanks again.
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
A control variable mapped to the actual control (i.e., DDX), versus using GetDlgItem(). Here's an example of the former:
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LISTCTRLIDGOESHERE , m_lbMyListControl);
}
Then you'd use it like:
m_lbMyListControl.InsertItem(...);
|
|
|
|
|
First of all you're using a simple Edit box. You need to change its style to "multiline", then you can write multiple lines into it. But if you want to list up a list of URLs the user has entered, I suggest you using a CListBox . It's nice, cute, simple and the best control for your purpose. You can find it in the toolbar as well. You can then add a URL to it with m_listBox.AddString(strURL); .
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks David and Greg for your responses.
//You can then add a URL to it with m_listBox.AddString(strURL);.
Greg: When i set the member variable for listbox, is it correct that i set the category to "control"? i set to "value" before and i gave me error.
But there is another problem that appear.
after compling,
IETEST2.exe - 0 error(s), 0 warning(s)
it seems that nothin has happen. The exe doesnt seems to load (pop up).
Anyones who knows what problem is this due to?
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
//is it correct that i set the category to "control"?
yes, it is
To the second question:
Seems like there are some rests of your old edit control, try to delete anything in your files dealing with the edit control in case you placed a new ListBox control on the dialog.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yeah~ Thanks a lot Gerg. I manage to achieve it. But i was hoping to make it into something like this http://www.codeproject.com/listctrl/XListCtrl/XListCtrl1.jpg[^] whereby there can be more than 1 column. Can this be done by list box?
Thanks for the help again.
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
Hi
If you want multliple columns you need to use a CListCtrl with LVS_REPORT -style turned on (can be in the control properties. Here's a nice article how to use this control.
But if you want to insert progressbars and checkboxes into your listcontrol, like on the picture, you need to draw all the things yourself, which is quite difficult for a newbie. You can simpler pick one of the custom listcontrol provided - here -.
Remember, a simple CListBox has only one column, whereas you can do a lot of things with a CListCtrl .
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I see. Yeah Thanks for all the help.
I would try my best to learn and play around with it.
Really thanks for all your help
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
Erm sorry about it. Mind if i ask another question?
I was wondering how to save the data that was display by the List box? like maybe saving it to a text file?
Thanks for the help again.
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
No problem
This is for a listbox:
for(int i=0; i<listbox.GetCount(); i++)
{
CString text;
listbox.GetText(i, text);
-> write "text" into a file
}
And for a listctrl:
for(int i=0; i<listctrl.GetItemCount(); i++)
{
for(int j=0; j<NUM_COLUMNS; j++)
{
CString text;
text = listctrl.GetItemText(i, j);
-> write "text" into a file
}
}
NUM_COLUMNS a constant value for the number of columns. YOu can write into the file via CFile for example.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi Greg,
i paste the code
for(int i=0; i<m_listbox.getcount(); i++)
="" {=""
="" cstring="" text;="" m_listbox.gettext(i,="" text);="" -=""> write "text" into a file
}
inside "void CIETEST2Dlg::OnNavigateComplete2Explorer1(LPDISPATCH pDisp, VARIANT FAR* URL)"
but it gave me this error
error C2143: syntax error : missing ';' before '->'
Error executing cl.exe.
IETEST2.exe - 1 error(s), 0 warning(s)
//did i do it the correct way ?
thanks for the help.
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
In what line does the error exactly occur?
I hope you did not copy the line -> write "text" into a file into your source. That's just a placeholder for the code responsible for writing the text into the file.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi greg,
"I hope you did not copy the line -> write "text" into a file into your source. That's just a placeholder for the code responsible for writing the text into the file." <-- haha. i really did that. silly me.
So i manage to compile and the everything goes well. But i didn't see any text file being created, having those data in the controlbox. Did i miss out something? (i was hoping like making a log of those navigation from the listbox;))Thanks again.
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
Hi
Yes, you forgot to replace the placeholder with the actual code that writes the string "text" into a file
The easiest way is to use a CStdioFile() . You can then easily write to the textfile with WriteString(text); . The MSDN has a nice example.
You can find here
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi greg,
that's the easiest? Looks like it is quite advance for me
But thanks for your help. Your the best!
I'm a newbie to visual c++. Simpler terms please
|
|
|
|
|
No problem
I suggest you buying a book, you'll quickly get all the basics and will understand how MFC (and winapi) works, actually some things are really easy to do with MFC.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hiya, I have set up 2 test dialogs apps for passing info between them. I am calling the second app with CreateProcess() e.g
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
ZeroMemory( &StartupInfo,sizeof(StartupInfo) );
StartupInfo.cb = sizeof( StartupInfo );
if( CreateProcess("\\MyApp1.exe","TestString",
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo ))
{
WaitForSingleObject( ProcessInfo.hProcess,INFINITE );
CloseHandle( ProcessInfo.hThread );
CloseHandle( ProcessInfo.hProcess );
}
else
{
cout << "Error - Opening Process..";
}
This is ok. The problem is when in the SECOND APP, I try to output the lpCommandLine parameter. I do this in the InitInstance() of the second app e.g
BOOL MyApp1::InitInstance()
{
CString str = GetCommandLine();
AfxMessageBox(str);
}
But it doesn't output the message box at all. It runs the second app but doesn't display the message box..
Any Ideas on this??
Thanks.
|
|
|
|
|
It may be because the second app's main window has not been created by the time AfxMessageBox() is called. Replace AfxMessageBox() with TRACE() and see what happens, or save the return value from GetCommandLine() to a member variable and call AfxMessageBox() later.
|
|
|
|
|
It sounds ugly but even though that doesn't exist in MSDN documentation (or at least I couldn't find an answer even though I searched a lot for it): If you change the commandline parameter of the CreateProcess call to reflect the executable AND the commandline both, it is going to work.
i.e:
<br />
CreateProcess("app.exe", "somecommandlineparameter", ...)<br />
doesn't work, but:
<br />
CreateProcess("app.exe", "app.exe somecommandlineparameter", ...)<br />
works. And I frankly don't know why.
|
|
|
|
|
How to do contextual menu ?
I think it is very easy, but I haven't got any idea
Please help
|
|
|
|
|
Look for examples of CMenu::TrackPopupMenu().
|
|
|
|
|
Hello,
In my OnDraw() function, I get the width of the page using:
int cWidthPels = GetDeviceCaps(pDC->m_hDC, HORZRES);
It works very well when I print for real, but it doesn't works when I want to draw the print preview.
When OnDraw() is called for the print preview, GetDeviceCaps() returns the width of the screen in pixels.
I want to get the size of the page (width and height) in inches for both: printing and print preview.
How can I do that ???
Is there a mean to know if OnDraw is called for printing or print preview ? and how ?
Thanks for your help,
|
|
|
|