Newsgroups: comp.windows.ms.programmer
Path: funic!news.funet.fi!sunic!psinntp!psinntp!rpi!usc!sol.ctr.columbia.edu!ira.uka.de!news.belwue.de!eratu.rz.uni-konstanz.de!nyx.uni-konstanz.de!PHSTUD19
From: PHSTUD19@nyx.uni-konstanz.de (Joerg Hegermann)
Subject: Palette..why doesn't it work?
Message-ID: <168C19904.PHSTUD19@nyx.uni-konstanz.de>
Sender: usenet@eratu.rz.uni-konstanz.de
Organization: University of Konstanz, Germany
Date: Fri, 18 Dec 1992 09:52:52 GMT
Lines: 133

Hi there,

I still have a problem with the palettes....
Now I wrote a small source which is supposed to fill an array
with some random bytes and blow it as a bitmap onto the screen.
The palette is supposed to be 8Bit gray.....
But the whole thing just doesn't show any effect.....
Can u tell me where the problem lies????????
alright...hre it goes...the source :-)

Program TestPal;

Uses
  WinTypes,WinProcs,WObjects;

Const
  MaxXRes = 100;
  MaxYRes = 100;
  TifSize = MaxXRes*MaxYRes;

Type
  TTiffType = Array1..TifSize of Byte;
  PTiffType = ^TTiffType;
  TiffApplication = Object(TApplication)
    Procedure InitMainWindow;Virtual;
  end;
  PMainWindow = ^TMainWindow;
  TMainWindow = Object(TWindow)
    DataHandle   : THandle;
    PData        : PTiffType;
    Size         : LongInt;
    RheedPicture : HBitmap;
    HPal         : HPalette;
    Constructor Init(AParent:PWindowsObject;ATitle:PChar);
    Destructor Done;Virtual;
    Procedure Paint(PaintDC:HDC;Var PaintInfo:TPaintStruct);Virtual;
  end;

Procedure AHIncr;Far;External 'KERNAL' index 114;

Procedure TiffApplication.InitMainWindow;
Begin
  MainWindow:=New(PMainWindow,Init(nil,'Test Rheed'));
end;

Constructor TMainWindow.Init(AParent:PWindowsObject;ATitle:PChar);
Var
  X,Y       : Integer;
  I         : LongInt;
  PalHandle : THandle;
  Pal       : ^TLogPalette;
Begin
  Randomize;
  TWindow.Init(AParent,ATitle);
  I:=SizeOf(TLogPalette)+255*SizeOf(TPaletteEntry);
  GlobalCompact(-1);
  PalHandle:=GlobalAlloc(Gmem_Moveable or Gmem_Zeroinit,I);
  If PalHandle<>0 Then
  Begin
    MessageBeep(0);
    Pal:=GlobalLock(PalHandle);
    Pal^.palVersion:=$0300;
    Pal^.palNumEntries:=256;
    For I:=0 to 255 do
    Begin
      Pal^.palPalEntryI.peRed:=I;
      Pal^.palPalEntryI.peGreen:=I;
      Pal^.palPalEntryI.peBlue:=I;
    end;
    HPal := CreatePalette(Pal^);
    GlobalUnlock(PalHandle);
    GlobalFree(PalHandle);
  end;
  GlobalCompact(-1);
  DataHandle:=GlobalAlloc(Gmem_Moveable or Gmem_Zeroinit,TifSize);
  If DataHandle<>0 Then
  Begin
    MessageBeep(0);
    PData:=GlobalLock(DataHandle);
    For I:=1 to TifSize do
      PData^I:=Byte(Random(255));
    RheedPicture:=CreateBitmap(MaxXRes,MaxYRes,1,8,PData);
    GlobalUnlock(DataHandle);
    GlobalFree(DataHandle);
  end;
end;

Destructor TMainWindow.Done;
Begin
  DeleteObject(RheedPicture);
  TWindow.Done;
end;

Procedure TMainWindow.Paint(PaintDC:HDC;Var PaintInfo:TPaintStruct);
Var
  OldBitmap    : HBitmap;
  MemDC        : HDC;
Begin
  MemDC:=CreateCompatibleDC(PaintDC);
  SelectPalette(MemDC,HPal,False);
  RealizePalette(MemDC);
  OldBitmap:=SelectObject(MemDC,RheedPicture);
  BitBlt(PaintDC,0,0,MaxXRes,MaxYRes,MemDC,0,0,SrcCopy);
  SelectObject(MemDC,OldBitmap);
  DeleteDC(MemDC);
end;

Var
  TiffApp : TiffApplication;
Begin
  TiffApp.Init('TiffApp');
  TiffApp.Run;
  TiffApp.Done;
end.

I'd appreciate it a LOT....if someone of you could help me with
this *smile*....
Anyway...Thanks in advance....


-----------------------------------------------------------------
Joerg Hegermann      HH  HH IIII GGGGG GGGGG  IIII NN   NN SSSSS
Am Silberberg 14     HH  HH  II  GG    GG      II  NNN  NN SS
7758 Meersburg       HHHHHH  II  GGGGG GGGGG   II  NN N NN SSSSS
Tel. 07532-5640      HH  HH  II  GG GG GG GG   II  NN  NNN    SS
     07532-2184      HH  HH IIII GGGGG GGGGG  IIII NN   NN SSSSS
-----------------------------------------------------------------
Phstud19@Dknkurz1                       ( VM Stuff  )
Phstud19@Nyx.Uni-Konstanz.De            ( VM Stuff  )
Higgins@vg10.Chemie.Uni-Konstanz.de     ( VMS Stuff )
-----------------------------------------------------------------
MSG PHSTUD58: Hi Higgi, verwandele Dich mal in einen virtuellen
              Zug und ueberfahre die Boa.
