TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: hgraves
from: Gerard Gerritsen
date: 1996-02-21 18:52:26
subject: Visual Pascal COM routin

Hello hgraves!

Thursday February 15 1996, hgraves writes to Gerard Gerritsen:

 h> Is there a possibility you could post some examples of 'C' -> VP.

Most C code I have converted is from the book of Charles Petzold about
Presentation Manager. ( I doubt he would like it if I would post all of his
source code in the book... )

Basicly, 90% of PM calls ( Win,Gpi) can be used directly with Virtual Pascal,
So the biggest job is converting the other code to something that works.


Here is a small example ( code might not be completely functional, but I
hope you get the general idea )

C code.

MRESULT EXPENTRY ClientWndProc(Hwnd hwnd, Ulong msg, MPARAM mp1, MPARAM mp2)
  {
  /* Some definitions */
  switch (msg)
     { case WM_CHAR:
           { do something
             return 0 }
       case WM_ERASEBACKGROUND:
            return MRFROMSHORT (1) ;
           }
         return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }

Virtual Pascal code

Function ClientWndProc(Window:Hwnd;Msg:Ulong;MP1,MP2:Mparam):Mresult;CDECL;

begin
ClientWndProc:=0;       { so I can use exit instead of having to type      
   ClientWndproc at the end of a case statement.}

Case Msg of
        WM_CHAR: BEGIN
                  {Do Something }
                  exit;
                 END;
        WM_ERASEBACKGROUND: BEGIN
                 ClientWndProc:=MrFromShort(1);
                  exit;
                 end;
            else
ClientWndProc:=WinDefWinProc(Window,Msg,Mp1,Mp2);
end;
end;


So maybe you could use 'real' vp code.

( it's for EEP4, so some changes might be needed. )
( All this program does is loading a dialog from the .exe file ( provided
you've compiled the resources )
( Thanks to Eelco Dolstra and other people from OS2PROG who responded to my
request for help with the dialog window... )

program DialogExample;
{$PMTYPE PM}            { this one }
uses os2pmapi,os2base,os2def;

{$DYNAMIC SYSTEM}
{$L VPRTL.LIB}

Function ClientWndProc (Window:HWND;MSG:ulong;Mp1,Mp2:Mparam):Mresult;CDECL;
begin
  Case Msg of
    WM_COMMAND: begin
                    DosBeep (1000, 1000); { Beep! }
                    ClientWndProc:= MResult (0);
                    exit;
                    end;
             end;

  ClientWndProc:=WinDefDlgProc(window,msg,mp1,mp2);
end;

var
  Anchor:hab;
  Message:HMQ;

begin
  Anchor:=WinInitialize(0);
  Message:=WinCreateMsgQueue(anchor, 100);

  WinDlgBox (hwnd_Desktop, 0, ClientWndProc, 0, 123, nil); { or
{at}clientWndProc for the beta release }

  WinDestroyMsgQueue(Message);
  WinTerminate(anchor);
end.


Now for the resource file
DialogExample.rc

#include "/vp/units/pm.h"   { it might be in another location }

#define ID_ICON 1
#define DialogExample 123

DLGTEMPLATE DialogExample LOADONCALL MOVEABLE DISCARDABLE
BEGIN
    DIALOG  "Calculator", 123, 100, 40, 132, 122, WS_VISIBLE,
      FCF_DLGBORDER | FCF_TASKLIST | FCF_SYSMENU | FCF_MINBUTTON | FCF_TITLEBAR
    {
       PUSHBUTTON "A",         18,   8,  84, 20, 14, BS_NOPOINTERFOCUS
    }
}


==> Gerard/2   - member of team os/2 -  1000521{at}ibk.fnt.hvu.nl

--- Fmail/2 1.02 Registered
* Origin: Yet another forgotten area! (2:283/203.18)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 283/203 2 512 280/801 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.