Click here to Skip to main content
15,860,844 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCListCtrl Get selection? Pin
Johpoke5-Dec-07 21:28
Johpoke5-Dec-07 21:28 
AnswerRe: CListCtrl Get selection? Pin
CPallini5-Dec-07 21:50
mveCPallini5-Dec-07 21:50 
GeneralRe: CListCtrl Get selection? Pin
Johpoke5-Dec-07 22:14
Johpoke5-Dec-07 22:14 
GeneralRe: CListCtrl Get selection? Pin
Nelek5-Dec-07 22:58
protectorNelek5-Dec-07 22:58 
AnswerRe: CListCtrl Get selection? Pin
David Crow6-Dec-07 3:01
David Crow6-Dec-07 3:01 
GeneralReceive LVN_BEGINDRAG in parent dialog of CListCtrl, but no LVN_ENDDRAG Pin
followait5-Dec-07 21:25
followait5-Dec-07 21:25 
Generalyyuuyuu Pin
vghh5-Dec-07 21:16
sussvghh5-Dec-07 21:16 
General16 bit image using Bitmap or TIFF using VC++ (MFC control) Pin
sunny.rana5-Dec-07 21:10
sunny.rana5-Dec-07 21:10 
i have a CCD camera that acquires 12 bit image and i have used MFC function BitMapInfoheader function to save it as 8 bit as a result my image displayed is compressed and i loose finer details could u please help to correct my code for 16 bit the code is as below.

Thank you in advance

./* Window.C */
#include "stdafx.h"
#include "afxstr.h"
#include "atlimage.h"
#include "string.h"

extern "C"
{
#include
#include "wingdi.h"
#include "win.h"
#include "master.h"

}


#define ALIGNLONG(i) ((i+3)/4*4)
#define COLORBITS 8

CImage image;
void Draw_Strip( HWND hWnd );
HBRUSH ghbrWhite, ghbrBlack;
void Create_DIB( HWND wnd );
void Draw_DIB( HWND wnd );

/*
* Some handy globals.
*/
CString fullname;
int W, H;
unsigned int Min,Max;
static HBITMAP hBitmap;
static LPBITMAPINFOHEADER lpbi;
static BITMAPINFOHEADER bi;
char *lpstBitmap;
HPALETTE palette;

CString name = "Image";
//CImage image;


/**************************************************
*
* Register this type of window...
*
*
**************************************************/
BOOL RegisterWindow(char *lpClass, HINSTANCE instance)
{
WNDCLASS wc;

ghbrWhite = CreateSolidBrush(0x00FFFFFF);
ghbrBlack = CreateSolidBrush(0x00000000);

wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) ImageWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = sizeof(LONG);
wc.hInstance = instance;
wc.hIcon = LoadIcon(NULL,IDC_ARROW);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = ghbrWhite;
wc.lpszMenuName = NULL;
wc.lpszClassName = lpClass;

if (!RegisterClass(&wc))
return FALSE;

else
return TRUE;

}

/**************************************************
*
* Create and show the window....
*
*
**************************************************/
HWND CreateWin( int x,
int y,
int width,
int height,
char *lpClass,
char *name,
HINSTANCE instance)
{
HWND handle;
W = width;
H = height;
handle = CreateWindow(
lpClass, // pointer to registered class name
name, // pointer to window name
WS_VISIBLE | WS_OVERLAPPEDWINDOW, //| WS_VSCROLL | WS_HSCROLL, // window style
x, // horizontal position of window
y+20, // vertical position of window
width, // window width
height, // window height
NULL, // handle to parent or owner window
NULL, // handle to menu or child-window identifier
instance, // handle to application instance
NULL // pointer to window-creation data
);

return (handle);

}

