PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3 4 ... 12

Author Topic: Josť, if you're bored...  (Read 5154 times)

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #15 on: August 05, 2018, 01:18:50 AM »

CTextStream can't know in advance if the file is ansi or unicode. However, if the file is unicode with a BOM and you open it as unicode using the OpenUnicode method, it will skip the BOM automatically, i.e. the first line will be returned without the BOM marker.

Maybe we can write a function that checks if the file has an UTF-16 BOM and, if not, call the IsTextUnicode API function, although this function isn't foolproof.

« Last Edit: August 05, 2018, 01:34:35 AM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #16 on: August 05, 2018, 02:13:55 PM »

What about this function?

Code: [Select]
' ========================================================================================
' Determines if a file is likely to contain a form of unicode text.
' ========================================================================================
PRIVATE FUNCTION AfxIsFileUnicode (BYREF wszFileName AS WSTRING) AS BOOLEAN
   DIM hFile AS HANDLE = CreateFileW(@wszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, _
                         OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL)
   IF hFile = INVALID_HANDLE_VALUE THEN RETURN FALSE
   DIM dwFileSize AS DWORD, dwHighSize AS DWORD
   dwFileSize = GetFileSize(hFile, @dwHighSize)
   DIM dwBytesToRead AS DWORD = 1024
   IF dwFileSize < dwBytesToRead THEN dwBytesToRead = dwFileSize
   DIM pBuffer AS UBYTE PTR = CAllocate(1, dwBytesToRead)
   DIM bRes AS BOOLEAN, dwBytesRead AS DWORD
   bRes = ReadFile(hFile, pBuffer, dwBytesToRead, @dwBytesRead, NULL)
   IF bRes THEN bRes = IsTextUnicode(pBuffer, dwBytesRead, NULL)
   IF pBuffer THEN DeAllocate(pBuffer)
   IF hFile THEN CloseHandle(hFile)
   RETURN bRes
END FUNCTION
' ========================================================================================

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #17 on: August 05, 2018, 04:19:46 PM »

I'm going to add a file called AfxFile.inc that will give access to all the file related classes and functions:

Code: [Select]
' ########################################################################################
' Microsoft Windows
' File: AfxFile.inc
' Contents: Includes all the WinFBX procedures and functions that deal with files and folders.
' Compiler: Free Basic 32 & 64 bit
' Copyright (c) 2018 Josť Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#pragma once

#include once "Afx/AfxWin.inc"
#include once "Afx/CStream.inc"
#include once "Afx/CTextStream.inc"
#include once "Afx/CFindFile.inc"
#include once "Afx/CFileSys.inc"
#include once "Afx/CFileTime.inc"
« Last Edit: August 05, 2018, 04:26:28 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #18 on: August 05, 2018, 04:28:56 PM »

Excellent idea to have an AfxFile.inc file to encapsulate all of the file routines. I will use it a lot.
The AfxIsFileUnicode  is a great addition as well.

If you ever get bored again, just ask, I have many more ideas!  LOL  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #19 on: August 05, 2018, 05:15:18 PM »

The attached file contains the updated AfxWin.inc and CStream.inc files, and the new AfxFile.inc. If somebody doesn't need to work with unicode, he can use the FB native functions instead.

> If you ever get bored again, just ask, I have many more ideas!  LOL

August is a good month because I don't have many things to do. I stopped adding code because of the lack of testers. I don't want to write code that nobody will use.

The WinFBX repository has been updated with these changes.
« Last Edit: August 05, 2018, 05:19:06 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #20 on: August 06, 2018, 10:35:03 AM »

Thanks Jose, I will ensure that the next WinFBE Suite upload includes the latest WinFBX code.
I will be replacing all internal WinFBE file handling code with this new AfxFile code.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #21 on: August 06, 2018, 11:41:08 AM »

A question I get a lot from ex-PBers is a replacement for XPRINT commands. Early in my FB learning I started to build on a previous XPRINT type of code (FBWinPrint) - I called mine WinXPrint. It is horrible looking code by today's standards.
https://www.freebasic.net/forum/viewtopic.php?f=3&t=25321&p=227827
If you're feeling bored and looking for a nice challenge - XPRINT code would certainly fill a gap in the FB library universe.

Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #22 on: August 06, 2018, 11:48:35 AM »

....and an all encompassing tutorial on how to build and use DLL's in Windows using FreeBASIC. Especially figuring out a good way to handle import libraries *.a which is a real pain compared to PowerBASIC. I tried to learn it many months ago and built a rudimentary utility "MakeLIB" that attempted to automate the process. That needs to be revisited.  http://www.planetsquires.com/protect/forum/index.php?topic=3675.0
I know that you use dynamic loading of the DLL functions but it would be cool if it was easy like PB.  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #23 on: August 06, 2018, 01:44:05 PM »

