|
FWIW I created a quick MFC SDI app and put PostMessage(WM_CLOSE);
at the end of the OnCreate() function of the main window class.
The app closed cleanly.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
I am using some propety pages in wizard mode, on one of my pages i am using a toolbar
The first time you use the wizard it all works fine
if you run the wizard again, the toolbar fails to load correctly
The toolbar appears to be there, but there are no images shown on any of the buttons
I am creating the toolbar in the oninitdialog() of the property page using
if(!m_toolBar2.Create(this) || !m_toolBar2.LoadToolBar(IDR_TOOLBAR2))
AfxMessageBox("Failed");
Can anyone help at all ?
thanks
Simon
|
|
|
|
|
Hi all,
I made an ActiveX Control in VB 6.0 which uses region functions to give the control an irregular look, I mean, not a plain square or rectangle. The control looks as it should when placed on a VB Form at design time. However, when I put the same control on a dialog box in VC++ 6.0, it gets a square shape, though at run time the control appears how it should. Is there a difference in the ways VB and VC initalize the same control at design time? Or is there an issue with using the region functions? Please help. Thanks.
Henry.
|
|
|
|
|
Is it good to have a public struct in a class? If its private, is there any way to use getter to get the struct?
|
|
|
|
|
you mean, the definition of the type ? or an instance of such a struct ?
|
|
|
|
|
|
so that doesn't make sense to have a getter to access a type definition.
a getter would be to retrieve a member of the class, which type could be of a defined struct...
so yes, either define your struct outside, or if inner, do it publically (unless it's for the class internal use only)
|
|
|
|
|
thank you for replying my noob questions, regards.
|
|
|
|
|
I'm not sure what you're doing but perhaps you want something fun like this
<br />
<br />
class CSomething<br />
{<br />
<br />
public:<br />
<br />
struct MyInterface<br />
{<br />
public:<br />
int Increment( void );<br />
};<br />
<br />
MyInterface* QueryInterface()<br />
{<br />
return dynamic_cast<myinterface*>(&aHiddenInstance);<br />
}<br />
<br />
private:<br />
<br />
struct stHidden : public CSomething::MyInterface<br />
{<br />
int Increment( void )<br />
{<br />
iHiddenStructMember++;<br />
}<br />
<br />
int iHiddenStructMember;<br />
};<br />
<br />
stHidden aHiddenInstance;<br />
};<br />
<br />
Geek points obvously to the first person who points out that this is fairly pointless and double to anyone who can guess which old MS technology I'm playing with today
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
I am trying to draw something into memory DC and then copy it to screen or printer DC. I get the correct output drawing on screen or when directly taking the print out on printer. BUt while viewing print preview, it does not show any output.
CMyView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rcClient;
if (pDC->IsPrinting())
{
rcClient = m_rcPrintRect;
}
else
{
GetClientRect(&rcClient);
}
CBitmap bmp;
CDC memDC;
memDC.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(pDC, rcClient.Width(), rcClient.Height());
memDC.SelectObject(&bmp);
memDC.DrawText(L"Hello", &rcClient, DT_CENTER | DT_VCENTER);
pDC->BitBlt(0,0,rcClient.Width(), rcClient.Height(), &memDC, 0, 0, SRCCOPY);
bmp.DeleteObject();
memDC.DeleteDC();
return;
}
I suspect something is wrong with creating compatible DC. pDC represents printer dc but the display is on screen. How to remove this problem?
|
|
|
|
|
What is the value of rcClient when it fails?
I'm not seeing anything wrong with your DC creation...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I checked it in debug mode. the program does not fail in print preview. BitBlt also completes successfully. only I do not get any output. I can initialize rcClient to (0,0,0,0) but that does not make a difference.
Thanks.
|
|
|
|
|
ok....and the answer to my question is?
From the debugger, what is the left/top/right/bottom values of the rect?????
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
oh sorry...
in print preview, top=0, bottom=6400, left = 0, right=4900 (size of A4 sheet in pixels @600 dpi)
in print, height= 6300, widht=4800...(because of different margin settings?)
the fruits of your success will be in direct ratio to the honesty and sincerity of your own efforts in keeping your own records, doing your own thinking and, reaching your own conclusions.
..surviving in autumn..in love with spring..
|
|
|
|
|
Arghh I'm drawing a blank here LOL
What happens if you do
pDC->MoveTo(rcClient.left, rcClient.top);
pDC->LineTo(rcClient.right, rcClient.bottom);
Do you get a diagonal line?
Also is the bitmap creation succeeding?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, I get a diagonal line. In fact. there's no problem with drawing directly on print preview dc. I am using memory dc in my code only to avoid flickering (perhaps it was obvious)
The following code draws properly in print preview... by using DIB. But it's heavily slowing down my system. perhaps, I need to create DIB section in more elegant way. DDB provided by create compatible bitmap perhaps does not work.
void CMyView::OnDraw(CDC* pDC)
{
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rcClient;
if (pDC->IsPrinting())
{
rcClient = m_rcPrintRect;
}
else
{
GetClientRect(&rcClient);
}
HBITMAP bmp;
BYTE* drawingSurfaceBits;
BITMAPINFOHEADER BMIH;
BMIH.biSize = sizeof(BITMAPINFOHEADER);
BMIH.biBitCount = 24;
BMIH.biPlanes = 1;
BMIH.biCompression = BI_RGB;
BMIH.biWidth = rcClient.Width();
BMIH.biHeight = rcClient.Height();
BMIH.biSizeImage = ((((BMIH.biWidth * BMIH.biBitCount) + 31) & ~31) >> 3) * BMIH.biHeight;
bmp = CreateDIBSection(pDC->GetSafeHdc(), (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&drawingSurfaceBits, NULL, 0);
if((bmp == NULL) || (drawingSurfaceBits == NULL))
{
AfxMessageBox(L"Bitmap not created", MB_OK | MB_ICONSTOP);
return;
}
memDC.CreateCompatibleDC(pDC);
memDC.SelectObject(bmp);
memDC.DrawText(L"Hello", &rcClient, DT_CENTER | DT_VCENTER);
pDC->BitBlt(0,0,rcClient.Width(), rcClient.Height(), &memDC, 0, 0, SRCCOPY);
return;
}
Also, in print preview mode, the quality of picture shown on screen is extremely poor. I am perhaps using only rgb etc. I need to study bitmapinfoheader further.
Thanks for the precious help.
modified on Thursday, September 18, 2008 1:07 PM
|
|
|
|
|
Creating that big bitmap on every draw is going to be a little slow.
I would only (re)create it when the size changes.
theCPkid wrote: (CONST BITMAPINFO*)&BMIH
Bad cast!!!!! No bueno! You need to pass a pointer to a BITMAPINFO,
not a pointer to a BITMAPINFOHEADER. The cast just hides the error from
the compiler
Try
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = rcClient.Width();
bmi.bmiHeader.biHeight = rcClient.Height();
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = ((((bmi.bmiHeader.biWidth * bmi.bmiHeader.biBitCount) + 31) & ~31) >> 3) * bmi.bmiHeader.biHeight;
bmp = ::CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void**)&drawingSurfaceBits, NULL, 0);
I'm not sure what's going on with the rendering quality....I'll ponder that
and let you know if I think of something...(maybe the code fix above will do better?)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Does not make any difference on rendering quality and the quality is very poor. So, I am not using it in my code as of now.
Thanks.
|
|
|
|
|
It's not your code or my code causing poor quality...either way
should work.
Rendering some text in a 6400x4900 offscreen buffer then squishing it down to fit
a window is going to look bad.
The only way to make it look 100% correct is to make your bitmap the exact
size it will be rendered on the screen.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
oh! I got your point. I did not think about it earlier.
Thanks again.
|
|
|
|
|
The issues you may be seeing could be down to what raster operations are supported by the DC types in question.
If you had been saying it shows in preview and not on the printer I would definately have said this, but you have it reversed which makes me intrigued (and I have even come out of CP semi-retirment to answer )
The first thing I would say is drop BitBlt altogether. its not guaranteed to be compatible with both display DCs and printer DCs. Your best option would be to switch to StretchDIBits, from memory this is compatible with all DC types.
Another thing that could be causing you problems is that your creating a DC compatible with a preview DC, this means you will have all the world transforms which map from print to preview display probably active on your memory DC. Try creating your comapatible DC directtly from the screen by passing NULL instead of pDC. If that fixes the issues then I would say its down to the preview DC supporting all the world transforms and your in effect drawing of the edge of the comaptible bitmap.
If you vote me down, my score will only get lower
|
|
|
|
|
Roger Allen wrote: but you have it reversed which makes me intrigued (and I have even come out of CP semi-retirment to answer )
Special thx for that.
Roger Allen wrote: The first thing I would say is drop BitBlt altogether. its not guaranteed to be compatible with both display DCs and printer DCs. Your best option would be to switch to StretchDIBits, from memory this is compatible with all DC types.
yeah...as noted earlier, creating a DIB bitmap removes the problem with print preview but the application becomes very slow. Also, the image quality becomes very poor. You can see red, blue, green lines over the whole image.
Roger Allen wrote: Try creating your comapatible DC directtly from the screen by passing NULL instead of pDC. If that fixes the issues then I would say its down to the preview DC supporting all the world transforms and your in effect drawing of the edge of the comaptible bitmap.
No, I tried that earlier...creating a dc for monitor in print preview mode does not work.
Anyway, what I did last night is to check whether the DC is of type CPreviewDC. If it is, then I directly draw on that dc instead of creating a memory dc for it. otherwise I create a memory DC in case of print and normal view mode. It works correctly.
Also, I am thinking of creating a smaller fixed size bitmap on which to draw and then StretchBlt it on whatever the size of actual DC. This will save me from creating a bitmap every time inside OnDraw as well as painting on larger DC. As of now, the applicaion is taking large CPU power and I am trying to find out various tools for profiling that can help me find bad code.
Thanks for your suggestion.
|
|
|
|
|
Hi,
I need to lock then internet from a c++ program. the program would be a control internet manager who lock the internet access in especific time periods. Ex: 01:00 am to 06:00 am.
Some one knows what i need read or learn to create this kind of program ?
is there a program who do it, today ?
Samuel Nunes de Arruda
Brasil.
|
|
|
|
|
Interesting problem. One solution would be to block the use of the browser (note: developers can usually work around this). Another solution would be to block port 80 traffic. I've not done wither of these so I may be way off base.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
You want to lock the internet from 1am to 6am? But 6am in brasil is after I after I start work in the UK.
Frankly, it seems rather harsh to me... I hope you'll leave the keys with someone else when you go on holiday..!
Iain.
ps, As to a more serious answer, I'm really not sure. You could probably write something to turn off network access for that particular PC, but how would it know whether a network request was for a machine in Venezuela, or to Consuela in accounting?
It sounds like something for your firewall, rather than the local PC.
Iain (again).
|
|
|
|
|