|
Thanks again Peter, you are the BEST!
|
|
|
|
|
Thanks again Peter, you are the BEST!
|
|
|
|
|
Hi!
I am building a chat application and I'd like the main chat window to scroll down (such that the last message is at the bottom of my CRichEditCtrl) when the user enters a message.
I have not been yet able to do this. I know about LineScroll, but how many lines should I scroll with it? (Because the user can move the scroll bar upwards whenever he wants.)
Thanks!
|
|
|
|
|
Before you update your CRichEditCtrl with the latest chat info, call GetLineCount to get the line count before line addition. Then add lines to it, and call GetLineCount again.
Do a LineScroll with the difference.
Peter Molnar
|
|
|
|
|
You didn't understand what I want.
Maybe I wasn't clear enough.
Doing what you said would work if the user wouldn't change the scrollbar's position.
But let's say he wants to see a message which is upwards and he scrolls upwards.
When a new message is entered, I want the CRichEditCtrl to scroll down as I said, with the last message being on the last line of the CRichEditCtrl.
So, how can I make it happen?
|
|
|
|
|
Then your task is even simpler:
1.Update your CRichEditCtrl
2.Call GetFirstVisibleLine
3.Call GetLineCount
4.Call LineScroll with the difference as a parameter. (3./ - 2./)
Peter Molnar
|
|
|
|
|
You still don't understand and I think this time it isn't my fault.
Doing what you say would take the last line on the _FIRST_ line of my CRichEditCtrl. I want the last message to be on the last line of the control.
|
|
|
|
|
I made a simple client. I want to connect to a small TCPIP enable module. With Hyperterminal, I can connect to it.
With the small client I wrote I can connect to other computer etc and also send. However, when I try to connect to this small module, it fails at gethostbyaddr. It returns null. When I connect to other things written in Windows, it is OK. I can't figure out why this would fail. I pinged and can ping the module so I know it definitely is there. It fails at gethostbyaddr before it even connects to the module. I am thinking it must be a config error or something. the type of socket is AF_INET. Could this affect the connection?
Thanks!!
|
|
|
|
|
hmmm,im not sure but maybe you could try getting the host by the ip address instead of the hostname.
try something like this :
SockAddr.sin_addr.s_addr = inet_addr ("0.0.0.0");
|
|
|
|
|
Is there a way to retrieve user email accounts from outlook exp. or outlook?
Best Wishes,
ez_way
|
|
|
|
|
Hi, I created a activex control with MFC, now I want to add a array as a property into this activex control,but I don't know how to add it,can you help me? thanks!
|
|
|
|
|
|
I've made a neat LED circut, and I am trying to control it through inpout32.dll. I am not used to DLLs, so I am hoping I am just doing something stupid...
short _stdcall Inp32(short PortAddress);<br />
void _stdcall Out32(short PortAddress, short data);<br />
<br />
void main()<br />
{<br />
Out32(0x378,0xff); <br />
Sleep(2000);<br />
}
This is giving me the following error:
LED.OBJ : error LNK2001: unresolved external symbol "void __stdcall Out32(short,short)" (?Out32@@YGXFF@Z)
Debug/LED.exe : fatal error LNK1120: 1 unresolved externals
What am I doing wrong? I have VERY LITTLE experience with DLLs, in fact, this as somewhat of a "copy-paste" program, so I feel fairly confident I forgot something simple.
If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
Hi!
You have to tell your linker where to find the exported functions. So, in the project properties, add something like input32.lib (in the Extra Dependencies tab for Visual C++ .net).
Appstmd
http://www.appstmd.com
|
|
|
|
|
My program has a CListBox that stores all of the MP3's in a directory selected by the user. I'm trying to use CFileFind to find the mp3 files in the directory, but I'm having problems. Here is the function that updates the CListBox.
<br />
void CID3MasterDlg::UpdateMP3List()<br />
{<br />
<font color="white">_____</font>CFileFind finder;<br />
<font color="white">_____</font>CString searchstr = m_strMP3Dir + "*.mp3";<br />
<br />
<font color="white">_____</font>m_MP3ListBox.AddString(searchstr);
<font color="white">_____</font>if(finder.FindFile(searchstr))<br />
<font color="white">_____</font>{<br />
<font color="white">__________</font>m_MP3ListBox.AddString(finder.GetFileName());
<font color="white">__________</font>while(finder.FindNextFile())<br />
<font color="white">_______________</font>m_MP3ListBox.AddString(finder.GetFileName());<br />
<font color="white">_____</font>}<br />
<font color="white">_____</font>finder.Close();<br />
<font color="white">_____</font>UpdateData(true);<br />
}<br />
The white _'s are just there for spacing since tabs are ignored by the forum.
m_strMP3Dir is the full name of the directory to be searched. It uses backslashes ( \ ) as the separator, and it has a backslash at the end of the string (e.g. "C:\MyFolder\MP3s\").
The program doesn't crash if a folder with no MP3s is selected. But, if a folder with MP3s in it is selected, the program will crash when it tries to add the first string to the listbox. Specifically, GetFileName() fails an assertion and exits with code 3.
Any help or advice or debugging tips are greatly appreciated. I'm completely stumped!
|
|
|
|
|
Hi!
Your program crashes because it finds a file. When you use the function GetFileName, you have to use the function FindNextFile first, as it is explained on the MSDN.
Your code should be:
<br />
void CID3MasterDlg::UpdateMP3List()<br />
{<br />
_____CFileFind finder;<br />
_____CString searchstr = m_strMP3Dir + "*.mp3";<br />
<br />
_____m_MP3ListBox.AddString(searchstr);
_____if(finder.FindFile(searchstr))<br />
_____{<br />
__________while(finder.FindNextFile())<br />
_______________m_MP3ListBox.AddString(finder.GetFileName());<br />
_____}<br />
_____finder.Close();<br />
_____UpdateData(true);<br />
}<br />
Appstmd
http://www.appstmd.com
|
|
|
|
|
Thank you, that did fixed it. Next time I'll RTFM more closely .
|
|
|
|
|
Hi, So glad to see this answer, I had similiar question before;)
|
|
|
|
|
Can anyone help with some sample code to automate word automation from a VC++ with MFC app. ?? Any one have real experience ?? I know how to load a logo into a header file that will apear on top of all pages.
My question is how do I make logo load only on first page header ? I would appreciate a real code sample that works... Also some info on footers. I have added all the word constants as a header file in my project and have access to the HeaderFooter, Section, Sections,HeadersFooters, etc. classes, but need some help on the setup for getting my report ( a .doc file) divided into 3 sections, with headers and footers for each section, like I said, with a logo on very first page. Thanks!
|
|
|
|
|
you can find some pretty good document about this issue with some sample code.
Search for "Automating Microsoft Office 97 and Office 2000"
As for your quetion about loading logo into first page header, do the following:
1.Open a Word doc
2.Tools/Macros/start Recording a Macro
3.Create a header with your logo
4.Stop macro
5.Check what you recorded
The contents of 5./ (somewhat optimized) you will have to put into your MFC automation code.
Peter Molnar
|
|
|
|
|
Peter,
I'm aware about the possibility of recording macro in word then checking the VB code, but there are worlds of difference between VB(wich I know next to nothing about) and VC++ and MFC...thats why I'm looking for some sample VC++ and MFC code to help me understand. And like I said, I know how to create the word .doc...etc.
|
|
|
|
|
I just have done what described above, namely I recorded a header inserting macro. This was recorded when I clicked: View/Header-Footer/Insert pic from file
Sub Fejlec()
'
' Fejlec Makró
' Rögzítés: 11/23/2003, készíto: Pepe
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow.ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:="c:\pic.jpg", LinkToFile:=False, SaveWithDocument:=True
End Sub
If you take a look at its contents, the if statements are useless for this task, you can delete them. (that was meant under "somewhat optimize").
What remains is:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:="c:\pic.jpg", LinkToFile:=False, SaveWithDocument:=True
What does it mean? What it reads:
1. line: start editing the header of the current page
2. line: add a pic to the selection (i.e. header) with the given filename, and save the file within the word document not linking to it as an external file.
This is how you code this with MFC:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
Documents oDocs = oApp.GetDocuments();
_Document oDoc = oDocs.Add(vOpt, vOpt);
Window oWin = oApp.GetActiveWindow();
Pane oPane = oWin.GetActivePane()
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
Selection oSel = oApp.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\pic.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
Some remarks:
1.The Word wrapper class was produced from Word 8 with VC6, because Word 8 is compatible with later word versions and VC6 produces one file for one type lybrary unlike VS.NET which does one file for every object in the tlb.
A similar wrapper is recommended to use.
2.The additon of different header for first file is left for you for practice, (ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True)
Peter Molnar
|
|
|
|
|
Peter,
I appreciate the practice you are attempting to let me try, but I'm pressed for tie in this thing. I'm trying to make the code you suggest work, and I will learn from it and then be able to practice. I adapted your code. Here is my version:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Creates new doc
Documents documents = application.GetDocuments();
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty); //First line
Window oWin = application.GetActiveWindow();
Pane oPane = oWin.GetActivePane();
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
//Second line
Selection oSel = application.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
//**************
Notice I just changed the names of the app and doc objects to match what I already had, and I added &varEmpty paramters to the :
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty) because Add does not take 2 arguments where I'm at.
As for the code:
(ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True)
I was aware of the "DifferentFirstPageHeaderFooter = True"..but as I said, can't quite figure out how to set it up...since you are starting from the ative document,then page setup objects, and from the functions available in the PageSetup class , I guess I would have to use the :
void PageSetup::SetDifferentFirstPageHeaderFooter(long nNewValue)
function. So, here goes:
PageSetup pageSetup;
pageSetup.SetDifferentFirstPageHeaderFooter(TRUE);
So, the total code would be:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Creates new doc
Documents documents = application.GetDocuments();
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
//First line
Window oWin = application.GetActiveWindow();
Pane oPane = oWin.GetActivePane();
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
//Second line
Selection oSel = application.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
PageSetup pageSetup;
pageSetup.SetDifferentFirstPageHeaderFooter(TRUE);
Am I on the right track ?? Because this compiles ok, but gives me an error at runtime that says "Error...member not found"
I have 1 week to complete getting this straightened out...I would appreciate yoour help. I may certainly have other questions if you can help me ok on this one.
|
|
|
|
|
You are much on the right track.
Remarks:
1.
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
You use a word version 9 (Word2000) or 10 (XP) for your C++ wrapper because your add function has 4 parameters (mine has only 2 because it was taken from Word8=Word97). This is no problem as far as you don' wanna target Word97, and you fill the params properly. Use for all 4 params vOpt, or declare vEmpty the way vOpt was.
2.
Start ALWAYS from the Application object going "down" (the VB code does the same, or it explicitely declares another)
PageSetup pageSetup;
pageSetup.SetDifferentFirstPageHeaderFooter(TRUE);
YOur pagesetup object is not initialized for proper usage with your doc, you just declared it (i.e: it compiles but does not run)
Use:
_Document oDoc = application.GetActiveDocument();
PageSetup oPageSetup = oDoc.GetPageSetup();
oPageSetup.SetDifferentFirstPageHeaderFooter(1);
3.
The constants (like wdSeekCurrentPageHeader) are not declared in my wrapper classes (if you could compile your above code then they were declared in yours).
If you don't have their values, you can either experiment around or try figuring it out from the macro editor.
Peter Molnar
|
|
|
|
|
Hi!
With your help, this is what I have put together so far...no compile errore, but still crashes at run time:
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//Creates new doc
Documents documents = application.GetDocuments();
_Document document = documents.Add(vOpt,vOpt,&varEmpty,&varEmpty);
Selection selection(application.GetSelection());
Window oWin = application.GetActiveWindow();
Pane oPane = oWin.GetActivePane();
View oView = oPane.GetView();
oView.SetSeekView(wdSeekCurrentPageHeader);
//since a doc has already been opened, you just have to find the active one
_Document oDocument = application.GetActiveDocument();//
PageSetup oPageSetup = oDocument.GetPageSetup();
//This initializes oPageSetup properly
oPageSetup.SetDifferentFirstPageHeaderFooter(1);
//Second line
Selection oSel = application.GetSelection();
Shapes oShapes = oSel.GetInlineShapes();
oShapes.AddPicture("c:\\Inspec\\LogoInspec.jpg",vFalse,vTrue,vOpt,vOpt,vOpt,vOpt,vOpt);
//***************************
The line it's having problems with is the :
oPageSetup.SetDifferentFirstPageHeaderFooter(1);
The error says "The parameter is incorrect" ???? I do see this function in the PageSetup class...here it is:
void PageSetup::SetDifferentFirstPageHeaderFooter(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x74, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}
Looks like I'm almost there...I await your help please "
|
|
|
|
|