Author Topic: SetDialogScale(hWnd, 0); added  (Read 977 times)

jcfuller

  • Sr. Member
  • ****
  • Posts: 415
    • View Profile
SetDialogScale(hWnd, 0); added
« on: February 19, 2024, 10:51:13 AM »
Kevin,
  SetDialogScale(hWnd, 0);
  is added to the cpp translation when a
  case WM_INITDIALOG is added to the bcx source
  Comment the WM_INITDIALOG and it is not added
  This is an rc dialog app. you will need to compile and include the res in the construction.
James

Code: [Select]
$CPP
$CPPHDR
$NOMAIN
$ONEXIT "ASTYLE.EXE -pn $FILE$.CPP"
$ONEXIT "VSCPP.BAT $FILE$ -m64 con"

$CCODE CONST
  using namespace std;
$CCODE

CONST MANIFEST                24
CONST IDD_DLG1                1000
CONST IDC_BTN1                1003
CONST IDC_BTN2                1004
CONST IDC_BTN3                1005
CONST IDC_STC1                1001
CONST IDC_STC2                1002
CONST IDR_XPMANIFEST1         1
CONST CTLHNDL(id) = GetDlgItem(hWnd,id)
$PP
'$USE USE_IMATCH USE_bc9StrParseCount USE_SetColor USE_CLIPBOARD
'$Include <BCppXLib.bi>
'==============================================================================
Function WinMain()
    Local As HWND hDlg
    Local As MSG Msg
Local As HFONT hFont
Dim As HWND hCtl
    hDlg = CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DLG1),0,(DLGPROC)DlgProc,0)
    While GetMessage(&Msg,NULL, 0, 0)
        If (IsDialogMessage(hDlg, &Msg) = 0) Then
            TranslateMessage(&Msg)
            DispatchMessage(&Msg)
        End If
    Wend
   
    Function = Msg.wParam   
End Function
'==============================================================================
Begin Dialog As DlgProc


    Select Case (CBMSG)
    'This is added automagically by BCX
    'case WM_CLOSE
        '    DestroyWindow(CBHWND)
    case WM_INITDIALOG
    ' BCX_SET_FONT(CTLHNDL(IDC_STC2),"Tahoma",11)
    case WM_DESTROY
            PostQuitMessage(0)
            Function = 0   
    case WM_COMMAND
            Select Case(CBCTL)
            case IDC_BTN3
                    PostMessage(CBHWND,WM_CLOSE,0,0)
                    CloseDialog
            End Select
           
    End Select
End Dialog
$PP
'==============================================================================
cpp Source
Code: [Select]
// *************************************************
//      Made with BCX BASIC To C/C++ Translator
//            Version 8.0.8 (12/27/2023)
// *************************************************
//    Translated for compiling with a C++ Compiler
// *************************************************

#ifndef __cplusplus
#error A C++ compiler is required
#endif

#ifdef _MSC_VER
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif

#if defined(__cplusplus)
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
typedef std::string stdstr;
#endif


#include <windows.h>    // WinApi
#include <windowsx.h>   // WinApi
#include <commctrl.h>   // WinApi
#include <commdlg.h>    // WinApi
#include <direct.h>     // WinApi
#include <mmsystem.h>   // WinApi
#include <oaidl.h>      // WinApi
#include <objbase.h>    // WinApi
#include <ocidl.h>      // WinApi
#include <ole2.h>       // WinApi
#include <oleauto.h>    // WinApi
#include <olectl.h>     // WinApi
#include <richedit.h>   // WinApi
#include <shellapi.h>   // WinApi
#include <shlobj.h>     // WinApi
#include <urlmon.h>     // WinApi
#include <wchar.h>      // WinApi
#include <wctype.h>     // WinApi
#include <tchar.h>      // WinApi
#include <unknwn.h>     // WinApi
#include <wingdi.h>     // WinApi
#include <wininet.h>    // WinApi
#include <winsock.h>    // WinApi
#include <winuser.h>    // WinApi
#include <stdbool.h>    // ISO StdLib
#include <ctype.h>      // ISO StdLib
#include <math.h>       // ISO StdLib
#include <setjmp.h>     // ISO StdLib
#include <stdarg.h>     // ISO StdLib
#include <stddef.h>     // ISO StdLib
#include <stdio.h>      // ISO StdLib
#include <stdlib.h>     // ISO StdLib
#include <string.h>     // ISO StdLib
#include <time.h>       // ISO StdLib
#include <process.h>    // ISO StdLib
#include <inttypes.h>   // ISO StdLib
#include <fcntl.h>      // POSIX
#include <io.h>         // WinNT POSIX subset
#include <conio.h>      // Primitive i/o


// *************************************************
//            System Defined Macros
// *************************************************

#define BCXSTRSIZE 2048

