Solved

Old resources in Delphi apps

Posted on 2000-02-15
3
185 Views
Last Modified: 2010-04-04
Is it possible to use dialog boxes created with Resource Workshop (Bundled with Borland C++ 4.5) in a Delphi 3.0 application, and if so how do i call them ?.

         Thanks Paul.
0
Comment
Question by:pr_wainwright
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 100 total points
ID: 2524599
Hi Paul,

This is from my PAQs from an answer by simonet:

Creating and handling a form from resource is pretty much like working with plain C: you have to create the dialog (the window) from the resource, display it, write the main loop, the handler for each message, etc. The program above does it:

{$ifndef _DEBUG}
{$O+,D-,L-,M-,Y-,R-,Q-,U-,C-}
{$endif}
program Window1;
{ Standard Windows API application written in Object Pascal }

uses
Windows, messages, ShellApi;

{$R myres.res}

const
AppName = 'APIWindow';

function CreateControls(hParent : HWnd) : boolean; forward;


function ControlsProc(Window: HWnd; AMessage, WParam, LParam: Longint): Longint; stdcall; export;
begin
  ControlsProc := 0;
  if AMessage=WM_COMMAND then
  begin
     case WParam of
        IDOK : SendMessage(GetParent(Window), WM_CLOSE, 0, 0);
     end;
  end;
end;

{
  WindowProc is the main message handler for the window.
  Messages that are not handled by this function must be passed to
  the default message handler by calling DefWindowProc()
}
function WindowProc(Window: HWnd; AMessage, WParam, LParam: Longint): Longint; stdcall; export;
begin
  WindowProc := 0;
case AMessage of
WM_DESTROY : begin
      PostQuitMessage(0);
      Exit;
      end;
     WM_CLOSE : if MessageBox(Window, 'Are you sure you want to quit?', pchar(AppName), MB_ICONQUESTION + MB_YESNO)=IDYES then
           DestroyWindow(Window)
        else
           Exit;
     WM_COMMAND : case LoWord(WParam) of
           102, 451 : SendMessage(Window, WM_CLOSE, 0, 0);
           901 : ShellAbout(Window, pchar(AppName), 'by Alex Simonetti Abreu', LoadIcon(hInstance, makeintresource(1)));
        end;
end;
  WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
end;

{ Register the Window Class }
function WinRegister: Boolean;
var
  WindowClass: TWndClass;
begin
  WindowClass.Style := cs_hRedraw or cs_vRedraw;
  WindowClass.lpfnWndProc := @WindowProc;
  WindowClass.cbClsExtra := 0;
  WindowClass.cbWndExtra := 0;
  WindowClass.hInstance := HInstance;
  WindowClass.hIcon := LoadIcon(0, idi_Application);
  WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  WindowClass.hbrBackground := HBrush(Color_Window);
  WindowClass.lpszMenuName := makeintresource(1);
  WindowClass.lpszClassName := AppName;
  Result := RegisterClass(WindowClass) <> 0;
end;

{ Create the Window Class }
function WinCreate: HWnd;
var
  hWindow: HWnd;
begin
  hWindow := CreateWindow(AppName, 'Object Pascal Window',
  ws_OverlappedWindow, CW_USEDEFAULT,  CW_USEDEFAULT,
  400, 320, 0, 0, HInstance, nil);
  if hWindow <> 0 then
  begin
     CreateControls(hwindow);
     ShowWindow(hWindow, cmdShow);
     UpdateWindow(hWindow);
  end;
  Result := hWindow;
end;


function CreateControls(hParent : HWnd) : boolean;
begin
  Result := CreateDialog(hInstance, MakeIntResource(3), hParent, @ControlsProc)<>0;
end;


{ The routine below is identical to
  the C\C++ declaration :


  int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)

  In Delphi, there's no need for a WinMain function. The begin..end of the main
  program is the entry point.

  If an exit result code is necessary, pass the code to the Halt() procedure.
}

var
  AMessage: TMsg;
  hWindow: HWnd;
begin
  if not WinRegister then begin
     MessageBox(0, 'Register failed', nil, mb_Ok);
     Exit;
  end;
  hWindow := WinCreate;
  if hWindow = 0 then begin
  MessageBox(0, 'WinCreate failed', nil, mb_Ok);
  Exit;
  end;
  while GetMessage(AMessage, 0, 0, 0) do
  begin
     TranslateMessage(AMessage);
     DispatchMessage(AMessage);
  end;
  Halt(AMessage.wParam);
end.

********** EOF

Note the CreateControls function above. It takes a the handle for the window that is create and then it creates the Form (all the controls inside the window).  This form was in "myres.res" and it's resource identifier is 3.

Also note the ControlsProc and WindowsProc functions in the program. They are responsible for the Main loop. They handle the messages sent by the Controls and the Window, respectively. The controls are identified by their number, defined at the moment you created the resource.

A great book for this subject is Delphi Unleashed, by Charlie Calvert.

You can also look at this MSDN area:

http://msdn.microsoft.com/library/sdkdoc/winui/dlgboxes_7foz.htm 


Cheers,

Raymond.
0
 
LVL 15

Expert Comment

by:simonet
ID: 2525038
Don't forget to make sure MYRES.RES is a 32-bit resource file, rather than a 16-bit resource file. Resource Workshop can handle both formats, so you better make sure.

Alex
0
 
LVL 1

Author Comment

by:pr_wainwright
ID: 2527140
Thanks, I was unaware Delphi could be
used like this .

    Paul.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TServerSocket - file via sendbuf or Text via sendtext ? 1 85
How to build JSON File in Delphi 6 3 85
DBCtrlGrid, Delphi, Scroll 7 34
delphi popmenu non latine charcters 3 44
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question