Click here to Skip to main content
15,892,927 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: String to integer array algorithm Pin
Llasus21-Jun-07 13:39
Llasus21-Jun-07 13:39 
GeneralMFC Bitmap Help [modified] Pin
dipen.rana20-Jun-07 11:33
dipen.rana20-Jun-07 11:33 
GeneralRe: MFC Bitmap Help Pin
Christian Graus20-Jun-07 11:46
protectorChristian Graus20-Jun-07 11:46 
GeneralRe: MFC Bitmap Help Pin
Mark Salsbery20-Jun-07 12:04
Mark Salsbery20-Jun-07 12:04 
GeneralRe: MFC Bitmap Help Pin
Hamid_RT20-Jun-07 18:42
Hamid_RT20-Jun-07 18:42 
GeneralRe: MFC Bitmap Help Pin
Mark Salsbery21-Jun-07 5:19
Mark Salsbery21-Jun-07 5:19 
GeneralRe: MFC Bitmap Help Pin
Hamid_RT21-Jun-07 19:43
Hamid_RT21-Jun-07 19:43 
GeneralRe: MFC Bitmap Help Pin
dipen.rana25-Jun-07 5:43
dipen.rana25-Jun-07 5:43 
Hey thnkz for the help but i still have problem i have written the code in .C and i m calling its function in my main thread (i call Createwin) but if i m using ATL in this *.c file it gives me error so i heres my code and if you can help its would be gratefull

/******************************************************************************************************************************

/* Window.C */
#include <windows.h>
#include "wingdi.h"
#include "win.h"


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


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

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


/**************************************************
*
* Register this type of window...
*
*
**************************************************/
BOOL RegisterWindow(char *lpClass, HANDLE 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,
HANDLE 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));

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,
DIB_RGB_COLORS);

error = GetLastError();



ReleaseDC( hWnd, hDC);
}



/**************************************************
*
* 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<h; i++)
="" for="" (j="0;j<W;" j++)
="" {
="" if="" (="" min="">= *head ) min = *head;
if ( max <= *head ) max = *head;
head++;
}

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

/* Transfer Data to 8 bits */
for (i=0; i
GeneralRe: MFC Bitmap Help Pin
Mark Salsbery25-Jun-07 7:40
Mark Salsbery25-Jun-07 7:40 
GeneralRe: MFC Bitmap Help Pin
dipen.rana25-Jun-07 8:45
dipen.rana25-Jun-07 8:45 
GeneralRe: MFC Bitmap Help Pin
Mark Salsbery25-Jun-07 13:49
Mark Salsbery25-Jun-07 13:49 
GeneralRe: MFC Bitmap Help Pin
dipen.rana2-Jul-07 10:00
dipen.rana2-Jul-07 10:00 
QuestionOptimizing floating-point calculation performance with 64-bit applications? Pin
Cyrilix20-Jun-07 11:16
Cyrilix20-Jun-07 11:16 
QuestionCInternetSession question Pin
baloneyman20-Jun-07 9:51
baloneyman20-Jun-07 9:51 
QuestionAnyone know which file defines GET_X_LPARAM and GET_Y_LPARAM macros for WM_MOUSEMOVE? Pin
Cyrilix20-Jun-07 9:12
Cyrilix20-Jun-07 9:12 
AnswerRe: Anyone know which file defines GET_X_LPARAM and GET_Y_LPARAM macros for WM_MOUSEMOVE? Pin
Mark Salsbery20-Jun-07 9:30
Mark Salsbery20-Jun-07 9:30 
GeneralRe: Anyone know which file defines GET_X_LPARAM and GET_Y_LPARAM macros for WM_MOUSEMOVE? Pin
Cyrilix20-Jun-07 9:32
Cyrilix20-Jun-07 9:32 
GeneralRe: Anyone know which file defines GET_X_LPARAM and GET_Y_LPARAM macros for WM_MOUSEMOVE? Pin
Mark Salsbery20-Jun-07 9:38
Mark Salsbery20-Jun-07 9:38 
QuestionIt has been 10 years! Pin
mrw_houston20-Jun-07 8:59
mrw_houston20-Jun-07 8:59 
AnswerRe: It has been 10 years! Pin
Cyrilix20-Jun-07 9:21
Cyrilix20-Jun-07 9:21 
AnswerRe: It has been 10 years! [modified] Pin
Mark Salsbery20-Jun-07 9:34
Mark Salsbery20-Jun-07 9:34 
GeneralRe: It has been 10 years! Pin
Stephen Hewitt20-Jun-07 13:55
Stephen Hewitt20-Jun-07 13:55 
GeneralRe: It has been 10 years! Pin
Mark Salsbery20-Jun-07 14:02
Mark Salsbery20-Jun-07 14:02 
QuestionRelease OK,Debug Error! Pin
kingliub20-Jun-07 6:21
kingliub20-Jun-07 6:21 
AnswerRe: Release OK,Debug Error! Pin
shivditya20-Jun-07 6:23
shivditya20-Jun-07 6:23 

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.