AkelPad Forum Index AkelPad
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to read the font size from AkelPad.ini file?

 
Post new topic   Reply to topic    AkelPad Forum Index -> Discussion (English)
View previous topic :: View next topic  
Author Message
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Wed Oct 20, 2010 8:39 pm    Post subject: How to read the font size from AkelPad.ini file? Reply with quote

Hi, I have this problem.
AkelPad.ini contains an entry:
Font=F1FFFFFF000000000000000000000000900100000000000003020131
How to interpret this?
How to read font size (in point), style and others?
I mean the general principle.
Back to top
View user's profile Send private message
FeyFre



Joined: 07 Aug 2007
Posts: 2054
Location: Vinnitsa, Ukraine

PostPosted: Wed Oct 20, 2010 10:52 pm    Post subject: Reply with quote

KDJ, in general case you will be not able to decode values in this option, because in easy to understand form they available only on graphics layer(i.e in Win GDI).

Read this article LOGFONT and you will understand whole thing(this option is actually dumped LOGFONT structure without last field lfFaceName, which have separate option in AkelPad).
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Instructor
Site Admin


Joined: 06 Jul 2006
Posts: 5404

PostPosted: Thu Oct 21, 2010 9:19 am    Post subject: Reply with quote

KDJ
AKD_GETFONTW?
Back to top
View user's profile Send private message Send e-mail
FeyFre



Joined: 07 Aug 2007
Posts: 2054
Location: Vinnitsa, Ukraine

PostPosted: Thu Oct 21, 2010 9:52 am    Post subject: Reply with quote

Instructor
Думаю KDJ всё-таки желал разобраться как оно представляется в настроечном файле(значении реестра), а не через скрипты. Врочем одно-другому не мешает. Smile
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Thu Oct 21, 2010 5:32 pm    Post subject: Reply with quote

FeyFre, Instructor
Gentlemen, thank you very much for your help.
I'm trying to read the font size in the script.
Code:
var hMainWnd = AkelPad.GetMainWnd();
var oSys = AkelPad.SystemFunction();
var hDC  = oSys.Call("user32::GetDC", hMainWnd);
var nDevCap = oSys.Call("gdi32::GetDeviceCaps" , hDC, 90 /*LOGPIXELSY*/);
var nFontSize = oSys.Call("kernel32::MulDiv", 0xF1FFFFFF, 72, nDevCap);

The result is nFontSize = -176160769.
In fact, the font size is 11 pt.
I do not understand this.
Back to top
View user's profile Send private message
Instructor
Site Admin


Joined: 06 Jul 2006
Posts: 5404

PostPosted: Thu Oct 21, 2010 5:58 pm    Post subject: Reply with quote

You were close Smile
Code:
var hMainWnd=AkelPad.GetMainWnd();
var hWndEdit=AkelPad.GetEditWnd();
var oSys=AkelPad.SystemFunction();

WScript.Echo("" + GetFontPoint(hWndEdit));

function GetFontPoint(hWndEdit)
{
  var lpLogFont;
  var lfHeight;
  var hDC;
  var nDevCap;
  var nPointSize=0;

  if (lpLogFont=AkelPad.MemAlloc(92 /*sizeof(LOGFONTW)*/))
  {
    AkelPad.SendMessage(hMainWnd, 1233 /*AKD_GETFONTW*/, hWndEdit, lpLogFont);
    lfHeight=AkelPad.MemRead(lpLogFont + 0 /*offsetof(LOGFONTW, lfHeight)*/, 3 /*DT_DWORD*/);

    if (hDC=oSys.Call("user32::GetDC", hWndEdit))
    {
      nDevCap=oSys.Call("gdi32::GetDeviceCaps", hDC, 90 /*LOGPIXELSY*/);
      nPointSize=-oSys.Call("kernel32::MulDiv", lfHeight, 72, nDevCap);
      oSys.Call("user32::ReleaseDC", hWndEdit, hDC);
    }
    AkelPad.MemFree(lpLogFont);
  }
  return nPointSize;
}
Back to top
View user's profile Send private message Send e-mail
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Thu Oct 21, 2010 8:17 pm    Post subject: Reply with quote

