|
Yeah that was a bit vague I suppose. But I've got to be careful, in case they see me...
Anyhow it was problems related to activation - which window was getting highlighted (or not). Turns out I was forgetting to forward the msg along to the default wndproc. I think I have it sort of fixed now.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Assuming MFC...
Attempt #1: You can CreateEx() with WS_POPUP style but that will deactivate your app while the popup is up and your popup window will show up in the taskbar.
Attempt #2: You can give it an extended style of WS_EX_TOOLWINDOW to prevent the taskbar entry but that doesn't solve the deactivated application problem.
The solution is to avoid WS_POPUP and use CreateEx() with an extended style of WS_EX_TOOLWINDOW, style of WS_CHILD, and make the parent the desktop window.
There are other issues to contend with but that will get you a window that can extend beyond the window of your application.
Hope that helps.
|
|
|
|
|
Thanks for the pointers! Yes that helped.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
I have successfully used SetDIBitsToDevice to copy a bitmap to the current job's window on the screen; but I cannot find a function GetDIBitsFromDevice. Please how could I copy the whole of the user area (i.e. not the edging) of the current job's window onto a bitmap?
|
|
|
|
|
Anthony Appleyard wrote: Please how could I copy the whole of the user area (i.e. not the edging) of the current job's window onto a bitmap?
If you are using MFC, try something like:
CDC dc;
HDC hdc = ::GetDC(wnd->m_hWnd);
dc.Attach(hdc);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CRect r;
wnd->GetClientRect(&r);
CSize sz(r.Width(), r.Height());
CBitmap bm;
bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);
CBitmap *oldbm = memDC.SelectObject(&bm);
memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, 0, 0, SRCCOPY);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks; but I want to copy the screen into a bitmap specified by a BITMAPINFO and an array of bytes, using the plain old Windows API functions.
|
|
|
|
|
Anthony Appleyard wrote: copy the screen into a bitmap specified by a BITMAPINFO and an array of bytes, using the plain old Windows API functions
RECT rct;
HWND wnd = ::GetDesktopWindow();
::GetWindowRect(wnd,&rct);
HDC hDC = ::GetDC(NULL);
int iWidth = rct.right - rct.left;
int iHeight = rct.bottom - rct.top;
BITMAPINFOHEADER BMI;
BMI.biSize = sizeof(BITMAPINFOHEADER);
BMI.biWidth = iWidth;
BMI.biHeight = -iHeight;
BMI.biPlanes = 1;
BMI.biBitCount = 32;
BMI.biCompression = BI_RGB;
BMI.biSizeImage = 0;
BMI.biXPelsPerMeter = 0;
BMI.biYPelsPerMeter = 0;
BMI.biClrUsed = 0;
BMI.biClrImportant = 0;
BYTE *pSrcBits;
HBITMAP hbmSrc = ::CreateDIBSection(hDC, (BITMAPINFO *)&BMI,DIB_RGB_COLORS, (void **)&pSrcBits,NULL,0);
HDC dc = ::CreateCompatibleDC(NULL);
HBITMAP hbm = (HBITMAP)::SelectObject(dc, hbmSrc);
::SetStretchBltMode(dc, HALFTONE);
::BitBlt(dc,0,0,iWidth,iHeight,hDC,0,0,SRCCOPY);
HBITMAP hOld = (HBITMAP)::SelectObject(dc, hbm);
::SelectObject(dc,hOld);
::ReleaseDC(wnd,hDC);
::DeleteDC(dc);
::DeleteObject(hbmSrc);
Best Wishes,
-David Delaune
|
|
|
|
|
|
|
void main()
{
char *buffer = new char[];
int n, a=5, b=3;
n = sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("[%s] is a %d char long string\n",buffer,n);
delete [] buffer; // THIS LINE THROWS an error
}
I need to have a dynamic array as shown, if i try to clean up the array, throws an exception. Any help will be great. Has to be in C++ only, no MFC please.
I am using visual Studio 6.0.
Thanks,
Saleem
|
|
|
|
|
what about allocating the array with a valid size ?
|
|
|
|
|
The issue here is i do not know the size of the array.
It has to be dynamic.
|
|
|
|
|
Md Saleem Navalur wrote: char *buffer = new char[];
Based on your example, you'd need, at most, 41 bytes. I wouldn't bother Windows' memory manager for such a minuscule amount.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You need to allocate a buffer having at least as many characters as string length plus 1 (string terminator). Since you don't know a priori what is the string length, then you may allocate a relatively large buffer. For instance:
char * buffer = new char[256];
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
char *buffer = new char[256]...
this can also be declared as
char buffer[1024]....
But the issue here is i do not know the size of the array.
It has to be dynamic.
|
|
|
|
|
Md Saleem Navalur wrote: But the issue here is i do not know the size of the array.
It has to be dynamic.
Then you have a design decision to make. If you only need a few thousand bytes, create a stack-based variable. Otherwise, if the difference between the least amount required and the max amount required is only a few hundred KB, then create a heap-based variable using the max amount. Lastly, employ the use of a string , vector , or similar data structure.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
char *buffer = new char[];
int n, a=5, b=3;
n = sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("[%s] is a %d char long string\n",buffer,n);
Md Saleem Navalur wrote: But the issue here is i do not know the size of the array.
It has to be dynamic.
Actually the issue is that you haven't allocated any memory prior to calling sprintf . Your call to sprintf is overrunning the buffer since the buffer has no size. sprintf doesn't allocate it for you - you must do that prior to calling the function. After you've overrun the buffer, all bets are off on anything else working correctly.
The "new" sprintf_s functions accept a length-of-buffer indicator to avoid an overrun like this.
Judy
|
|
|
|
|
It would probably be better to go with 257 bytes, just in case.
|
|
|
|
|
Nope. The options are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, well you know how to go on.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Nope. The options are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, well you know how to go on.
lol -- I wonder if there is any correlation between age/language/education and the habit of declaring arrays sized by powers of 2. I always have.
|
|
|
|
|
I think the correlation is with age. But it is sporadic, for instance it happened to me first when I was 16, then on my 32. Well you know how to go on.
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
|
see _scprintf[^] which returns the number of characters in the formatted string. you can use the count to dynamically allocate the buffer that is to be passed to sprintf.
if you have only static hardcoded format string such as "%d plus %d is %d" you can manually calculate the formatted string length as %d formats an integer and you know the maximum and minimum value of integer.
|
|
|
|
|
Hi all,
I've to develop and application that must satisfy some
"real time like" requirements.
The application has to do something periodically; the period
is about 10 milliseconds and it must be very accurate:
it cannot be affected by operations done in the user interface
like mouse moving or window resizing.
What's the best timer to solve this requirement ?
Is it multimedia timer ? or there are better timers ?
Thanks a lot
|
|
|
|
|
On a standard windows platform ? If yes, forget about it because windows is not a real-time operating system. You can have jitter varying up to 10 msec and there's no way to control that. You'll have to use another operating system for that (WinCE for example, which has a different scheduler).
|
|
|
|
|