[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Old resources in Delphi apps

Posted on 2000-02-15
3
Medium Priority
?
188 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 400 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

Technology Partners: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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