A question I get a lot from ex-PBers is a replacement for XPRINT commands. Early in my FB learning I started to build on a previous XPRINT type of code (FBWinPrint) - I called mine WinXPrint. It is horrible looking code by today's standards.
https://www.freebasic.net/forum/viewtopic.php?f=3&t=25321&p=227827
If you're feeling bored and looking for a nice challenge - XPRINT code would certainly fill a gap in the FB library universe.

I don't even have a printer... :)

Maybe this code could be a starting point: http://www.planetsquires.com/protect/forum/index.php?topic=4059.msg30559#msg30559

Johan Klassen

  • FireFly3 Registered User
  • Junior Member
  • *
  • Posts: 73
  • FF3 User
Re: Josť, if you're bored...
« Reply #24 on: August 06, 2018, 01:44:17 PM »

actually you can use a dll without an import lib, you can #inclib "mydll" where "mydll" is mydll.dll
the dll probably needs to reside where the program using it resides, beware that if you have an import lib of the dll then perhaps FB may link agains the import lib, have not tested this case, only made sure that there was no import lib, but the dll only.
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #25 on: August 06, 2018, 04:25:46 PM »

I know that you use dynamic loading of the DLL functions but it would be cool if it was easy like PB.  :)

The only thing that comes to my mind is to prepare the .bi file as:

Code: [Select]
TYPE PFNSQLITE3LIBVERSIONNUMBERPROC AS FUNCTION CDECL () AS LONG
DIM SHARED sqlite3_libversion_number AS PFNSQLITE3LIBVERSIONNUMBERPROC
' ... more procedures

FUNCTION InitSqLite3Lib (BYREF wszDllPath AS WSTRING = "sqlite3.dll") AS HMODULE
   DIM hLib AS HMODULE
   hLib = LoadLibraryW(wszDllPath)
   IF hLib = NULL THEN RETURN NULL
   sqlite3_libversion_number = CAST(PFNSQLITE3LIBVERSIONNUMBERPROC, GetProcAddress(hLib, "sqlite3_libversion_number"))
   ' ... more procedures
   RETURN hLib
END FUNCTION

Then, to use it:

Code: [Select]
InitSqLite3Lib("sqlite3_32.dll")
print sqlite3_libversion_number()

If it has no parameters, the use of () is mandatory; otherwise, it will print the value of the sqlite3_libversion_number pointer instead of calling the sqlite3_libversion_number function.

Another possibility is to build the .dll as a low-level COM server and use a class instead of functions.

Of course, the best solution would be to modify the compiler to accept a LIB or IMPORT clause in the declare.
« Last Edit: August 06, 2018, 04:41:20 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #26 on: August 07, 2018, 11:15:04 AM »

Some ideas for a printing class:

1) Methods to attach a printer: AttachPrinter and ChoosePrinter.

2) Properties to set printer values, such paper size, orientation, etc.

3) Pages can be constructed using a memory bitmap and drawn using GDI and/or GDI+ and passed to a method of the class that will send them to the printer.

Criticism?
« Last Edit: August 07, 2018, 09:01:29 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #27 on: August 08, 2018, 02:11:40 PM »

Some ideas for a printing class:

1) Methods to attach a printer: AttachPrinter and ChoosePrinter.

2) Properties to set printer values, such paper size, orientation, etc.

3) Pages can be constructed using a memory bitmap and drawn using GDI and/or GDI+ and passed to a method of the class that will send them to the printer.

Criticism?


Sorry for my lateness. Yes, that is the kind of approach to a printing class that was in my mind also. Some basic properties to set elements of what is being printed, and then constructing the document in memory and output to the printer via api methods. Also being able to handle different fonts, colors, and graphics. It would be a great addition. Not sure that a Print Preview would be an absolute necessity but it would be cool also.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #28 on: August 08, 2018, 02:13:23 PM »

I just finished reviewing WinFBE code. There are 10 source code files that contain 22 references to FB related file handling routines. I will post a new WinFBE package tonight and then start with replacing the FB file handling routines with Jose's classes.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #29 on: August 08, 2018, 02:17:00 PM »

A first try.

The idea is to create an instance of the CPrint class and attach a printer to it with AttachPrinter or ChoosePrinter.

Code: [Select]
'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "Afx/CPrint.inc"
USING Afx

DIM pPrint AS CPrint
pPrint.AttachPrinter("Bullzip PDF Printer")

Then we can use the CMemBmp class to create a memory bitmap (with the dimensions returned by the GetHorizontalResolution and GetVerticalResolution methods of the CPrint class), draw its contents using GDI or GDI+ and send it to the PrintBitmap method.

For documents with more than one page, we could build an array of memory bitpamps and send it to a future new method of the CPrint class that will print them.

Pages: 1 [2] 3 4 ... 12