Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
Print Page - Lost and Confused

Theo's Forum

IT-Consultant: James C. Fuller => bc9Basic => Topic started by: James C. Fuller on March 22, 2016, 07:21:15 PM

Title: Lost and Confused
Post by: James C. Fuller on March 22, 2016, 07:21:15 PM
OK this one has me baffeled.

The window shown when the app runs is the same and correct when the c++ source is compiled
with TDM-GCC-64 or NUWEN. It is also the same when compiled as a 64 bit "c" app with PellesC8.
It is not correct when compiled with VS 2015 community.

If I use Borje Hagsten's PbWinSpy on the windows it creates exactly the same code for both

In the attachment I include both exe's, the screen captures shown here, the c++ and bc9Basic sources.
I compile from the command line and have included both the TDM and VS batch files.


Title: Re: Lost and Confused
Post by: Frederick J. Harris on March 23, 2016, 06:41:00 PM
I'm not exactly sure what the issue is James.  I looked at all the jpgs and red text is showing up on a white background in tdm and vs.  Likewise with green on black.  Just what exactly is wrong?
Title: Re: Lost and Confused
Post by: James C. Fuller on March 23, 2016, 07:34:01 PM
  The displayed width of the window. No space between the edit fields and the window border on the vs 2015 window.

Here is a discussion I just started on the codeguru forum:

Title: Re: Lost and Confused
Post by: Frederick J. Harris on March 24, 2016, 12:03:11 AM
Could that be a DPI phenomenon?  Different versions of user32.dll do seem to change things a bit.  I always have minor (sometimes major) clipping problems when moving from one OS to the next.  Don't think its changes to the window dimensions specified in the CreateWindowEx() call, so much as changes to the window's client area.
Title: Re: Lost and Confused
Post by: Frederick J. Harris on March 24, 2016, 02:34:24 AM
I just compiled and ran ec02.cpp with VC15 (from Visual Studio 2008 - 64 bit) and it looked OK.  The edit controls didn't extend to the edge of the window, anyway.
Title: Re: Lost and Confused
Post by: Frederick J. Harris on March 25, 2016, 03:19:37 PM
Say Jim,

     I just re-coded the app the way I'd typically do it and I used my my DPI code, and its displaying the exact same way in VC15 (Visual Studio 2008) and VC19 (Visual Studio 2015.  I wish they would get their numbers in some kind of synchronized order!!!!).

     The only thing I didn't add from your code was the capability to not allow multiple instances of the app.  I don't typically do that.  Also, I compiled it with TCLib and its coming in 6656 bytes (6100 VC15).  I'll attach everything, but here's ec02b.cpp

Code: [Select]
// cl ec02b.cpp /O1 /Os /MT kernel32.lib user32.lib gdi32.lib
// cl ec02b.cpp /O1 /Os /GS- /link TCLib.lib kernel32.lib user32.lib gdi32.lib
//  6,656 Bytes x64, UNICODE, VC19, TCLib
// 89,088 Bytes Std. VC Compile, MT Linked
// 90,112 Bytes BCX Translated C++ VC19 ansi MT Linked
#ifndef UNICODE
   #define UNICODE
#ifndef _UNICODE
   #define _UNICODE
#include <windows.h>
#include "stdio.h"
#include "tchar.h"
#include "Form1.h"

void SetMyProcessDpiAware()
 BOOL (__stdcall* pFn)(void);

 HINSTANCE hInstance=LoadLibrary(_T("user32.dll"));
    pFn=(BOOL (__stdcall*)(void))GetProcAddress(hInstance,"SetProcessDPIAware");

LRESULT fnWndProc_OnCreate(WndEventArgs& Wea)
 BOOL blnDpiAware=FALSE;
 double rxRatio,ryRatio;
 DpiData* pDpiData=NULL;
 int dpiX,dpiY;
 HWND hCtl;
 Wea.hIns    = ((LPCREATESTRUCT)Wea.lParam)->hInstance;
 hHeap       = GetProcessHeap();
 blnDpiAware = IsProcessDPIAware();
 // Deal With DPI
 hDC      = GetDC(NULL);
 dpiX     = GetDeviceCaps(hDC, LOGPIXELSX);
 dpiY     = GetDeviceCaps(hDC, LOGPIXELSY);
 rxRatio  = (dpiX/96);
 ryRatio  = (dpiY/96);
 pDpiData = (DpiData*)HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(DpiData));
    return -1;
 pDpiData->rx=rxRatio, pDpiData->ry=ryRatio;
 // Create Child Window Objects
 SendMessage(hCtl, (UINT)WM_SETFONT, (WPARAM)hFont1, (LPARAM)TRUE);
 SetWindowText(hCtl, _T(" Text in this control set to RED ON WHITE"));
 SendMessage(hCtl, (UINT)WM_SETFONT, (WPARAM)hFont2, (LPARAM)TRUE);
 SetWindowText(hCtl, _T(" Text in this control set to Green ON BLACK"));
 return 0;