Thanks Instructor.
I suppose I understand.
In AklePad.ini file, the bytes are in reverse order. And lfHeight is negative.
Instead 0xF1FFFFFF, I should write 0xFFFFFFF1.
Code:
var nFontSize = -oSys.Call("kernel32::MulDiv", 0xFFFFFFF1, 72, nDevCap);
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Fri Oct 22, 2010 10:36 pm    Post subject: Reply with quote

I wrote the script FontIniSize.js, which sets the initial font size from AkelPad.ini file.
I was unable to load the font settings using the functions AKD_INIOPEN and AKD_INIGETVALUE. Problem solved otherwise.
The following code generates this error: type mismatch.
Code:
var hMainWnd = AkelPad.GetMainWnd();
var pIniFile = AkelPad.GetAkelDir() + "\\AkelPad.ini";
var hIniFile = AkelPad.SendMessage(hMainWnd, 1366 /*AKD_INIOPEN*/, 0x1 /*POB_READ*/, pIniFile);
Back to top
View user's profile Send private message
FeyFre



Joined: 07 Aug 2007
Posts: 2054
Location: Vinnitsa, Ukraine

PostPosted: Fri Oct 22, 2010 10:42 pm    Post subject: Reply with quote

KDJ
But you also should check if AkelPad stores settings in Registry.
(If, as you said, RegRead does not reads Binary values, you can use native API to read data from registry: advapi32::RegOpenKeyEx advapi32::RegQueryValueEx advapi32::RegCloseKey, etc see MSDN)
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Sat Oct 23, 2010 11:58 am    Post subject: Reply with quote

FeyFre, thank you for the information.
I tried to read data from the registry (REG_BINARY type) using the method ActiveXObject("WScript.Shell").RegRead().
But the return value is "VBArray of integers".
JavaScript does not recognize this value (type=unknown).
Probably should write the script in VBS.
I will try to still do it in JS using Advapi32::RegQueryValueEx.
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Sat Oct 23, 2010 7:49 pm    Post subject: Reply with quote

Unfortunately, I failed to read the registry value "HKLM\Software\ Akelsoft\AkelPad\Options\Font" in JS.
I tried these features:
oSys.Call("Advapi32.dll::RegOpenKeyExW", HKEY_CURRENT_USER, "Software\\Akelsoft\\AkelPad\\Options", 0, KEY_QUERY_VALUE, lphKey);
oSys.Call("Advapi32.dll::RegQueryValueExW", hKey, "Font", 0, lpType, lpData, lpSize);
and
oSys.Call("Advapi32.dll::RegOpenCurrentUser", KEY_QUERY_VALUE, lphKey);
oSys.Call("Advapi32.dll::RegGetValueW", hKey, "Software\\Akelsoft\\AkelPad\\Options", "Font", 0x0000FFFF, lpType, lpData, lpSize);
Back to top
View user's profile Send private message
FeyFre



Joined: 07 Aug 2007
Posts: 2054
Location: Vinnitsa, Ukraine

PostPosted: Sat Oct 23, 2010 9:02 pm    Post subject: Reply with quote

KDJ
Probably you missed something.
It works
Code:
function MakeString(str)
{
   var res = AkelPad.MemAlloc((str.length+1)*_TSIZE);
   AkelPad.MemCopy(res, str, _TSTR);
   return res;
}
var HKCU = 0x80000001;
var KEY_QUERY_VALUE = 0x0001;
var DT_DWORD = 3;
var REG_BINARY = 3;
var ERROR_SUCCES = 0;
var ERROR_MORE_DATA = 234;

var SubKey = MakeString("SOFTWARE\\Akelsoft\\AkelPad\\Options");
var Value = MakeString("Font");
var LPKEY = AkelPad.MemAlloc(4);

var result = AkelPad.SystemFunction().Call("advapi32::RegOpenKeyEx"+_TCHAR,
         HKCU,               //! Parent key
         SubKey,               //! Subkey
         0,                  //! Reserved. must be 0
         KEY_QUERY_VALUE,      //! Desired access
         LPKEY);               //! Result key
