NO

Recent Posts

Pages: 1 ... 8 9 [10]
91
Announcements / Re: Version 10.00 (RC2) is now available
« Last post by John Z on July 13, 2020, 05:00:22 pm »
Thanks Pelle,

I appreciate you taking a look at this and figuring it out. 
Saves my sanity looking for where I went wrong :)

I'll implement your suggestion.

Thanks again,
John
92
I could argue there is a difference between "copy" and "insert", but it doesn't really matter much. The choice was made many years ago, when I wrote this part of the IDE, and the behavior matched exactly what I wanted back then. Now it's a little late to change things...
Ok, no problem.  :)

Then I cannot use copy in my way.  ;)
93
Announcements / Re: Version 10.00 (RC2) is now available
« Last post by Pelle on July 12, 2020, 08:12:25 pm »
It's a compiler bug, due to imprecise alias/liveness info. The compiler thinks ext[] and LineIn[] can share stack space, which they can't.
The quick fix is to add
Code: [Select]
#pragma pack_stack(off)but a proper fix looks much harder. I'm out of ideas at the moment...
94
Beginner questions / Re: RichEdit Syntax Coloring
« Last post by Robby on July 11, 2020, 06:42:51 pm »
This might be of help for those experimenting with EM_SETCHARFORMAT...
Code: [Select]
#define WIN32_DEFAULT_LIBS //Avoid ShellExecute linker errors.
#define WIN32_LEAN_AND_MEAN 
#include <windows.h>   
#include <commctrl.h>
#include <richedit.h>
#include <ntsecAPI.h>
#include <shellapi.h>
#include <wininet.h>
#include "main.h"

static LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
HFONT MakeFontEx(LPCWSTR, int, int, DWORD, DWORD);

// ****************************************************************************

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WCHAR *pszCmdLine, int nCmdShow)

  // Initialize common controls, needed for MANIFEST's
  INITCOMMONCONTROLSEX icc = {sizeof(icc), ICC_WIN95_CLASSES};
  InitCommonControlsEx(&icc);

  HMODULE hRichEditLib = LoadLibraryW(L"MsftEdit.dll");  /* Load RichEdit "RichEdit50W" v4.1 */

   
  // Register the main window class
  WNDCLASSEX WinClass;
  WinClass.cbSize        = sizeof(WNDCLASSEX);
  WinClass.style         = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
  WinClass.lpfnWndProc   = MainWndProc;
  WinClass.cbClsExtra    = 0;
  WinClass.cbWndExtra    = 0;
  WinClass.hInstance     = hInstance;
  WinClass.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
  WinClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  WinClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);   
  WinClass.lpszMenuName  = 0;
  WinClass.lpszClassName = L"SimpleClass"; 
  WinClass.hIconSm       = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));   

  HWND hWnd;
  if (RegisterClassEx(&WinClass))

    hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
                          L"SimpleClass",
                          L"RichEdit",
                          WS_OVERLAPPEDWINDOW,
                          (GetSystemMetrics(SM_CXSCREEN) - 500) / 2, //Center window on desktop
                          (GetSystemMetrics(SM_CYSCREEN) - 300) / 2, //Center window on desktop
                          500,
                          300,
                          NULL,
                          NULL,
                          hInstance,
                          0);
   
   // Show and paint the main window
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   // Pump messages until we are done
   MSG msg;
   while (GetMessage(&msg, NULL, 0, 0) > 0)
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }

   FreeLibrary(hRichEditLib);

   return msg.wParam;
}

//****************************************************************************

