#include "FiveWin.ch"
#define GWL_STYLE -16
#define RT_DIALOG MakeIntResource( 5 )
static hVars := { "oBtn" => 0, "oLbx" => 0, "oGet" => 0, "oTbr" => 0,;
"oBrw" => 0, "oMtr" => 0, "oGrp" => 0, "oRad" => 0 }
function Main()
local oDlg, cDlgName, aDlgNames := {}, oLbx, oGetCode, cCode := Space( 800 ), oDlgNew
TMeterEx():Register()
TXBrowse():Register()
TFolderEx():Register()
EnumResourceNames( GetInstance(), RT_DIALOG, { | cDlgName | AAdd( aDlgNames, cDlgName ), .T. } )
DEFINE DIALOG oDlg TITLE "RC dialogs to PRG" SIZE 720, 500
@ 0, 1.5 SAY "Select a dialog" OF oDlg
@ 1, 1 LISTBOX oLbx VAR cDlgName ITEMS aDlgNames OF oDlg SIZE 100, 200
@ 12, 5 BUTTON "Generate" OF oDlg ACTION oDlgNew := BuildDialog( cDlgName, oGetCode )
@ 12, 16 BUTTON "End" OF oDlg ACTION oDlgNew:End()
@ 1.1, 14 GET oGetCode VAR cCode OF oDlg MULTILINE SIZE 240, 188
ACTIVATE DIALOG oDlg ON INIT oDlg:SetPos( 300, 100 )
return nil
function BuildDialog( cDlgName, oGetCode )
local oDlg
DEFINE DIALOG oDlg RESOURCE ( cDlgName )
ACTIVATE DIALOG oDlg NOWAIT ON INIT ( oDlg:SetPos( 300, 900 ), WritePrg( oDlg, oGetCode ) )
return oDlg
function WritePrg( oDlg, oGetCode )
local cPrg := "", n, cVars := "", cKey
EnumChildWindows( oDlg:hWnd, { | hCtrl | cPrg += GenCode( hCtrl ) } )
for each cKey in hb_HKeys( hVars )
if hVars[ cKey ] != 0
cVars += "local "
for n = 1 to hVars[ cKey ]
cVars += If( n > 1, ", ", "" ) + cKey + AllTrim( Str( n ) )
next
cVars += CRLF
endif
next
oGetCode:SetText( cVars + CRLF + 'DEFINE DIALOG oDlg RESOURCE "' + oDlg:cResName + '"' + ;
CRLF + CRLF + cPrg + "ACTIVATE DIALOG oDlg CENTERED" )
return nil
function GenCode( hCtrl )
local cCode := "REDEFINE "
local cClass := Upper( GetClassName( hCtrl ) )
static hPrevCtrl
do case
case cClass == "BUTTON"
if nAnd( GetWindowLong( hCtrl, GWL_STYLE ), BS_AUTORADIOBUTTON ) == BS_AUTORADIOBUTTON
cCode += "RADIO oRad" + AllTrim( Str( ++hVars[ "oRad" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg ON CLICK ''" + " // " + LTrim( GetWindowText( hCtrl ) )
elseif nAnd( GetWindowLong( hCtrl, GWL_STYLE ), BS_GROUPBOX ) == BS_GROUPBOX
cCode += "GROUP oGrp" + AllTrim( Str( ++hVars[ "oGrp" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg"+ " // " + LTrim( GetWindowText( hCtrl ) )
else
cCode += "BUTTON oBtn" + AllTrim( Str( ++hVars[ "oBtn" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg ACTION ''"
endif
case cClass == "EDIT"
cCode += "GET oGet" + AllTrim( Str( ++hVars[ "oGet" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg" + If( lAnd( GetWindowLong( hCtrl, GWL_STYLE ), ES_MULTILINE ), " MULTILINE", "" ) + ;
" // " + If( ! Empty( hPrevCtrl ) .and. ;
Upper( GetClassName( hPrevCtrl ) ) == "STATIC", GetWindowText( hPrevCtrl ), "" )
case cClass == "LISTBOX"
cCode += "LISTBOX oLbx" + AllTrim( Str( ++hVars[ "oLbx" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg ON CHANGE ''"
case cClass == "MSCTLS_TRACKBAR32"
cCode += "TRACKBAR oTrb" + AllTrim( Str( ++hVars[ "oTrb"] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg ON CHANGE ''"
case cClass == "TXBROWSE"
cCode += "XBROWSE oBrw" + AllTrim( Str( ++hVars[ "oBrw" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg"
case cClass == "STATIC"
cCode = ""
case cClass == "TMETEREX"
cCode += "METEREX oMtr" + AllTrim( Str( ++hVars[ "oMtr" ] ) ) + " ID " + AllTrim( Str( GetDlgCtrlId( hCtrl ) ) ) + ;
" OF oDlg"
otherwise
MsgInfo( cClass )
endcase
hPrevCtrl = hCtrl
return cCode + If( ! Empty( cCode ), CRLF + CRLF, "" )
#pragma BEGINCODE
#include <Windows.h>
#include <hbapi.h>
#include <hbapiitm.h>
//---------------------------------------------------------------------------//
static BOOL CALLBACK EnumResourceNamesCallback( HMODULE hModule, LPSTR lpszType, LPSTR lpszName, LONG_PTR lParam )
{
( void ) hModule;
if( lpszType == RT_DIALOG )
{
PHB_ITEM pStrName = hb_itemPutC( NULL, lpszName );
hb_evalBlock1( ( PHB_ITEM ) lParam, pStrName );
hb_itemRelease( pStrName );
}
return hb_parl( -1 ); // .T. continue enumeration
}
//---------------------------------------------------------------------------//
HB_FUNC( ENUMRESOURCENAMES )
{
#ifndef _WIN64
EnumResourceNames( ( HMODULE ) hb_parnl( 1 ), ( const signed char * ) hb_parnl( 2 ),
( ENUMRESNAMEPROC ) EnumResourceNamesCallback, ( LONG_PTR ) hb_param( 3, HB_IT_BLOCK ) );
#else
EnumResourceNames( ( HMODULE ) hb_parnll( 1 ), ( const signed char * ) hb_parnl( 2 ),
( ENUMRESNAMEPROC ) EnumResourceNamesCallback, ( LONG_PTR ) hb_param( 3, HB_IT_BLOCK ) );
#endif
}
//---------------------------------------------------------------------------//
#pragma ENDCODE