|
vegeakhil wrote:
I am trying write a Windows Service Program, its job is to take Screen Capture once in while and save it as a bitmap
Is your service is DESKTOP INTERECTIVE SERVICE? if not, you always get BLANK IMAGE or Invalid HANDLE
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Yes, the service is created with SERVICE_INTERACTIVE_PROCESS property. Give me some more time I will post the code also. Thanks
|
|
|
|
|
The same Screen Capture function is working fine if I call from simple application (normal application not a service application). So I am thinking it is something to do with service.
|
|
|
|
|
Hi Guys
Pls help me...the code is , just to remind you again, if I call this function from simple application it is fine, but if I call from windows service, BitBlt is failing with "Invalid Handle".
Thanks
BOOL CFrameBuffer::CaptureScreen(CRect rectScreen, BYTE *scrBuff)
{
HBITMAP hDesktopCompatibleBitmap=NULL;
HDC hDesktopCompatibleDC=NULL;
HDC hDesktopDC=NULL;
HWND hDesktopWnd=NULL;
int nHeight=rectScreen.bottom-rectScreen.top;/GetSystemMetrics(SM_CXSCREEN);
int nWidth=rectScreen.right-rectScreen.left;//GetSystemMetrics(SM_CYSCREEN);
hDesktopWnd=GetDesktopWindow();
hDesktopDC=::GetDC(NULL);
hDesktopCompatibleDC=CreateCompatibleDC(hDesktopDC);
hDesktopCompatibleBitmap=CreateCompatibleBitmap(hDesktopDC,nWidth,nHeight);
BOOL bRet = FALSE;
HBITMAP oldbitmap;
oldbitmap = (HBITMAP)SelectObject(hDesktopCompatibleDC,hDesktopCompatibleBitmap);
if(hDesktopCompatibleDC && hDesktopDC)
{
bRet = BitBlt(hDesktopCompatibleDC,0,0,nWidth,nHeight,hDesktopDC,0,0,SRCCOPY);
}
OPENFILENAME ofn;
char szFileName[512]; szFileName[0]='\0';
ZeroMemory(&ofn,sizeof(ofn));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST;
ofn.lpstrFilter="Bitmap Files (*.bmp)\0*.bmp\0";
ofn.lpstrDefExt="bmp";
strcpy(szFileName,"C:\\temp\\MyBitmap.bmp");
ofn.lpstrFile=szFileName;
ofn.nMaxFile=512;
CFileFind finder;
if(finder.FindFile(szFileName))
{
DeleteFile(szFileName);
}
SetCursor(LoadCursor(NULL,IDC_WAIT));
BITMAPINFO bi;
void *pBits=NULL;
ZeroMemory(&bi,sizeof(bi));
bi.bmiHeader.biSize=sizeof(bi.bmiHeader);
bi.bmiHeader.biHeight=nHeight;
bi.bmiHeader.biWidth=nWidth;
bi.bmiHeader.biPlanes=1;
bi.bmiHeader.biBitCount=32;//16 bit
bi.bmiHeader.biCompression=BI_RGB;
bi.bmiHeader.biSizeImage=nWidth*nHeight *sizeof(DWORD);
bi.bmiHeader.biHeight = abs(nHeight);
HDC hBmpFileDC=CreateCompatibleDC(hDesktopCompatibleDC);
HBITMAP hBmpFileBitmap=CreateDIBSection(hDesktopCompatibleDC,&bi,DIB_RGB_COLORS,&pBits,NULL,0);
SelectObject(hBmpFileDC,hBmpFileBitmap);
BitBlt(hBmpFileDC,0,0,nWidth,nHeight,hDesktopCompatibleDC,0,0,SRCCOPY);
HANDLE hFile=CreateFile(szFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile!=INVALID_HANDLE_VALUE)
{
DWORD dwRet=0;
BITMAPFILEHEADER bmfHeader;
ZeroMemory(&bmfHeader,sizeof(bmfHeader));
bmfHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bmfHeader.bfSize=bi.bmiHeader.biSizeImage+bmfHeader.bfOffBits;
bmfHeader.bfType='MB';
WriteFile(hFile,&bmfHeader,sizeof(bmfHeader),&dwRet,NULL);
WriteFile(hFile,&bi.bmiHeader,sizeof(bi.bmiHeader),&dwRet,NULL);
WriteFile(hFile,pBits,bi.bmiHeader.biSizeImage,&dwRet,NULL);
CloseHandle(hFile);
AddToMessageLog(" Inside 2 CaptureScreen() is called", 1 );
}
if(scrBuff!=NULL)
{
memcpy(scrBuff,pBits,bi.bmiHeader.biSizeImage);
}
SelectObject(hDesktopCompatibleDC,oldbitmap);
DeleteDC(hBmpFileDC);
DeleteObject(hBmpFileBitmap);
ReleaseDC(hDesktopWnd,hDesktopDC);
return TRUE;
}
|
|
|
|
|
How do i create a function which accepts the same parameters as printf(...)?
In stdio.h, printf is declared as
_CRTIMP int __cdecl printf(const char *, ...); I tried creating a similar function
void test(const char *pStr, ...)
{
printf(pStr);
} However, test(...) display differently from the actual printf(...) call. What am i missing?
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
The ... represents a parameter collection of unknown size. Zero is an acceptable size, so your code ends up calling successfully, but gives printf nothing to do.
This[^] took me ages to find, none of the words I was searching on was specific enough to avoid a thousand hits to basic C++ pages, as ... appears all over the place.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for the link. It certainly explains some 'behind the scene' stuff.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
The fuction below represents that last time I remember having to do this:
int my_printf( const char *format,... )
{
int n=-1;
char *buf=NULL;
size_t size=0;
va_list ap;
va_start( ap,format );
while( n == -1 ) {
size += 128;
if( buf ) free(buf);
buf = (char *)malloc(size);
if( !buf ) n = 0;
else n = _vsnprintf(buf,size,format,ap);
}
va_end(ap);
my_print(buf);
return n;
}
The _vsnprintf() function is still supported by VC6, so it still works. The key is the va_list(), va_start() and va_end() (macros I believe). You'll need to look them all up and may be bring them upto date (this was written around 1992).
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
Thanks. Your code works just like printf. Now i need to see if this would run well on unix.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
|
Thanks for the links. I should have search the articles section first.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Very new to c++.
I need to extract specific data from a comma delimited file and then and created a new comma delimited file with the extracted data.
Help is appreciated
Thanks
Joe M
|
|
|
|
|
This makes no since (it would be simple to do your self), but someone at MS thought differently.
CopyFile() or CopyFileEx().
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
i want to apply ado to access database. i put following in my stdafx.h
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "adoEOF")
but when i compile ,there are "error C2011: 'LockTypeEnum' : 'enum' type redefinition".
what should i change no_namespace into?
|
|
|
|
|
the bit at the end that says rename ("EOF", "adoEOF") could possibly also be used to rename LockTypeEnum ( I don't know for sure ). Or you could check where the clash is and fix it at the other end ( the other place that defines LockTypeEnum ). Or you can remove it entirely, which means that ADO will be imported within a namespace.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a linked list each node of it hase (name,phone....)
I want to sort it by name
struct PhoneBookEntry
{
CString Name,Email,Website,Adress;
CString OfPhone,HoPhone,Mobile;
};
typedef CList<phonebookentry *,="" phonebookentry="" *=""> PhoneBook;
PhoneBookEntry* InputEntry()
{
PhoneBookEntry* pEntry = new PhoneBookEntry;
cout << " Enter New Contact Details:" << endl;
cout << " Name : ";
char cName[100];
gets(cName);
return pEntry;
}
void main()
int nChoice
switch (nChoice)
{
case 1: // add contact
PhoneBookEntry *pEntry;
pEntry = InputEntry();
g_PhoneBook.AddTail(pEntry);
break;
case 2: // list entries
pos = g_PhoneBook.GetHeadPosition();
while (pos)
{
PhoneBookEntry* pEntry = g_PhoneBook.GetNext(pos);
PrintEntry(pEntry);
}
break;
|
|
|
|
|
|
how can I switch to std::list, and use std::sort. ??!
I didnt understand.....sorry
|
|
|
|
|
The list container is part of the STL.
Simple sort example:
<br />
#include "stdafx.h"<br />
<br />
#include <list><br />
#include <algorithm>
<br />
bool sortAscending(int a, int b)<br />
{<br />
return (a < b);<br />
}<br />
<br />
bool sortDescending(int a, int b)<br />
{<br />
return (b < a);<br />
}<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
std::list<int> myList;<br />
<br />
myList.push_back(2);<br />
myList.push_back(1);<br />
myList.push_back(4);<br />
<br />
std::cout << "Before sort" << std::endl;<br />
for (std::list<int>::iterator i = myList.begin(), iEnd = myList.end();<br />
i != iEnd; ++i)<br />
{<br />
std::cout << (*i) << std::endl;<br />
}<br />
<br />
myList.sort(sortAscending);<br />
<br />
std::cout << "Ascending sort" << std::endl;<br />
for (std::list<int>::iterator i = myList.begin(), iEnd = myList.end();<br />
i != iEnd; ++i)<br />
{<br />
std::cout << (*i) << std::endl;<br />
}<br />
<br />
myList.sort(sortDescending);<br />
<br />
std::cout << "Descending sort" << std::endl;<br />
for (std::list<int>::iterator i = myList.begin(), iEnd = myList.end();<br />
i != iEnd; ++i)<br />
{<br />
std::cout << (*i) << std::endl;<br />
}<br />
<br />
return 0;<br />
}<br />
|
|
|
|
|
is this sort int or sting?
I need to soet strings
|
|
|
|
|
Read up on the Standard Template Library (STL).
The purpose of this library is the containers (such as lists) and be applied to any data type, it is universal.
Elaine
The tigress is here
|
|
|
|
|
How can I change the color of my comments in the IDE? Sometimes I make changes to my code and want to make them the code or maybe the comments red. I am using VStudio.net.
Jerry
|
|
|
|
|
|
I have 2 functions that need to communicate with the same device using the same COM Port. Problem is sometimes they do so at the sametime and end up reading the wrong data. Is there anyway that I can have both use the same comport without having this conflict?
I thought about Overlapped I/O, but I am not all to familiar with how to implement it and am not sure if it will solve my problem.
Thanks
|
|
|
|
|
Brute force method:
Add a comport_status flag and a pair of functions to set and check the status - BUSY or NOT_BUSY - then modify each I/O function to test the port status before attempting to use it. BUSY would be set by the function just prior to using the port, then on completion, it would reset the status to NOT_BUSY. There are certainly more elegant ways to do this, but it's one approach.
"...putting all your eggs in one basket along with your bowling ball and gym clothes only gets you scrambled eggs and an extra laundry day... " - Jeffry J. Brickley
|
|
|
|
|