LRESULT fnWndProc_OnCtlColorEdit(WndEventArgs& Wea)
 int iCtlId=GetDlgCtrlID((HWND)Wea.lParam);
    SetTextColor((HDC)Wea.wParam, RGB(255, 0, 0));
    return (LRESULT)GetStockObject(WHITE_BRUSH);
    SetTextColor((HDC)Wea.wParam, RGB(0, 255, 0));
    return (LRESULT)GetStockObject(BLACK_BRUSH);
 return DefWindowProc(Wea.hWnd, WM_CTLCOLOREDIT, Wea.wParam, Wea.lParam);

LRESULT fnWndProc_OnDestroy(WndEventArgs& Wea)
 DpiData* pDpiData=NULL;
 return 0;

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
 WndEventArgs Wea;

 for(unsigned int i=0; i<dim(EventHandler); i++)
        Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
        return (*EventHandler[i].fnPtr)(Wea);

 return (DefWindowProc(hwnd, msg, wParam, lParam));

int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
 TCHAR szClassName[]=_T("Form1");
 MSG messages;
 HWND hWnd;

 wc.lpszClassName = szClassName,                     wc.lpfnWndProc   = fnWndProc;
 wc.hIcon         = LoadIcon(NULL,IDI_APPLICATION),  wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
 wc.hInstance     = hIns,                            wc.hCursor       = LoadCursor(NULL,IDC_ARROW),         
 wc.cbWndExtra    = 3*sizeof(void*);
 hWnd=CreateWindow(szClassName,_T("Edit Ctrl Colors and Fonts"),WS_OVERLAPPEDWINDOW,75,75,338,320,HWND_DESKTOP,0,hIns,0);

 return messages.wParam;

Code: [Select]
#ifndef Form_h
#define Form_h

#define IDC_EDIT1                 2000
#define IDC_EDIT2                 2005
#define dim(x)                    (sizeof(x) / sizeof(x[0]))
#define SizX(x)                   (int)(x * pDpiData->rx)       // For DPI Scaling Calculations And Purposes
#define SizY(y)                   (int)(y * pDpiData->ry)       // For DPI Scaling Calculations And Purposes
extern "C" int                    _fltused=1;
struct WndEventArgs
 HWND                             hWnd;
 WPARAM                           wParam;
 LPARAM                           lParam;
 HINSTANCE                        hIns;

LRESULT fnWndProc_OnCreate        (WndEventArgs& Wea);
LRESULT fnWndProc_OnCtlColorEdit  (WndEventArgs& Wea);
LRESULT fnWndProc_OnDestroy       (WndEventArgs& Wea);

 unsigned int                     iMsg;
 LRESULT                          (*fnPtr)(WndEventArgs&);

const EVENTHANDLER EventHandler[]=
 {WM_CREATE,                      fnWndProc_OnCreate},
 {WM_CTLCOLOREDIT,                fnWndProc_OnCtlColorEdit},
 {WM_DESTROY,                     fnWndProc_OnDestroy}

struct DpiData                   
 double                           rx;
 double                           ry;


Title: Re: Lost and Confused
Post by: Frederick J. Harris on March 25, 2016, 03:31:03 PM
Here's the zip James.

Added later:

Be careful if you compile it as I see above I used "tchar.h" instead of <tchar.h> when compiling with TCLib.lib for the reasons described in my writeup on TCLib.  So you would want to change that if doing a standard build without TCLib.  And "stdio.h" isn't needed except for my debug build with fprintf calls, which I didn't post.

Just had a little bit of a 'runin' with my WinMain declaration.  Don't know why it was acting up on me.  Bedeviled me for about ten minutes very seriously.  Anyway, if it gives you troubles try this...

Code: [Select]
int WINAPI _tWinMain(HINSTANCE hIns, HINSTANCE hPrev, LPTSTR lpCmdLn, int iShow)
Title: Re: Lost and Confused
Post by: Frederick J. Harris on March 25, 2016, 05:14:18 PM
Haven't tried it yet with GCC.  You turned me on to that years ago (the 64 bit TDM versions) and they became my main compilers which I mostly used with Code::Blocks IDE.  Easier to set up projects with CodeBlocks, not so many crazy folders created as Visual Studio, etc.  I'll try it later and report back, or maybe you could.  I really expect it'll be the same and work though.  Thing is, the versions of GCC I was using didn't have support for the SetProcessDPIAware() or IsProcessDPIAware() functions.  That's why I have that SetMyProcessDPIAware() function.  To differentiate between GCC and VS builds.  Maybe they added DPI support.  The latest one I have on any of my machines is GCC 4.8.  I think they're up to 5.1 or 5.2 by now.
Title: Re: Lost and Confused
Post by: James C. Fuller on March 25, 2016, 05:47:46 PM
  Thank you for your effort but it's just way too complicated for my purpose.
Attached is the example I posted to the CodeGuru forum. Much simpler but still the same issue.

The g++ I used is the TDM-GCC compiler from here:

The other most up to date is the nuwen distro 64bit only