// *************************************************
//             User Defined Macros
// *************************************************

using namespace std;
#define MANIFEST 24
#define IDD_DLG1 1000
#define IDC_BTN1 1003
#define IDC_BTN2 1004
#define IDC_BTN3 1005
#define IDC_STC1 1001
#define IDC_STC2 1002
#define IDR_XPMANIFEST1 1
#define CTLHNDL(id) GetDlgItem(hWnd,id)

// *************************************************
//                  Compiler Macros
// *************************************************

#if defined(__cplusplus)
#define overloaded
#define C_EXPORT EXTERN_C __declspec(dllexport)
#define C_IMPORT EXTERN_C __declspec(dllimport)
#else
#define C_EXPORT __declspec(dllexport)
#define C_IMPORT __declspec(dllimport)
#endif

// *************************************************
//                   Microsoft VC++
// *************************************************

#ifndef DECLSPEC_UUID
#if(_MSC_VER >= 1100) && defined(__cplusplus)
#define DECLSPEC_UUID(x)  __declspec(uuid(x))
#else
#define DECLSPEC_UUID(x)
#endif
#endif
#if (_MSC_VER >= 1900)            // earlier versions untested
#include <intrin.h>
#ifndef _rdtsc
#define _rdtsc __rdtsc   // MSVC uses 2 underscores
#endif
#pragma warning(disable: 4018) // signed/unsigned mismatch warnings
#pragma warning(disable: 4100) // unreferenced argument warnings
#pragma warning(disable: 4244) // conversion from type1 to type2 warnings
#pragma warning(disable: 4267) // conversion from type1 to type2 warnings
#pragma warning(disable: 4305) // truncation from double to float warnings
#pragma warning(disable: 4800) // forcing value to bool warnings
#pragma warning(disable: 4838) // conversion from type1 to type2 warnings
#endif

// *************************************************
//                  GCC and CLANG
// *************************************************

#if defined(__GNUC__) || defined(__clang__)
#ifndef __BCPLUSPLUS__
#include <x86intrin.h>
#endif
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wdeprecated"
#endif

// *************************************************
//                  Embarcadero C++
// *************************************************

#if defined(__BCPLUSPLUS__)
#if defined (_clang__)
#include <mmintrin.h>
#endif
#define _kbhit kbhit
#ifndef _rdtsc
#define _rdtsc __rdtsc  // Uses 2 underscores
#endif
#endif


// *************************************************
// Instruct Linker to Search Object/Import Libraries
// *************************************************

#if !defined(__GNUC__) && !defined(__TINYC__)
#if !(defined(__BCPLUSPLUS__) && defined(_WIN64))
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"comctl32.lib")
#pragma comment(lib,"advapi32.lib")
#pragma comment(lib,"winspool.lib")
#pragma comment(lib,"shell32.lib")
#pragma comment(lib,"msimg32.lib")
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"oleaut32.lib")
#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"odbc32.lib")
#pragma comment(lib,"odbccp32.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"comdlg32.lib")
#pragma comment(lib,"imagehlp.lib")
#pragma comment(lib,"version.lib")
#pragma comment(lib,"wininet.lib")
#pragma comment(lib,"urlmon.lib")
#endif
#endif


// *************************************************
//               Standard Macros
// *************************************************


// *************************************************
//               User's Prototypes
// *************************************************

int     WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
INT_PTR CALLBACK DlgProc (HWND, UINT, WPARAM, LPARAM);

// *************************************************
//            User's Global Initialized Arrays
// *************************************************


// *************************************************
//                 Runtime Functions
// *************************************************

// *************************************************
//            User's Subs and Functions
// *************************************************

int WINAPI WinMain (HINSTANCE  hInst, HINSTANCE  hPrev, LPSTR  CmdLine, int CmdShow)
{
    HWND     hDlg = {0};
    MSG      Msg = {0};
    HFONT    hFont = {0};
    HWND     hCtl = {0};
    hDlg = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DLG1), 0, (DLGPROC)DlgProc, 0);
    while(GetMessage(&Msg, NULL, 0, 0)) {
        if((IsDialogMessage(hDlg, &Msg) == 0)) {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    }
    return Msg.wParam;
}


INT_PTR CALLBACK DlgProc (HWND hWnd, UINT Msg, WPARAM  wParam, LPARAM  lParam)
{
    if((Msg) == WM_INITDIALOG ) {
        SetDialogScale(hWnd, 0);
        goto L1001;
    }
    if((Msg) == WM_DESTROY ) {
        PostQuitMessage(0);
        return 0;
    }
    if((Msg) == WM_COMMAND ) {
        if((LOWORD(wParam)) == IDC_BTN3 ) {
            PostMessage(hWnd, WM_CLOSE, 0, 0);
            DestroyWindow(hWnd);
        }
    }
L1001:
    ;
    if(Msg == WM_CLOSE) DestroyWindow(hWnd);
    return EXIT_SUCCESS;
}



 
James


MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2392
    • View Profile
Re: SetDialogScale(hWnd, 0); added
« Reply #1 on: February 19, 2024, 12:03:45 PM »
James,

It seems this code in BCX:

Code: [Select]
    IF InDialogEvt OR ModDialogEvt THEN
        IF iMatchNQ(Arg$, "WM_INITDIALOG") THEN
            CALL AddExpressionToStack(Arg$)
            CALL AddExpressionToStack("SetDialogScale(hWnd,0)")
            GOTO ProcessNew
        END IF
    END IF

is responsible for the issue that you're seeing.

A possible fix would be to add a C++ test to that block:

Code: [Select]
    IF (InDialogEvt OR ModDialogEvt) and UseCpp = FALSE THEN
      .
      .
    END IF

This might have unintended consequences in other apps but I seriously doubt it.

jcfuller

  • Sr. Member
  • ****
  • Posts: 415
    • View Profile
Re: SetDialogScale(hWnd, 0); added
« Reply #2 on: February 19, 2024, 01:46:01 PM »
That's a negatory. Fails with Pelles also after removing c++ stuff
It appears you cannot use "Begin Dialog As DlgProc" with a resource dialog.
For a real hack if you switch    case WM_INITDIALOG with case WM_INITDLG it works
       
James

Code: [Select]
$NOMAIN
$ONEXIT "ASTYLE.EXE -pn $FILE$.C"
$ONEXIT "PEL.BAT $FILE$ -m64 gui"

CONST MANIFEST                24
CONST IDD_DLG1                1000
CONST IDC_BTN1                1003
CONST IDC_BTN2                1004
CONST IDC_BTN3                1005
CONST IDC_STC1                1001
CONST IDC_STC2                1002
CONST IDR_XPMANIFEST1         1
CONST CTLHNDL(id) = GetDlgItem(hWnd,id)
CONST WM_INITDLG = WM_INITDIALOG
'==============================================================================
Function WinMain()
    Local As HWND hDlg
    Local As MSG Msg
Local As HFONT hFont
Dim As HWND hCtl
    hDlg = CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DLG1),0,(DLGPROC)DlgProc,0)
    While GetMessage(&Msg,NULL, 0, 0)
        If (IsDialogMessage(hDlg, &Msg) = 0) Then
            TranslateMessage(&Msg)
            DispatchMessage(&Msg)
        End If
    Wend
   
    Function = Msg.wParam   
End Function
'==============================================================================
Begin Dialog As DlgProc


    Select Case (CBMSG)
    'This is added automagically by BCX
    'case WM_CLOSE
        '    DestroyWindow(CBHWND)
    case WM_INITDIALOG
    'case WM_INITDLG
    BCX_SET_FONT(CTLHNDL(IDC_STC2),"Tahoma",14)
    BCX_SET_FONT(CTLHNDL(IDC_STC1),"Tahoma",14)
    BCX_SET_FONT(CTLHNDL(IDC_BTN1),"Tahoma",12)
    BCX_SET_FONT(CTLHNDL(IDC_BTN2),"Tahoma",12)
    BCX_SET_FONT(CTLHNDL(IDC_BTN3),"Tahoma",12)
    case WM_DESTROY
            PostQuitMessage(0)
            Function = 0   
    case WM_COMMAND
            Select Case(CBCTL)
            case IDC_BTN3
                    PostMessage(CBHWND,WM_CLOSE,0,0)
                    CloseDialog
            End Select
    End Select
End Dialog


MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2392
    • View Profile
Re: SetDialogScale(hWnd, 0); added
« Reply #3 on: February 19, 2024, 02:02:08 PM »
Well, my suggested change to BCX worked for me.

Your code runs using MSVC and Mingw. 

See attached scrnshot.

« Last Edit: February 19, 2024, 03:22:52 PM by MrBcx »

jcfuller

  • Sr. Member
  • ****
  • Posts: 415
    • View Profile
Re: SetDialogScale(hWnd, 0); added
« Reply #4 on: February 20, 2024, 07:08:04 AM »
Crap!
It appears I did it again and did not explain myself fully.
I have no reason to believe your fix will not work. On the contrary it will work for c++ but will not for "c" coding.

I am on a new coding rig (my old Gaming box) and cannot compile a new bc.exe at present.

The "BEGIN DIALOG AS DlgProcName" is not searchable in the help file and it took me a bit to find it this am. I am aware now it is part of the BCX_DIALOG coding. As such the adding of the "SetDialogScale(hWnd, 0);" is NOT a BUG.

I am probably the only one who wants to use it with a resource dialog so I will find my own way around it.
Sorry for the inconvenience.

James