Article View: borland.public.cppbuilder.nativeapi
Article #1753Re: Multi-thread OR Event-based?
From: Robert G. Hoover
Date: Thu, 14 Jun 2007 14:57
Date: Thu, 14 Jun 2007 14:57
122 lines
4504 bytes
4504 bytes
Hi Everyone,
Thanks SO much for your help. I'm still struggling with this whole
thing. Can you have a look at this code? I've stripped out everything I
can think of and reduced it to a single application thread by using the
WM_TIMER event. I must be missing something obvious...
Many thanks,
Rob
_________________________________________________________________________
#include <vcl.h> #include "PixelSaverShell.h"
#pragma hdrstop
#pragma package(smart_init)
#pragma resource "*.dfm"
typedef struct
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256];
}
BITMAPINFOSTRUCT;
// global variables
TShellForm *ShellForm;
HDC hDC;
BITMAPINFOSTRUCT bmInfo;
BITMAP bmBitmap;
__fastcall TShellForm::TShellForm(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TShellForm::FormCreate(TObject *Sender)
{
Left = 0;
Top = 0;
ClientWidth = Screen->Width;
ClientHeight = Screen->Height;
bmBitmap.bmType = 0;
bmBitmap.bmPlanes = 1;
bmBitmap.bmWidth = ClientWidth;
bmBitmap.bmHeight = ClientHeight;
bmBitmap.bmBitsPixel = 8;
bmBitmap.bmWidthBytes = ClientWidth;
// pad rows
short RowPad = bmBitmap.bmWidthBytes % 4;
if (RowPad != 0)
bmBitmap.bmWidthBytes += 4 - RowPad;
bmBitmap.bmBits = (unsigned char *)malloc(bmBitmap.bmWidthBytes *
bmBitmap.bmHeight);
bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfo.bmiHeader.biWidth = bmBitmap.bmWidth;
bmInfo.bmiHeader.biHeight = bmBitmap.bmHeight;
bmInfo.bmiHeader.biPlanes = bmBitmap.bmPlanes;
bmInfo.bmiHeader.biBitCount = bmBitmap.bmBitsPixel;
bmInfo.bmiHeader.biCompression = BI_RGB;
bmInfo.bmiHeader.biSizeImage = bmBitmap.bmWidthBytes * bmBitmap.bmHeight;
bmInfo.bmiHeader.biXPelsPerMeter = 0;
bmInfo.bmiHeader.biYPelsPerMeter = 0;
bmInfo.bmiHeader.biClrUsed = (bmBitmap.bmBitsPixel == 8) ? 256 : 0;
bmInfo.bmiHeader.biClrImportant = 0;
// initialize color table - monochrome greyscale image
for (DWORD i = 0; i < 256; i++)
{
bmInfo.bmiColors[i].rgbRed = i;
bmInfo.bmiColors[i].rgbGreen = i;
bmInfo.bmiColors[i].rgbBlue = i;
bmInfo.bmiColors[i].rgbReserved = 0;
}
hDC = GetDC(Handle);
}
//---------------------------------------------------------------------------
void __fastcall TShellForm::FormShow(TObject *Sender)
{
DisplayTimer->Enabled = true;
}
//---------------------------------------------------------------------------
// draw video frame
void __fastcall TShellForm::DisplayTimerTimer(TObject *Sender)
{
static unsigned char ThisShade = 127;
memset(bmBitmap.bmBits,
ThisShade++,
bmBitmap.bmWidthBytes * bmBitmap.bmHeight);
StretchDIBits(hDC,
0,
0,
ClientWidth,
ClientHeight,
0,
0,
bmInfo.bmiHeader.biWidth,
bmInfo.bmiHeader.biHeight,
bmBitmap.bmBits,
(BITMAPINFO *)&bmInfo,
DIB_RGB_COLORS,
SRCCOPY);
}
//---------------------------------------------------------------------------
void __fastcall TShellForm::FormDestroy(TObject *Sender)
{
ReleaseDC(Handle, hDC);
free(bmBitmap.bmBits);
}
//---------------------------------------------------------------------------
Technical Details
Message-ID:
<467157ba@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<46701cfb@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,27bec389d3c536e6 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 14 Jun 2007 10:57:09 -0400 From: "Robert G. Hoover" <not.a.real.address@anywhere.sorry> User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Multi-thread OR Event-based? References: <46701cfb@newsgroups.borland.com> In-Reply-To: <46701cfb@newsgroups.borland.com> X-Enigmail-Version: 0.94.1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 000748-5, 06/13/2007), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 76.106.54.160 Message-ID: <467157ba@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1181833146 76.106.54.160 (14 Jun 2007 07:59:06 -0700) Lines: 123 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail