|
negativeG wrote: I want to make that instance be get focus and be the top most application.
See the InitInstance() method in this example.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks!
I had to massage it a little since I have a Dialog based app, but it is working great now!
-G
|
|
|
|
|
|
If you're using Visual Studio 2003 or later, it might be easier to use CImage[^], as that has built-in 'save as jpeg' functionality?
alexhalt wrote: But at this line
(void)jpeg_write_scanlines( &cinfo,
jsmpArray,
cinfo.image_height );
I've got the following error
Improper call to jpeg library in state 100
Looking at the code for libjpeg, 100 is the 'initialisation' state. This error would be raised by jpeg_write_scanlines if you hadn't called jpeg_start_compress.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: If you're using Visual Studio 2003 or later, it might be easier to use CImage[^], as that has built-in 'save as jpeg' functionality?
I use C, not C++.
Stuart Dootson wrote:
Looking at the code for libjpeg, 100 is the 'initialisation' state. This error would be raised by jpeg_write_scanlines if you hadn't called jpeg_start_compress.
Thanks! Now I get a better error
bRet = OpenClipboard( hwndWindow );
uFormat = CountClipboardFormats();
hClipboardData = GetClipboardData( CF_BITMAP );
hDib = DDBToDIB( ( HBITMAP )hClipboardData, BI_RGB, NULL );
lpbi = ( LPBITMAPINFOHEADER )hDib;
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * outfile;
char filename[] = "out.jpg";
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
if ((outfile = fopen(filename, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
exit(1);
}
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = lpbi->biWidth;
cinfo.image_height = lpbi->biHeight;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
{
JSAMPARRAY jsmpArray;
jsmpArray = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo,
JPOOL_IMAGE,
cinfo.image_width * cinfo.input_components,
cinfo.image_height);
DibToSamps( hDib, cinfo.image_width * cinfo.input_components, cinfo, jsmpArray );
jpeg_start_compress(&cinfo,TRUE);
(void)jpeg_write_scanlines( &cinfo,
jsmpArray,
cinfo.image_height );
Where DibToSamps() function is like here http://www.codeguru.com/cpp/g-m/bitmap/otherformats/print.php/c1731[^]
and DDBToDIB is like follows
HANDLE DDBToDIB( HBITMAP bitmap, DWORD dwCompression, HPALETTE pPal )
{
BITMAP bm;
BITMAPINFOHEADER bi;
LPBITMAPINFOHEADER lpbi;
DWORD dwLen;
HANDLE hDIB;
HANDLE handle;
HDC hDC;
HPALETTE hPal;
int nColors = 0;
BOOL bGotBits;
if( dwCompression == BI_BITFIELDS )
return NULL;
hPal = (HPALETTE) pPal;
if (hPal==NULL)
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
GetObject(bitmap,sizeof(bm),(LPSTR)&bm);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;
bi.biCompression = dwCompression;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
nColors = (1 << bi.biBitCount);
if( nColors > 256 )
nColors = 0;
dwLen = bi.biSize + nColors * sizeof(RGBQUAD);
hDC = GetDC(NULL);
hPal = SelectPalette(hDC,hPal,FALSE);
RealizePalette(hDC);
hDIB = GlobalAlloc(GMEM_FIXED,dwLen);
if (!hDIB)
{
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
*lpbi = bi;
GetDIBits(hDC, (HBITMAP)bitmap, 0L, (DWORD)bi.biHeight,
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);
bi = *lpbi;
if (bi.biSizeImage == 0)
{
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8)
* bi.biHeight;
if (dwCompression != BI_RGB)
bi.biSizeImage = (bi.biSizeImage * 3) / 2;
}
dwLen += bi.biSizeImage;
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))
{
hDIB = handle;
}
else
{
GlobalFree(hDIB);
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
lpbi = (LPBITMAPINFOHEADER)hDIB;
bGotBits = GetDIBits( hDC, bitmap,
0L,
(DWORD)bi.biHeight,
(LPBYTE)lpbi
+ (bi.biSize + nColors * sizeof(RGBQUAD)),
(LPBITMAPINFO)lpbi,
(DWORD)DIB_RGB_COLORS);
if( !bGotBits )
{
GlobalFree(hDIB);
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return NULL;
}
SelectPalette(hDC,hPal,FALSE);
ReleaseDC(NULL,hDC);
return hDIB;
}
At the bottom line of the code :
(void)jpeg_write_scanlines( &cinfo,
jsmpArray,
cinfo.image_height );
appears some ACCESS VIOLATION at address 0x10.
In the code I followed the manual, which says
Allocate and initialize a JPEG compression object
Specify the destination for the compressed data (eg, a file)
Set parameters for compression, including image size & colorspace
jpeg_start_compress(...);
while (scan lines remain to be written)
jpeg_write_scanlines(...);
But obviously it looks like I haven't preallocated something.
Please advise
|
|
|
|
|
All I can suggest is that you build libjpeg for debug (i.e. include debug information), link your application to the debug library and step through jpeg_write_scanlines and find which line causes the access violation. You can then look at the variables associated with that line and see which pointer looks suspicious (NULL, probably!).
The other thing to try would be to verify that jsmpArray has been allocated correctly and that DibToSamps has completed successfully.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello,
I would appreciate it if you help me in making a code for the UDP Ping by using C or C++.
|
|
|
|
|
ping doesn't use UDP - it's at the IP level (strictly, it uses ICMP), which is lower (closer to hardware) than UDP. See this[^] for full (very full) details.
[edit]Ah - I see what a UDP ping is - it's an effort to ping when ICMP is blocked. Look for "nmap source code" to find source for an application that will do a UDP ping. I'll give no more details than that because I'm not sure that UDP ping isn't evil.[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
modified on Wednesday, March 4, 2009 12:28 PM
|
|
|
|
|
|
FISH786 wrote: fopen_s
That's Microsoft's 'safe' version of fopen. The C standard (and any self-respecting Unix resource) will still tell you to use fopen. It's up to you.
FISH786 wrote: My question is short of going through the headear files, can someone recommend a good book or has a good documentation or a link that he/she is willing to share for the different functions.
How about the MSDN page listing all the C runtime's functions[^]?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I guess, I could supress some of the warning in my header file. On the other hand that might be a bad idea too.
I am sorry but I will be dumb and ask this short of but might be worth the effort in trying to get familliar with Visual Studio options. Is there a way I could have supressed that from the IDE environment setting?
Any sugetions? ..thanks a million for the link though.
|
|
|
|
|
FISH786 wrote: Is there a way I could have supressed that from the IDE environment setting?
Not quite - you need to put stuff in your source files - see this page[^] for details.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
thank you that was great.
|
|
|
|
|
I'm trying to insert headers to a CListCtrl.
m_cList.InsertColumn(0, "Heading 1",LVCFMT_LEFT, 100);
m_cList.InsertColumn(1, "Heading 2",LVCFMT_LEFT, 120);
Doesn't work. What do I miss here?
|
|
|
|
|
Did you specify the "Report" style for the control?
|
|
|
|
|
I do not see any property like that in the property window. How do I set it?
|
|
|
|
|
It's the 'View' property - set the 'View' property to 'Report'.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Just found it right on time, thus saving myself from saying yet another thanks to you.
|
|
|
|
|
He is no different. Just looked at his profile.
|
|
|
|
|
Okay got it thanks. It's in "view" property.
|
|
|
|
|
How do you route message to a view?
I have a CFormView. I want to handle menu events in my View. But my CFrameWnd is actually capturing the events of the Frame level. For example, I want to handle Window-maximize event from my CFormView. Or if there's a way I can route the message from CFrameWnd to CFormView, it'll be great. Any idea?
|
|
|
|
|
grassrootkit wrote: I want to handle menu events in my View. But my CFrameWnd is actually capturing the events of the Frame level
Only if you have relevant handlers in your frame?
I have a vanilla SDI app. I've just added a handler for ID_FILE_OPEN to the view class. It caught the relevant message.
For the maximize event, you will have to explicitly route the message. Add the following handler to your frame class and your view should get visibility of maximize events.
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
GetActiveView()->SendMessage(WM_SYSCOMMAND, nID, lParam);
CFrameWndEx::OnSysCommand(nID, lParam);
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Also Stuart, how do we access the Document from a Dialog that I added through "insert new dialog" in resource option?
|
|
|
|
|
Well, you would need to tell the dialog about the document. You could add a CDocument* member variable to the dialog and set it before you call DoModal .
Alternatively (and I prefer this one), just pass the relevant attributes of the document to the dialog, so the dialog doesn't need to know about the document - letting the dialog have visibility of the document class upsets my aesthetic sense.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|