static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   wchar_t pURL[INTERNET_MAX_URL_LENGTH];
   CREATESTRUCT * pCreateStructure;
   ENLINK *param = (ENLINK *)lParam;

   switch (msg)
   {
     case WM_CREATE:
       pCreateStructure = (LPCREATESTRUCT) lParam; //Get instance from wWinMain
       static HINSTANCE hInstance;
       hInstance = pCreateStructure->hInstance;

       #ifdef _WIN64
         SetWindowText(hwnd, L"Simple app - 64bit");
       #else
         SetWindowText(hwnd, L"Simple app - 32bit");
       #endif

       RECT rc;
       GetClientRect(hwnd, &rc); //Get client rectangle

       //Create a richedit control
       static HWND hEdit;
       hEdit = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_RIGHTSCROLLBAR, L"RichEdit50W", L"",
                              WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL |
                              ES_WANTRETURN | ES_SAVESEL | ES_NOHIDESEL | WS_VSCROLL | WS_TABSTOP,
                              2, 2, rc.right - 4, rc.bottom - 4,
                              hwnd, NULL, hInstance, NULL);
       //URL detection
       SendMessage(hEdit, EM_AUTOURLDETECT, TRUE, 0);
       SendMessage(hEdit, EM_SETEVENTMASK, 0, ENM_LINK | ENM_PROTECTED);

       //Create a font
       static HFONT hFont;
       hFont = (HFONT) MakeFontEx(L"Segoe UI", 12, FW_NORMAL, FALSE, FALSE); //Create desired font
       SendMessage(hEdit, WM_SETFONT, (WPARAM) hFont, TRUE);

       SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)
       TEXT("\n RichEdit50W - RichEdit make powerfull controls!\n\n"
            " http://www.smorgasbordet.com/pellesc/\n"
            " {Double click to go...}")); //Set text

       //Set control background color
       SendMessage(hEdit, EM_SETEDITSTYLE, SES_EXTENDBACKCOLOR, 0); //Extend background color
       SendMessage(hEdit, EM_SETBKGNDCOLOR, 0, RGB(200, 200, 200)); //Set background color

       //Set selection fore and back color
       CHARFORMAT2W ChrFormat = {sizeof(CHARFORMAT2),0,0,0,0,0,0,0,L"",0,0,0,0,0,0,0,0,0,0,0};
       ChrFormat.dwMask       = CFM_COLOR | CFM_BACKCOLOR; //Flag for fore and back color
       ChrFormat.crTextColor  = RGB(200, 0, 255);            //Fore color
       ChrFormat.crBackColor  = RGB(255, 255, 0);          //Back color
       SendMessage(hEdit, EM_SETSEL, 29, 40);              // Select some text
       SendMessage(hEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &ChrFormat); //Set selection fore and back color
       SendMessage(hEdit, EM_SETSEL, -1, -1); //Remove selection by moving caret to the end
       SetFocus(hEdit); //Set focus
       break;

     case WM_NOTIFY:
       if((param)->nmhdr.hwndFrom == hEdit) //Only hEdit
       {
         if((param)->nmhdr.code == EN_LINK) //If we got EN_LINK code
         {
           if((param)->msg == WM_LBUTTONDBLCLK) //If it is a double click
           {
             DWORD UrlLen = ((param)->chrg.cpMax - (param)->chrg.cpMin + 2); //Get lenght of URL
             TEXTRANGE TxtRange;
             TxtRange.chrg = (param)->chrg; //Copy text range
             TxtRange.lpstrText = pURL;  //Point to URL
             SendMessage(hEdit, EM_GETTEXTRANGE, 0, (LPARAM) &TxtRange); //Get the URL text
             ShellExecute(NULL, L"open", pURL, L"", L"", SW_SHOW); //Open the URL using default browser.
             PostMessage(hEdit, EM_SETSEL, (param)->chrg.cpMin, (param)->chrg.cpMin); //Remove selection
           }
         }
         return FALSE;
       }
       break;
     
     case WM_SIZE:
       if (wParam != SIZE_MINIMIZED)
       {
         MoveWindow(hEdit, 2, 2, LOWORD(lParam) - 4, HIWORD(lParam) - 4, TRUE); //Resize the richedit control
       }
       break;

     case WM_DESTROY:
       PostQuitMessage(0); //Say bye!
       break;

     default:
       return DefWindowProc(hwnd, msg, wParam, lParam);
       break;
   }
}

//****************************************************************************

void MakeFontExEnumCharSet(ENUMLOGFONT elf, NEWTEXTMETRIC ntm, DWORD FontType, DWORD CharSet)
 {
   //Get type of character set - ansi, symbol. A must for some fonts.
   CharSet = elf.elfLogFont.lfCharSet;
 }

//****************************************************************************

HFONT MakeFontEx(LPCWSTR wFontName, int PointSize, int fBold, DWORD fItalic, DWORD fUnderline)
 {
 HDC hDC = GetDC(HWND_DESKTOP);
 DWORD CyPixels = GetDeviceCaps(hDC, LOGPIXELSY);
 DWORD CharSet;
 EnumFontFamilies(hDC, wFontName, &MakeFontExEnumCharSet, CharSet);
 ReleaseDC(HWND_DESKTOP, hDC);
 PointSize = 0 - (PointSize * CyPixels) / 72;

 HFONT font;
 font =  CreateFont(PointSize, 0, //Height, width(default=0)
                    0, 0,         //Escapement(angle), orientation
                    fBold,        //Weight (%FW_DONTCARE = 0, %FW_NORMAL = 400, %FW_BOLD = 700)
                    fItalic,      //Italic
                    fUnderline,   //Underline
                    FALSE,        //StrikeThru
                    CharSet, OUT_TT_PRECIS,
                    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                    FF_DONTCARE, wFontName); 
  return font;
 
  }

//****************************************************************************
//
95
Announcements / Re: Version 10.00 (RC2) POSSIBLE Optimize speed bug
« Last post by John Z on July 11, 2020, 05:56:31 pm »
Hi,

