|
First of all, looks like 75% of your code here is useless, you don't need to copy the source surface byte by byte. DirectDraw exposes a DC. Once you've got it, you simply do a StretchBlit to a destination DC.
<pre>
// m_pDDSOffscreen3 is a DirectDraw surface
HDC MemDC, SurfDC;
HBITMAP hBmp,hDib;
DDSURFACEDESC ddsd;
LPBYTE destbuffer=NULL;
BITMAP bmp;
PBITMAPINFO pbmi;
WORD cClrBits;
LPVOID lpBits=NULL;
if (m_pDDSOffscreen3==NULL) return;
// Get the size of the surface...
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
m_pDDSOffscreen3->GetSurfaceDesc(&ddsd);
// Create the Memorybitmap now...
HRESULT hr = m_pDDSOffscreen3->GetDC(&SurfDC);
if (SUCCEEDED(hr))
{
// Create the Memorybitmap now...
MemDC = ::CreateCompatibleDC( NULL );
hBmp = ::CreateCompatibleBitmap( SurfDC, ddsd.dwWidth, ddsd.dwHeight );
::SelectObject( MemDC, hBmp );
::BitBlt( MemDC, 0, 0, ddsd.dwWidth, ddsd.dwHeight, SurfDC, 0, 0, SRCCOPY );
// Bitmapstruct init...
::GetObject( hBmp, sizeof(BITMAP), (LPSTR)&bmp ); cClrBits = (WORD) 24;
pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));
/* Initialize the fields in the BITMAPINFO structure. */
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = 24;
if( cClrBits < 24 ) pbmi->bmiHeader.biClrUsed = 2^cClrBits;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 7) /8 *
pbmi->bmiHeader.biHeight * 24;
pbmi->bmiHeader.biClrImportant = 0;
hDib = ::CreateDIBSection(NULL,pbmi,DIB_RGB_COLORS,&lpBits,NULL,0);
if (hDib==NULL) TRACE("CreateDIBSection failed\n");
// Get the bits from the DC to save it to disk...
GetDIBits( SurfDC, hBmp, 0, (WORD) bmp.bmHeight, lpBits, pbmi, 0 );
if( lpBits == NULL ) TRACE( "No memory for screenshot!\n" );
if (bAddTail)
{
CString name=_T("");
if (GetDocument()->addShot(name,nStart,nEnd) &&
pThumb->AddItem(CBitmap::FromHandle(hDib), name))
{
GetDocument()->addShotInfo(nStart,nEnd,
pThumb->GetImageListIndex(),pThumb->GetItemIndex());
}
}
else
{
// remplace
replaceShot(CBitmap::FromHandle(hDib));
}
m_pDDSOffscreen3->ReleaseDC(SurfDC );
::SelectObject(MemDC,NULL);
::DeleteDC(MemDC);
::DeleteObject(hBmp);
::DeleteObject(hDib);
</pre>
<hr noshade>
<font size="-1" face="arial"><i>And I swallow a small raisin.</i></font>
<b style="background-image:'url(http://www.arstdesign.com/hands.jpg)';width:50px;height:45px"></b>
|
|
|
|
|
Thanks for the tip, but I think your solution seems slightly wasteful. You suggest creating a DIB from a DDB which requires allocating a new DDB + memory for the DIB bits. Isn't Lock'ing the surface the same thing as getting the DIB bits (and hence you can avoid the DDB HBITMAP stuff)?
|
|
|
|
|
Todd Jeffreys wrote:
You suggest creating a DIB from a DDB
Yes? That is AFAIK what the very definition of a .BMP-file says it contains.
|
|
|
|
|
I created 8 buttons on a page and created OnClick calls the easy way by double clicking the buttons. After doing this I put break points in each one. Then when I ran the program the broke in the wrong one...they were all off by 1 and the last one did nothing.
This maybe part of the problem or just another one, but the resource.h file has duplicated numbers all over the place. I would think that they should all be unique.
All explainations welcomed!!!
Thanks
|
|
|
|
|
what do you mean?
but the resource.h file has duplicated numbers all over the place. I would think that they should all be unique.<br />
|
|
|
|
|
I ended deleting all the buttons and then adding them back in and now they work.
I still have dublicate numbers...maybe they are on a window by window basis.
|
|
|
|
|
I still have dublicate numbers...maybe they are on a window by window basis.
what numbers.. of what???
|
|
|
|
|
resource.h example:
#define IDC_RADIO7 1017
#define IDC_CHECK8 1017
#define IDC_ACTV_7 1017
#define IDC_MALF08 1017
#define IDC_MALF08_SYS1 1017
#define IDC_SYS8_FAU 1017
#define IDC_SYS1_MODE_SEL_SWITCH4 1017
#define IDC_MF_FRONT1 1017
#define IDC_ALQ122_DUP 1017
#define IDC_MF1_FRONT 1017
|
|
|
|
|
Its a common problem.
Theres a tool at http://www.codeproject.com/macro/resorg.asp that can help you reorganise.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Has anyone found a workaround for disabling the arrow on an owner drawn menu when the popup menu item is disabled?
|
|
|
|
|
If you mean whether all the items to the left of the => arrow are disabled so you'd like to remove the menu item?
Can't you catch the OnInitMenu handler ( Or whatever it is in CMainFrame ) and call pMenu->ModifyMenu etc... to remove the arrow or just remove that menu item all together.
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
Hi
Thank you for the reply. What I mean't is that I wanted to show the popup menu arrow as disabled in an owner drawn menu like it is in a standard menu if you disable the popup.
Cheers
Paul
|
|
|
|
|
Yaw all!
Happy new year! (To all Jewish folks)
<font color = blue>CWnd</font>::SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE) doesn't set my window to be topmost ( creates by <font color = blue>CWnd</font>::CreateEx() , Styles: WS_POPUP )!!!
I want it to appear above the taskbar, but it does-NOT!
Any? Help?
--BlackSmith--
/*The roof is on fire, we don't need no water, let the MF burn*/. BHG.
|
|
|
|
|
Ummm... Maybe you can try setting the desktop as the parent of your window with CWnd::SetParent .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
This is an MFC CFormView MDI application and this code is in the View class.
I have a CFileDialogST from which I want to terminate the app in case the user presses cancel. Its a class from CP by Davide Calabro. I trap the IDCANCEL and indeed i do get the messagebox, but I've tried
a. PostQuitMessage is ignored
b. PostMessage(WM_CLOSE) is ignored
c. SendMessage(WM_CLOSE) is ignored
d. exit(0) makes the app crash!
if(nRetValue == IDCANCEL)
{
AfxMessageBox ("No Image folder selected, terminating application");
PostMessage(WM_CLOSE);
}
This message No Image folder selected, terminating application shows up so I know it gets in the if .
Please help!
Thanks,
ns
|
|
|
|
|
|
I think PostMessage is a better alternative here --if using SendMessage(WM_CLOSE) inside a message handler, windows can get destroyed too soon.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I did like you said:
if(nRetValue == IDCANCEL)
{
AfxMessageBox ("No Image folder selected, terminating application");
AfxGetMainWnd()->PostMessage(WM_CLOSE);
}
and it crashes after the messagebox pops up. Same behavior as with exit(0);
???
thank you very much for helping,
ns
|
|
|
|
|
It goes to the end of mainframes destroy() where I write registry info, then suddenly gets into disassembly at the ending curly bracket of destroy(), and I can seem to get out of it, - have no clue how to interpret disassembly...crashes while stepping through disassembly somewhere...
|
|
|
|
|
|
Without the registry info code, the destroy is empty. I commented it all out - still crashes!
thanks.
A peculiar observation:
Atfirst the registry is blank. The app pops up the first thing: a CfileDialogST asking for a location (directory browser). If you hit cancel at this point, things are okay. No crash. Next, you run the app, give it a valid folder, and the main UI comes up. In this UI you can run the same exact function that ran at startup, and the CFileDlg pops up again. Now if you hit cancel, it crashes. I dont know what this means...
Appreciate your help,
ns
|
|
|
|
|
|
When the app crashes, it doesnt die from task manager processes, so I kill it. So I know that when I start the app again (after recompiling or whatever) its the one and only app running...I hope thats what you meant...
Thanks,
ns
|
|
|
|
|
Ummm... These are just guesses:- Try with
AfxGetApp()->m_pMainWnd()->PostMessage(WM_CLOSE) , although I don't think it will work any better.
- What are you doing within
OnDestroy ? Something sensible with your document? Try moving the code to OnClose .
- Is the quit message posted from a thread other than the main thread?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'm saving registry info in destroy(). Even if I comment it all out it still crashes. My response to the last post mentions a sequencing detail that might be important...
I only have one thread. I'm in the view class from which I post the message. Its not a multithreaded app.
Thanks so much,
ns
|
|
|
|