if(result == ERROR_SUCCES)
{
   var KEY = AkelPad.MemRead(LPKEY, DT_DWORD);
   var LPTYPE = AkelPad.MemAlloc(4);
      AkelPad.MemCopy(LPTYPE, REG_BINARY, DT_DWORD); //! I prefer to init this value
   var LPDATASIZE = AkelPad.MemAlloc(4);
      AkelPad.MemCopy(LPDATASIZE, 28, DT_DWORD);
   var BUFFER = AkelPad.MemAlloc(28);
   result = AkelPad.SystemFunction().Call("advapi32::RegQueryValueEx"+_TCHAR,
         KEY,      //! Parent key
         Value,      //! Value name
         0,         //! Must be NULL
         LPTYPE,      //! Value type receiver: will be REG_BINARY
         BUFFER,      //! Buffer
         LPDATASIZE);//! Buffer size
   if(   (result == ERROR_SUCCES || result == ERROR_MORE_DATA) &&
      (AkelPad.MemRead(LPTYPE, DT_DWORD)==REG_BINARY)&&   //! Must be binary
      (AkelPad.MemRead(LPDATASIZE, DT_DWORD)>=4)         //! Must be at least 4 bytes
      )
   {
      var lfHeight  =  AkelPad.MemRead(BUFFER,DT_DWORD);
      var hDC       =  AkelPad.SystemFunction().Call("user32::GetDC", AkelPad.GetMainWnd());
      var nDevCap   =  AkelPad.SystemFunction().Call("gdi32::GetDeviceCaps" , hDC, 90 /*LOGPIXELSY*/);
      var nFontSize = -AkelPad.SystemFunction().Call("kernel32::MulDiv", lfHeight, 72, nDevCap);
      AkelPad.SystemFunction().Call("user32::ReleaseDC", AkelPad.GetMainWnd(), hDC);
      AkelPad.MessageBox(0, "Size is: "+nFontSize, "Caption", 0);
   }
   AkelPad.SystemFunction().Call("advapi32::RegCloseKey",KEY);
   AkelPad.MemFree(BUFFER);
   AkelPad.MemFree(LPDATASIZE);
   AkelPad.MemFree(LPTYPE);
}
AkelPad.MemFree(LPKEY);
AkelPad.MemFree(Value);
AkelPad.MemFree(SubKey);

Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Sun Oct 24, 2010 4:35 pm    Post subject: Reply with quote

FeyFre, thanks.
Actually, I made a few mistakes.
I still have a few questions:
Why do you allocate memory at a string of one byte more?
Why do you initiate LPTYPE value?
Why DATASIZE must be at least 4 bytes?
Back to top
View user's profile Send private message
FeyFre



Joined: 07 Aug 2007
Posts: 2054
Location: Vinnitsa, Ukraine

PostPosted: Sun Oct 24, 2010 6:33 pm    Post subject: Reply with quote

Quote:
Why do you allocate memory at a string of one byte more?
First of all, not one byte bigger, byte one char bigger(1 byte for ANSI, 2 bytes for Unicode).
Because WINAPI works with so called Zero-terminated strings - arrays of chars which last element is zero(if you forget put zero there all functions will continue process string until they meet it).
Quote:
Why do you initiate LPTYPE value?
It is my personal habit. In most cases I use functions which require pointers to initialized memory and I used to do such initializations whenever presence or absence such requirements.
Quote:
Why DATASIZE must be at least 4 bytes?
Validation. Because I read 4 bytes from buffer later. In case when this options is broken(manually edited by nasty user) I will be sure I will not try to use invalid data.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
KDJ



Joined: 06 Mar 2010
Posts: 1396
Location: Poland

PostPosted: Sun Oct 24, 2010 8:03 pm    Post subject: Reply with quote

For now I solved the problem of reading from the registry in VBS -> FontIniSize.vbs
Later I'll try to do it in JS. According to the lesson from FeyFre.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Discussion (English) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


SourceForge.net Logo Powered by phpBB © 2001, 2005 phpBB Group