|
Thanks for that
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hi everyone,
I am using an activex control which i have inserted onto a formview of an mdi application.when i press File->new option i get a new window with the activex in it. Now i want to implement the same funtionality on a button press. i want the same results as that of File->New.How do i achieve it from the CFormView or the Cmainframe class.
|
|
|
|
|
Maybe something like this:
if (AfxGetApp()->m_pDocManager)
AfxGetApp()->m_pDocManager->OnFileNew();
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
O' My God that really worked like magic.. But how do i get a pointer to each view. I want to pass data to the view
|
|
|
|
|
I'm glad it worked. That's how MFC does it but it's using an undocumented variable (although
it's worked for as long as I can remember).
You probably could just give your button the id ID_FILE_NEW and it would have worked like magic
too I thought for sure someone here would jump on me for that one LOL.
chaitannya_m wrote: But how do i get a pointer to each view. I want to pass data to the view
Which view? The one just created?
The view just created should be the active view. To get the active view in MDI;
CMDIFrameWnd *pFrame =
(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
CMyView *pView = (CMyView *) pChild->GetActiveView();
To iterate through all views, one way is to iterate through all documents and their associated
views:
POSITION DocTemplatePos = AfxGetApp()->GetFirstDocTemplatePosition();
while (DocTemplatePos != NULL)
{
CDocTemplate *pTmpl = AfxGetApp()->GetNextDocTemplate(DocTemplatePos);
POSITION DocPos = pTmpl->GetFirstDocPosition();
while (DocPos != NULL)
{
CDocument *pDoc = pTmpl->GetNextDoc(DocPos);
POSITION ViewPos = pDoc->GetFirstViewPosition();
while (ViewPos != NULL)
{
CView *pView = pDoc->GetNextView(ViewPos);
}
}
}
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
What are the best books to start knowing about data structures from a begineer point of view with emphasis on hands on rather than the theoritical aspect? Any help would be highly appreciated.
|
|
|
|
|
|
tom groezer wrote: What are the best books
What's good for others may not be good for you, and vice versa.
What's wrong with this?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi all,
I'm trying to use the Replace function of the CString class, and it seems to be mostly fine, except it's ballsing up in one particular instance. I can't see what I'm doind different, but for some reason it doesn't like this:
CString PostCode;
m_PostCode.GetLine(0, PostCode.GetBuffer(m_PostCode.LineLength(0)), m_PostCode.LineLength(0));
PostCode.Replace("'", "''");
where m_PostCode is a member of the class this code is called from, being an instance of CEdit. I can't see anything that I'm doing differently to any other times I'm using the Replace function, but in this instance it just won't replace ' with ''.
Any ideas? I can't seem to find anything that suggests this is a known issue.
Thanks!
Louis.
Addendum:
I've noticed that it occurs with other CString/CEdit pairs like this, but if I copy the contents of the CString into a new CString, then run the Replace function of the new string it works fine. Am I missing something here?
-- modified at 12:05 Wednesday 4th July, 2007
|
|
|
|
|
Maybe try calling
PostCode.ReleaseBuffer(m_PostCode.LineLength(0));
before calling Replace()
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Yes, this worked like a charm!
Thanks a lot Mark, very speedy response!
Louis.
|
|
|
|
|
Hey Guys,
I have an MFC CStatic derived class that has a public member function Draw();. Draw uses GDI to draw stuff to the CStatic window. I call this Draw method from a multimedia timer (timeSetEvent) to continually update the display.
My problems is that When my main app is doing a lot of work the drawing is sometimes interrupted when I load files. So I put the lengthy process of loading files in a worker thread, but the drawing is still "jerky" when loading a file. Is there anything else I can do to ensure that my CStatic is always drawing? Is this something I need a user interface thread for?
Thanks,
Greg
|
|
|
|
|
I'm not certain what you're trying to achieve here as genuinely constant redrawing would preclude you doing anything else anyway but you may have run up against a perenial problem with the MFC architecture. Essentailly anything done to the user interface is done on the main thread even if you call it from a worker thread. I would definitely suggest doing the file loading on a worker thread before getting into the absolute minefield of multiple user interface threads.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Basically I have two music files playing (video and/or audio) I am showing a scrolling waveform as the song is playing in realtime (using GDI). I need this waveform to always scroll. When loading a file into the second player while the first player is playing the scrolling waveform is being interrupted. I just need that waveform to always be scrolling.
So MFC always draws from the main thread no matter what? That's no good for me. Is my only option UI threads?
|
|
|
|
|
If you're doing that sort of thing and you want it really smooth I'd consider DirectX/OpenGL or perhaps just doing everything except the drawing in lower priority background threads and relying on having enough hardware under the bonnet to keep up. Double buffering may be your friend aswell when it comes to getting smooth display updates. i.e. draw it all to an off screen Bitmap and then blit that to the screen in one go. With a bit of manipulation perhaps you could do the scrolling in the bitmap memory aswell without having to redraw the old parts of the waveform.
It's a while since I did much PC based MFC but I certainly wouldn't have recommended it for the sort of app your describing when I did. Having said that there may be other issues causing your problems. Are you using a cyclic or fixed buffer that doesn't do any heap allocation while in use to store your waveform? If not you're going to get horrible performance glitches from the memory allocator for example.
Are you maxing out your current hardware? If you check the performance monitor while your app is the only one running and it's flat out at 100% then either you've got some ineffecient code or you're trying to push your hardware beyond what it can achieve. Ultimately all such jolts and flickers are down to something being blocked either by synchronisation or a bandwidth limit somewhere. Unless something is resource stealing. In that regard watch out for the Quicktime tray icon app if you use DirectX it can steal the graphics card from you every few seconds and cause horrible jitter.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I don't agree that all drawing is done on one thread. Through WM_PAINT maybe, but if you're using
GDI to draw from another thread then it's drawing on that thread. I do video rendering and it's
definitely not on one UI thread
*edit* BTW, I've personally never used multiple UI threads - I meant multiple worker <br />
threads doing GDI drawing.
Try calling GDIFlush() when you're done drawing each time.
Also remember GDI is not thread safe - It's up to you to sync drawing from other threads with
drawing that may occur in response to WM_PAINT on the UI thread.
Mark
-- modified at 13:15 Wednesday 4th July, 2007
Mark Salsbery
Microsoft MVP - Visual C++
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
Hi,
Using a CDialogBar:OnSize(UINT nType, int cx, int cy) I get assertion error when i am trying to access a child window ie CStatic control under OnSize method. In OnInitDialog it works fine but in the OnSize the hWnd is equal to ??? (unkown). What's wrong here ?
void CBottomPanel::OnSize(UINT nType, int cx, int cy)
{
CDialogBar::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CStatic *pStatic;
pStatic= (CStatic*) GetDlgItem(IDC_MYSTATIC);
-----> ASSERT(pStatic); ----------------------------->Assertion Error, not valid handle.
}
sdancer75
|
|
|
|
|
On the first call [or so] to OnSize the child windows have not been created yet. In other words, their HWNDs are not valid. Perheps this is what causes the assertion failure. Try to have smth like so;
CStatic *pStatic;
pStatic= (CStatic*) GetDlgItem(IDC_MYSTATIC);
if (NULL != pStatic)
{
// do anything here
}
In this way you will skip the first time call to OnSize.
In general, using GetDlgItemis not a good idea. Instead, let the wizard define CStatic c_myStatic member-variable. In this case the code will turn into this one;
if (NULL != c_myStatic.GetSafeHwnd())
{
// do anything here
}
--
=====
Arman
|
|
|
|
|
Hi Arman,
I suppose you have right. I did not tested since i have changed my code and i placed all code to CalcDynamicLayout(int nLength, DWORD dwMode) and it works.
Thank you for your reply,
Regards,
sdancer75
|
|
|
|
|
I agree with Arman maybe your error is of first call.
|
|
|
|
|
in my progarm (special to deal with data), i need good expressions for 2,4,8,16 based integers.
for example, in c++, we use 0x... to stand for 16 based data.
so, expressions i try to use are:
0b... (2 based)
0f... (4 based)
0o... (8 based)
0x... (16 based)
but i am afraid that expressions above are not good.
i hope i can use common or popular expressions.
do you know expressions which are accepted already by people for different based integers?
|
|
|
|
|
Base-2 and base-8 numbers already have a known prefix. Why the change? What exactly are you trying to do?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hey!
m working on a code where in i have to write to a board. the system and the board are connected via UART. m using VC++. the problem is that the moment i try to write a character the system hangs. here is a part of the code -
void CserialportthingieDlg::OnBnClickedWrite()
{
UpdateData(TRUE);
size_t size;
size = strlen(m_sshwwrite);//m_sshwwrite is he variable associated with the editbox
int i;
i=size-1;
asd->WriteByte(m_sshwwrite[i]);//asd is an instance of the class SerialCom where in i writebyte has been defined.
}
the definition of writebyte is --
BOOL CSerialCom::WriteByte(BYTE bybyte)
{
iBytesWritten=0;
if(WriteFile(hComm,&bybyte,1,&iBytesWritten,NULL)==0)
return false;
else
return true;
}
please let me know if any thing is wrong with the code or tell me a better way.
thanks a lot!
regards
lovy
|
|
|
|
|
How do you set the serial port timeouts (remember: WriteFile is a blocking call)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
actually i had set some arbit time out.
now even when i restored it to the default value the system still hangs!
help me out!
thanks
regards
lovy
|
|
|
|