/**************************************************
*
* Handles the messages for this window
*
*
**************************************************/
int WINAPI ImageWndProc(
HWND hwnd,
UINT message,
DWORD wParam,
LONG lParam)
{
switch (message)
{
case WM_PAINT:

Draw_DIB( hwnd );


return 0L;
break;
case WM_SIZE:
return DefMDIChildProc(hwnd, message, wParam, lParam);
break;
case WM_CREATE:
Create_DIB( hwnd );

return 0L;
break;

case WM_CLOSE:

return DefMDIChildProc(hwnd, message, wParam, lParam);
break;

case WM_DESTROY:

return DefMDIChildProc(hwnd, message, wParam, lParam);

break;

default:
return DefMDIChildProc(hwnd, message, wParam, lParam);
break;
}

}

/**************************************************
*
* Create a Device Independent Bitmap...
*
*
**************************************************/
void Create_DIB( HWND hWnd )
{

HDC hDC;
unsigned char i;
long k,j, NumBytes;
LPBITMAPINFO info;
unsigned char *dat;
DWORD error;

hDC = GetDC (hWnd) ;
// Intialize BITMAPINFOHEADER data.
//.................................
bi.biSize = sizeof (BITMAPINFOHEADER) ;
bi.biWidth = W;
bi.biHeight = -H; // top-down DIB
bi.biPlanes = 1;
bi.biBitCount = COLORBITS;
bi.biCompression = BI_RGB;
bi.biSizeImage = ( ALIGNLONG( (W * COLORBITS)/8 ) * H);
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 256;
bi.biClrImportant = 256;


// Allocate memory for BITMAPINFO structure.
//..........................................
NumBytes = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); // +
//( ALIGNLONG( ( W * COLORBITS ) / 8 ) * H );

lpbi = (BITMAPINFOHEADER*)GlobalAlloc( GPTR, NumBytes );

if( lpbi == NULL )
{
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf, 0, NULL );
// Display the string.
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
// Free the buffer.
LocalFree( lpMsgBuf );

exit( EXIT_FAILURE ); // Get out now!
}

// Copy BITMAPINFOHEADER information.
//...................................
*lpbi = bi;

// Create The Palette
info = (LPBITMAPINFO) lpbi;


for ( i=0; i<255; i++ )
{
info->bmiColors[i].rgbRed = i;
info->bmiColors[i].rgbBlue = i;
info->bmiColors[i].rgbGreen = i;
info->bmiColors[i].rgbReserved = 0;
}

// Set pointer to bitmap’s bit data.
//..................................
// lpstBitmap = (LPSTR)lpbi + (WORD)sizeof(BITMAPINFOHEADER) +
// (256 * sizeof(RGBQUAD));

hBitmap = ::CreateDIBSection(hDC,(LPBITMAPINFO)lpbi, DIB_RGB_COLORS,(VOID **)&lpstBitmap, NULL,0);
dat = (unsigned char*)lpstBitmap;

for ( k=0; k< H; k++ )
for ( j = 0; j < W; j++ )
*dat++ = (unsigned char)k;

// Create uninitialized DIB bitmap.
//.................................
/* hBitmap = CreateDIBitmap( hDC,
&bi,
0 ,
0,
(LPBITMAPINFO) lpbi, */




error = GetLastError();


ReleaseDC( hWnd, hDC);



}

void Save(int num)
{

CString prefix = "C:\\Documents and Settings\\Garner Lab\\My Documents\\Hyperspectimages\\image";
char buf[4];
itoa(num, buf, 10);
CString number = buf;
CString suffix = ".bmp";
fullname = prefix + number + suffix;
CImage image;
image.Attach(hBitmap);
image.Save(fullname); // save as BMP
image.Detach();
}
/**************************************************
*
* Force repaint and update the display...
*
*
**************************************************/
void Draw_DIB( HWND hWnd )
{
PAINTSTRUCT ps;
HDC hMemDC;
int scan;
DWORD lasterror;


BeginPaint( hWnd, &ps );
hMemDC = CreateCompatibleDC( ps.hdc );

SelectPalette(hMemDC, palette, TRUE);
RealizePalette(hMemDC);
SelectPalette(ps.hdc, palette, TRUE);
RealizePalette(ps.hdc);


scan = SetDIBits(
hMemDC, // handle of device context
hBitmap, // handle of bitmap
0, // starting scan line
H, // number of scan lines
lpstBitmap, // array of bitmap bits
(LPBITMAPINFO) lpbi, // address of structure with bitmap data
DIB_RGB_COLORS ); // type of color indices to use



if ( !scan )
lasterror = GetLastError();
SelectObject( hMemDC, hBitmap );

BitBlt( ps.hdc, 0, 0, W, H,
hMemDC, 0, 0, SRCCOPY );
DeleteDC( hMemDC );

EndPaint( hWnd, &ps );




}