Back on RC1 I mentioned a possible bug using optimizations.  V10 was/is giving me different results compared to V9.  I have a small portion of code, from a huge program, that either demonstrates the possible bug, or demonstrates I need to be a better programmer (undoubtedly true regardless ;) ).

This program will run 'correctly' using no optimizations, optimize for size, and optimize for size more in V10 RC2. However it will fail to run correctly when using optimize for speed or optimize for speed more in V10 RC2.  Using V9.009 it always works with all original code as written and any optimization desired.  I have stripped out many, many, lines of code to get a small example for V10.

It 'appears' that a pointer changes.  A statement
memset(p_ext,0,49); // clear extension storage is clearing a different pointer space that belonging to p_LineIn. 

If I change this one line to clear by writing nothing
swprintf(p_ext,49,L"%s",""); // clear extension storage then the optimizations ALL work and the program runs correctly.

There are other lines of code that can be removed and the result changes as well, but they seem unrelated to clearing p_ext.  Also using wmemset has the same issue as memset.  If there is a programmer pointer error I've gone blind to it.....

At the top of mainc. there are some instructions on what lines to comment out to try it. When it works correctly two message boxes will show with identical strings and the program will quit.  When it fails the second message box is blank, a third box will indicate that it failed.

I will really appreciate any help, or tips, and your time to look this over, hopefully I won't be too embarrassed!

John
96
I could argue there is a difference between "copy" and "insert", but it doesn't really matter much. The choice was made many years ago, when I wrote this part of the IDE, and the behavior matched exactly what I wanted back then. Now it's a little late to change things...
97
Dialog controls have a numeric id which the IDE attempts to map to symbolic names. See menu "Resource" -> "Symbols...".
No metadata of any kind (would be horribly complicated). A copy is a copy, so numeric id is copied (lets say 4001) and then you change the symbolic name of 4001 from "some_name_1" to "some_name_2". All ids with number 4001 is now mapped to "some_name_2". Clear?


No because if you copy for example a button whose name is IDC_HELLO and insert it in the same dialog copied button will receive a new name (numeric id) like 4002. However if button is inserted into a foreign dialog its name is still IDC_NAME.

Why is there a difference?

What happend to me? I created a new dialog based on an other dialog. So I copied this dialog and changed it. I didn‘t recognized that by changing control names of new dialog old dialog would also be changed. And after a while I compiled project and realized that old dialog didn't work any more because numeric ids of old dialog changed.


Would it not be better if an inserted control would be receive a new numeric id by default? 
98
Hi HelloWorld,

A bit of further input.  This method of copying does not impair functionality.  Different dialog boxes can have the same Button ID and will work correctly, because the message is handled by the procedure assigned to the Dialog Box for processing.  So another box with the same Button ID will not be processed inadvertently, the message won't get to it.

However -

If you really, really, really want to change it you can do it this way.
First you open whatever .h file is being used for your resource file and add a symbol(s) and ID(s) you want to use for Dialog box 2, Button IDs.  If your resource file is main.rc then main.h would be opened

#define IDCANCEL2 4076  //example add (be sure number is not already is use)
Save the .h file

The open the .rc resource file as TEXT (right click on the file, 'open as', text)
In the resource file locate the second Dialog box definition
Find the button you want to change
  CONTROL "Cancel", IDCANCEL, "Button", WS_TABSTOP, 160, 23, 45, 15
change to
  CONTROL "Cancel", IDCANCEL2, "Button", WS_TABSTOP, 160, 23, 45, 15

Save the file.  Now it should have the new ID.

It takes a bit and not really necessary but it can be done.

John Z
99
I can't see a bug here. This is how it works.

Dialog controls have a numeric id which the IDE attempts to map to symbolic names. See menu "Resource" -> "Symbols...".
No metadata of any kind (would be horribly complicated). A copy is a copy, so numeric id is copied (lets say 4001) and then you change the symbolic name of 4001 from "some_name_1" to "some_name_2". All ids with number 4001 is now mapped to "some_name_2". Clear?
100
Sometimes if I copy controls from one dialog to another dialog both controls have the same name. If I change name of one control other control will also change its name.

Steps to Reproduce:
1.) Start PellesC and create a new resource
2.) Add two dialogs to resource
3.) Open first dialog, add a new button, open properties tab and set button name to IDC_HELLO
4.) Copy the button via [Strg]+[c], open second dialog and insert button via [Strg]+[v]
5.) Name of inserted button is IDC_HELLO. Change it to IDC_HELLO_2.
6.) Switch to first dialog and look to the button name. Its name is IDC_HELLO_2 and not IDC_HELLO!

In this state both buttons seems to share the same internal string, ID or whatever. Whenever you change the name of one button other button will also receive new name.


I attached resource file containing .rc and .h file.
Pages: 1 ... 8 9 [10]