|
The image control expects a pointer to the start of the image: It gets it from disk with stuff like:
pFile = fopen(strFile, "rb");
if(pFile == 0)
{
return 0;
}
fseek(pFile, 0, SEEK_END);
int fileSize = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
if(pImage ==NULL) return fileSize;
fread(<code>pImage</code>, fileSize, 1, pFile);
pImage[fileSize] = 0;
fclose(pFile);
What I want to extract from the bitmap resource is the pImage
Thanks so much,
ns
|
|
|
|
|
So you'll need extra BITMAPFILEHEADER before DIB section. Sooner or later your image control will need a handle to DIB or DDB. Are you absolutely sure your control only loads .bmp files?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
No, it takes jpegs and tiffs too but it uses the same strategy (fread) and processes the pre-DIB section information in itself. But I have a bmp to deal with. I've not read up on DIB, DDB etc, and am learning as I go along. So I guess (sorry if I'm being unbelievably dense), what I want is somehow to get the pImage out from the resource. Is there something like:
char* pImage = Somefunction(IDB_BMP1);
Any links would be great. Meanwhile I'm hurrying along with my background reading. I did find how to get (I hope it works) to get at the colortable:
HGlobal pBMP = ::LoadResource(NULL, ::FindResource(NULL, MAKEINTRESOURCE(ID), RT_BITMAP));
PBITMAPINFO pBMInfo = (PBITMAPINFO) (pBMP + sizeof(BITMAPFILEHEADER));
int bitCount = 8;
int clrUsed = 0;
if (pBMInfo->bmiHeader.biBitCount != bitCount ||
pBMInfo->bmiHeader.biClrUsed != clrUsed )
return;
memcpy(pPalette, pBMInfo->bmiColors, (4*clrUsed));
I havent tried it out yet. Surely this pBMP is not what I'm looking for? I need a char* back, and not sure what to do with an HGlobal.
|
|
|
|
|
The code you've posted isn't correct. The bitmaps stored as resource doesn't have BITMAPFILEHEADER structure; they start with BITMAPINFOHEADER.
You'll have to create a memory buffer and copy BITMAPFILEHEADER followed by stuff loaded with LoadResource call.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Okay. Thanks. A little digression. I removed the offset for the fileheader and tried to access the color table like this: but no luck!
char* pBMP = (char*) ::LoadResource(NULL, ::FindResource(NULL, MAKEINTRESOURCE(IDB_BITMAP1), RT_BITMAP));
PBITMAPINFO pBMInfo = (PBITMAPINFO) (pBMP );
int bitCount = 8;
int clrUsed = 0;
if (pBMInfo->bmiHeader.biBitCount != bitCount ||
pBMInfo->bmiHeader.biClrUsed != clrUsed )
return;
memcpy(pPalette, pBMInfo->bmiColors, (4*clrUsed));
What am I doing wrong? THanks for all this help!
|
|
|
|
|
clrUsed is zero. 4 * clrUsed is zero as well.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Yikes. I needed to bitshift it to 256. Many thanks. It looks good now. A big problem resolved!
ns
|
|
|
|
|
How do you execute the MapNetwork drive wizard? (and disconnect drive)
Is there any other method than trying to simulate a context menu command on MyComputer?
Asim Hussain
e: asim@jawache.net
w: www.jawache.net
|
|
|
|
|
BOOL CAMIDoc::MountNetworkDrive()<br />
{<br />
CString sDrive;<br />
<br />
BeginWaitCursor();<br />
while (TRUE)<br />
{<br />
if( (_access( "\\\\apps1\\data", 0 )) == -1 )<br />
{<br />
CDriveMountDlg dlg;
int response = dlg.DoModal();<br />
if (response == IDCANCEL)<br />
return FALSE;<br />
<br />
NETRESOURCE resource;<br />
resource.dwType = RESOURCETYPE_ANY;<br />
resource.lpRemoteName = "\\\\apps1\\data";<br />
resource.lpProvider = NULL;<br />
<br />
int nDrive = 4;<br />
<br />
sDrive.Format("%c:", nDrive + 'A');<br />
resource.lpLocalName = sDrive.GetBuffer(2);<br />
<br />
DWORD result = WNetAddConnection2(&resource, (LPCSTR)dlg.m_sPassword, NULL, 0);<br />
if (result == ERROR_INVALID_PASSWORD)<br />
{<br />
AfxMessageBox("Invalid password. Aborting");<br />
return FALSE;<br />
}<br />
<br />
while ((result != 0) && (nDrive < 25))<br />
{<br />
nDrive++;<br />
sDrive.Format("%c:", nDrive + 'A');<br />
result = WNetAddConnection2(&resource, (LPCSTR)dlg.m_sPassword, NULL, 0);<br />
}<br />
<br />
if (result != 0)<br />
{<br />
AfxMessageBox("Unable to mount a drive. Please check password and ensure you have a free drive letter. Aborting.");<br />
}<br />
else<br />
{<br />
m_sDrive = sDrive;<br />
m_bMountFlag = TRUE;<br />
break;<br />
}<br />
}<br />
else<br />
break;<br />
}<br />
<br />
EndWaitCursor();<br />
return TRUE;<br />
}<br />
<br />
BOOL CAMIDoc::DismountNetworkDrive()<br />
{<br />
if (m_bMountFlag)<br />
{<br />
DWORD result = WNetCancelConnection2(m_sDrive, 0, TRUE);<br />
if (result != NO_ERROR)<br />
{<br />
result = GetLastError();<br />
if (result == ERROR_BAD_PROFILE)<br />
{<br />
m_bMountFlag = FALSE;<br />
}<br />
else if (result == ERROR_CANNOT_OPEN_PROFILE)<br />
{<br />
m_bMountFlag = FALSE;<br />
}<br />
else if (result == ERROR_DEVICE_IN_USE)<br />
{<br />
m_bMountFlag = FALSE;<br />
}<br />
else if (result == ERROR_EXTENDED_ERROR)<br />
{<br />
m_bMountFlag = FALSE;<br />
}<br />
else if (result == ERROR_NOT_CONNECTED)<br />
{<br />
m_bMountFlag = FALSE;<br />
}<br />
else if (result == ERROR_OPEN_FILES)<br />
{<br />
m_bMountFlag = FALSE;<br />
}<br />
return FALSE;<br />
}<br />
}<br />
return TRUE;<br />
<br />
}
|
|
|
|
|
I've got a CStatic with more text than gets into the window, and would like to make the text scroll programmatically. CEdit s do have LineScroll which do precisely what I want, but alas this method is not available for static controls. Does anyone know some custom-made routine or anything to achieve this behavior? The thing can be replicated with CWnd::SCrollWindow and all that stuff, but details are clumsy and maybe someone has already done the work
Thanx
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Is read-only edit control an option?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
It's almost an option, but notentirely: this way, the cursor appears, and I don't like any cursors around. Also, disabling the edit control gets me almost there, but the text is grayed and I want it black (do you know how to change this?).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
this way, the cursor appears, and I don't like any cursors around
You mean the insertion point cursor, right? So maybe handling WM_SETCURSOR will get rid of this problem?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
I tried, and it doesn't seem to work (the docs says one should return TRUE from the parent to stop further processing to the childs). Anyway, I guess this has to do with the mouse rather than the text cursor.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
the docs says one should return TRUE from the parent to stop further processing to the c
So you handled WM_SETCURSOR in parent right? Maybe you should add handler in edit clas, do not call base class implementation and just set cursor to standard arrow instead?
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Have just tried it, returning TRUE and FALSE --nothing. I guess this message has nothing to do with text cursors, but rather it is suposed to handle mouse icons and stuff.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Wait - what do you mean by 'text cursor'? A caret? This blinking | thing? In this case, you'd have to probably handle WM_SETFOCUS (or EN_SETFOCUS) and call HideCaret.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|
|
Yes, I refer to the | blinking thing. I've finally found a solution: it doesn't involve handling those messages, but rather cheating the system with the enabling/disabling thing by handling WM_ENABLE . I found this trick here[^].
Thank you very much for your efforts. Keep the good work helping people here at CP!
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'm not to sure there is a way to do this easily, Basically within my OnWizNext I validate data, if this fails, I want to drop out of the wizard process for the user to modify data. I was hoping to be able to call OnCancel() however this doesnt work, has anyone any ideas?
|
|
|
|
|
Popup a messagebox, tell some data error and return without call base class
overload function "OnWizNext"
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
Hi all,
I am using msado15.dll in my application by #import directive
as follows
#import "msado15.dll"\
no_namespace rename("EOF", "EndOfFile")
while compiling i am getting the following warning
"\debug\msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned"
can any one explain me why this warning hapens and what is the solution.
Thanks in advance
anju
|
|
|
|
|
This is an MS bug, Q253317. It can safely be ignored, as I have been doing so for years. The quickest way to avoid seeing it is to change your import statement to the following:
#pragma warning( push )
#pragma warning( disable: 4146 )
#import "c:\program files\common files\system\ado\MSADO15.DLL" no_namespace rename( "EOF", "EndOfFile" )
#pragma warning(pop)
</code>
HTH-
Ty
|
|
|
|
|
Hi TyMatthews,
Thanks a lot now code is working fine.
anju
|
|
|
|
|
I'm using _ftime64(__timeb64) to obtain the system time. but when compiling, I receive "unknown identifier"-errors.
include files (found on msdn):
#include "time.h"
#include "sys/types.h"
#include "sys/timeb.h"
code (found on msdn):
struct __timeb64 timebuffer;
char *timeline;
_ftime64( &timebuffer );
timeline = _ctime64( & ( timebuffer.time ) );
Have I forgotten an include file?
Is there a better way?
tnx
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Grote Smurf (aka frisco) wrote:
Is there a better way?
I'm not sure it's actually a better way, but you need VC.NET for ctime64. If you prefer to use VC6, then ctime (without 64) is your only choice.
Tomasz Sowinski -- http://www.shooltz.com
To some its a six-pack, to me it's a support group
|
|
|
|