/**************************************************
*
* Set the bits to the bitmap to be displayed...
*
*
**************************************************/
void Update_Bitmap( HWND hwnd, unsigned short *data, int AutoStop )
{
// Alter The Bits via the pointer
int i,j;
unsigned char *dbits = (unsigned char*)lpstBitmap;
unsigned short *head;
static float mp;
unsigned int max, min;

max = 0;
min = 65535;
head = data;


/* Calculate Scaling Factor */
for (i=0; i for (j=0;j {
if ( min > *head ) min = *head;
if ( max < *head ) max = *head;
head++;
Min = min;
Max = max;
}

mp = (float)256 / ( (float)max-(float)min );

/* Transfer Data to 8 bits */
for (i=0; i for ( j=0;j
*dbits++ = (unsigned char)(((float)*data++ - (float)min)*mp);


// force repaint
InvalidateRect( hwnd, NULL, FALSE );

if( AutoStop ); // Get rid of compiler warning
}
GeneralRe: 16 bit image using Bitmap or TIFF using VC++ (MFC control) Pin
CPallini5-Dec-07 21:38
mveCPallini5-Dec-07 21:38 
GeneralInternet Printing Pin
Rajeev Verma5-Dec-07 20:48
Rajeev Verma5-Dec-07 20:48 
GeneralRe: Internet Printing Pin
Nelek5-Dec-07 22:56
protectorNelek5-Dec-07 22:56 
QuestionGetWindowModuleFileName (Succeed/Failed) ? Pin
nitin35-Dec-07 20:16
nitin35-Dec-07 20:16 
AnswerRe: GetWindowModuleFileName (Succeed/Failed) ? Pin
Naveen5-Dec-07 20:43
Naveen5-Dec-07 20:43 
GeneralRe: GetWindowModuleFileNameEx (Succeeded ! ) Pin
nitin35-Dec-07 21:12
nitin35-Dec-07 21:12 
GeneralWriteFIle() to serial port. Pin
Anu_Bala5-Dec-07 20:14
Anu_Bala5-Dec-07 20:14 
GeneralRe: WriteFIle() to serial port. Pin
CPallini5-Dec-07 21:25
mveCPallini5-Dec-07 21:25 
QuestionCListCtrl : How to un-select item in the list programmatically ? Pin
xanagan6665-Dec-07 19:51
xanagan6665-Dec-07 19:51 
AnswerRe: CListCtrl : How to un-select item in the list programmatically ? Pin
Naveen5-Dec-07 20:50
Naveen5-Dec-07 20:50 
QuestionHow do I detect the audio/video capabilities on machine Pin
jit_knit5-Dec-07 18:45
jit_knit5-Dec-07 18:45 
GeneralSaving PowerpointSlide as Bitmap From a Win32 Api based Application Pin
niloy5-Dec-07 18:20
niloy5-Dec-07 18:20 
Questionabout pdf library. Pin
keyto5-Dec-07 18:12
keyto5-Dec-07 18:12 
GeneralRe: about pdf library. Pin
Hamid_RT5-Dec-07 18:29
Hamid_RT5-Dec-07 18:29 
QuestionRe: about pdf library. Pin
keyto5-Dec-07 19:05
keyto5-Dec-07 19:05 
GeneralFill CListCtrl with Images, about 20 images, performance problem Pin
followait5-Dec-07 17:09
followait5-Dec-07 17:09 
GeneralRe: Fill CListCtrl with Images, about 20 images, performance problem Pin
Hamid_RT5-Dec-07 18:28
Hamid_RT5-Dec-07 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.