May 08, 2024, 02:27:38 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Fontrequest and some noobs questions...

Started by ExMember001, July 14, 2006, 10:15:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ExMember001

I have some problem with Fontrequest...
i have use the richedit example code to put in my Oncontrol sections... the only difference with the example is that My program is a window and the example is a dialog.
i was sure that this will work instantly but it doesnt...
the program compile ands run, but when i click on the fontrequest button the program crash

this is the code i use:
if(nNotifyCode = 0)
{
  fontname = FONTREQUEST(*(CWindow)this,size,weight,flags,textclr,oldfont);
  if fontname <> ""
  {
oldfont = fontname;
if weight = 700 bold = 1 ELSE bold = 0;
m_Red->SetSelFont(fontname,size,bold,flags);
m_Red->SetSelColor(textclr); 
m_Red->SetFocus();
  }
}


i'm sure that the *(CWindow)this as something to do with this, because this is the part i dont really understand right now
what does it mean? and what the "this" mean exactly? and in which occasioni should use "this"?

Ionic Wind Support Team

'this' is a pointer to instance of the class that the method is in.

I would need to see more of the code, for example where is this handler located?  Is m_Red a valid pointer? etc.

Ionic Wind Support Team

ExMember001

here is the full code:

////////////////////////////////////////////////////////////////////////////////
// Pour InsÃÆ'Ã,©rer une Image
#use "oleaut32.lib"

////////////////////////////////////////////////////////////////////////////////
// API CALL
DECLARE IMPORT,ShellExecuteA(UINT hwnd,pointer pOp,pointer pFile,pointer pParam,pointer pDir,int nShow),UINT;

////////////////////////////////////////////////////////////////////////////////
// Variable Globale
#define RICHEDIT 100
#define B_Police 20
#define C_GCD    21
#define B_Marge  22
#define B_Degre  23

int run;
int size,weight,textclr,bold,flags;
int Comb_sel;
string fontname,oldfont,filter,imagefile;

////////////////////////////////////////////////////////////////////////////////
//PopotteMain definitions
class PopotteMain : CWindow
{

int l,t,w,h;

declare TBWindow();
declare _TBWindow();

declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare virtual OnCreate(),int;
declare virtual OnEraseBkgnd(),int;
declare virtual OnMenuPick(int nID),int;
declare virtual OnSize(int nType,int cx,int cy),int;

    declare virtual InsertImage(string Path, CRichEdit *re1);
declare virtual OuvrirFichier();

CToolBar m_tool;
CMenu m;

//create pointer to ComboBox class
CCOMBOBOX *m_Comb;

//create pointer to Richedit class
CRichEdit *m_Red;

}

////////////////////////////////////////////////////////////////////////////////
global sub main()
{

//the default font properties
fontname = "Time New Roman";
oldfont = fontname;
size = 12;
weight = 400;

//CrÃÆ'Ã,©ÃÆ'Ã,© la Window Principal du programme
PopotteMain Win;

Win.Create(0,0,640,480,
AWS_VISIBLE | AWS_SYSMENU | AWS_SIZE | AWS_MINIMIZEBOX | AWS_MAXIMIZEBOX | AWS_AUTODRAW,0,
"Popotte v3.0",null);

//add Buttons
Win.AddControl(CTBUTTON,"Police",10,45,70,20,0x50010000,0x0,B_Police);
Win.AddControl(CTBUTTON,"Marges",170,45,70,20,0x50010000,0x0,B_Marge);
Win.AddControl(CTBUTTON,"DegrÃÆ'Ã,©",245,45,70,20,0x50010000,0x0,B_Degre);

//Add Combobox
win.m_Comb = new(CCOMBOBOX,1);
win.m_Comb->Create(85,43,80,75,0x50810603,C_GCD,"",win);
win.m_Comb->AddString("Gauche");
win.m_Comb->AddString("CentrÃÆ'Ã,©");
win.m_Comb->AddString("Droite");
win.m_Comb->SetCurSel(0);

//add richedit control
win.m_Red = new(CRichEdit,1);
win.m_Red->Create(10,70,610,345,0x50B110C4,RICHEDIT,"",win);
win.m_Red->SetDefaultFont(fontname, size, 0,0);

//set the background color here
Win.SetWindowColor(RGB(200,200,255));

Win.SetFocus(RICHEDIT);

//Main loop
run = 1;
do{wait();}until run = 0;
win.Destroy();
delete win.m_Comb;
delete win.m_Red;

return;
}

////////////////////////////////////////////////////////////////////////////////
//Handler subroutine
////////////////////////////////////////////////////////////////////////////////

//TBWindow Implementation
PopotteMain::TBWindow()
{
}

PopotteMain::_TBWindow()
{
}

////////////////////////////////////////////////////////////////////////////////
//Fenetre Principal Initiation
PopotteMain::OnCreate(),int
{
//create the toolbar and set the button tooltips
int tbarray[12];
tbarray = 2,3,4,5,0,6,0,7,8,9,0,10;
m_tool.LoadFromFile(GetStartPath()+"toolbar.bmp",tbarray,12,ACCS_TOP|ATBSTYLE_TRANSPARENT|ATBSTYLE_FLAT|ATBSTYLE_TOOLTIPS,98,this);
m_tool.SetLabels("Livres|Nouvelle|Ouvrir|Sauver|Image|Couper|Copier|Coller|Imprimer||");
m_tool.SetToolTip(2,"Ouvrir Mes Livres de Recettes");
m_tool.SetToolTip(3,"CrÃÆ'Ã,©er une Nouvelle Recette");
m_tool.SetToolTip(4,"Ouvrir Un Fichier");
m_tool.SetToolTip(5,"Sauvegarder votre Recette");
m_tool.SetToolTip(6,"InsÃÆ'Ã,©rer Une Image");
m_tool.SetToolTip(7,"Couper le texte SÃÆ'Ã,©lectionnÃÆ'Ã,© dans le Presse-Papier");
m_tool.SetToolTip(8,"Copier le texte SÃÆ'Ã,©lectionnÃÆ'Ã,© dans le Presse-Papier");
m_tool.SetToolTip(9,"Coller le texte SÃÆ'Ã,©lectionnÃÆ'Ã,© dans le Presse-Papier");
m_tool.SetToolTip(10,"Imprimer la Recette");
m_tool.Resize();

//CrÃÆ'Ã,©ÃÆ'Ã,© le menu principal
m.BeginMenu();
m.MenuTitle( "&Fichier");
m.MenuItem( "Nouvelle Recette",0,1);
m.MenuItem( "Mes Livres de Recettes",0,2);
m.Separator();
m.MenuItem( "Ouvrir un Fichier",0,3);
m.MenuItem( "Exporter Format ASCII",0,4);
m.Separator();
m.MenuItem( "Imprimer",0,5);
m.Separator();
m.MenuItem( "Sauvegarder",0,6);
m.Separator();
m.MenuItem( "Quitter",0,7);
m.MenuTitle( "&ÃÆ'ââ,¬Â°diter");
m.MenuItem( "Annuler",0,8);
m.Separator();
m.MenuItem( "Tout SÃÆ'Ã,©lectionner",0,9);
m.Separator();
m.MenuItem( "Rechercher",0,10);
m.Separator();
m.MenuItem( "Couper",0,11);
m.MenuItem( "Copier",0,12);
m.MenuItem( "Coller",0,13);
m.MenuTitle( "&Options");
m.MenuItem( "Changer la Couleur de la FenÃÆ'Ã,ªtre",0,14);
m.MenuItem( "Changer la Couleur de la Barre d'Outils",0,15);
m.Separator();
m.MenuItem( "Ouvrir Mes Livres au DÃÆ'Ã,©marrage",AMF_CHECKED,16);
m.MenuItem( "Ouvrir la DerniÃÆ'Ã,¨re Recette au DÃÆ'Ã,©marrage",AMF_CHECKED,17);
m.Separator();
m.MenuItem( "DÃÆ'Ã,©tection Automatique des Hyperliens",AMF_CHECKED,18);
m.MenuTitle( "&Outils");
m.BeginPopup( "InsÃÆ'Ã,©rer la Date");
m.MenuItem( "MM-JJ-AAAA",0,19);
m.MenuItem( "JJ-MM-AAAA",0,20);
m.MenuItem( "Date Longue",0,21);
m.EndPopup();
m.Separator();
m.MenuItem( "Table des CaractÃÆ'Ã,¨res",0,22);
m.MenuTitle( "&Aide");
m.MenuItem( "Truc du Jour",0,23);
m.Separator();
m.MenuItem( "Aide En-ligne",0,24);
m.Separator();
m.MenuItem( "Kryptik CrÃÆ'Ã,©ations",0,25);
m.Separator();
m.MenuItem( "ÃÆ'€ Propos",0,26);
    m.EndMenu();
//Attacher le Menu
SetMenu(m.Detach());

CenterWindow();

return true;
}

////////////////////////////////////////////////////////////////////////////////
// Controle le Sizing de la fenetre principal
PopotteMain::OnSize(int nType,int cx,int cy),int
{
//resize the toolbar
m_tool.Resize();

//resize the Richedit control
if m_Red->m_hwnd
{
      m_Red->SetSize(10,70,cx-22,cy-81);
}

return true;
}

////////////////////////////////////////////////////////////////////////////////
//Fenetre Pricipal Ferme
PopotteMain::OnClose(),int
{
run = 0;
    return true;
}

////////////////////////////////////////////////////////////////////////////////
//Controle les Controles de la Fenetre Principal
PopotteMain::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select nID
{
//handle toolbar buttons
case 2: /* Ouvrir Dialog Mes Livres */

if(nNotifyCode = 0)
{
}

case 3: /* Nouvelle Recette */

if(nNotifyCode = 0)
{
m_Red->SetSel(0, -1,true);
m_Red->ReplaceSel("",true);
}

case 4: /* Ouvrir un Fichier */

    if(nNotifyCode = 0)
{
  OuvrirFichier();
}
 
case 5: /* Sauvegarder */

if(nNotifyCode = 0)
{
}

case 6: /* InsÃÆ'Ã,©rer Une image */

if(nNotifyCode = 0)
{
imagefile = FILEREQUEST("Select image",this, true,
                "All supported types (bmp,jpg,gif,wmf,ico)|*.bmp;*.jpg;*.gif;*.wmf;*.ico||","");

if imagefile <> ""
{
  InsertImage(imagefile,m_Red);
  m_Red->SetFocus();
}
}
 
case 7: /* Couper */

if(nNotifyCode = 0)
{
  m_Red->Cut();
}

case 8: /* Copier */

if(nNotifyCode = 0)
{
  m_Red->Copy();
}

case 9: /* Coller */

if(nNotifyCode = 0)
{
  m_Red->Paste();
}

case 10: /* Imprimer */

    if(nNotifyCode = 0)
{
  m_Red->PrintDocument(0);
}

//Handle Other Controls
case B_Police:

    if(nNotifyCode = 0)
{
  fontname = FONTREQUEST(*(CWindow)this,size,weight,flags,textclr,oldfont);
  if fontname <> ""
  {
oldfont = fontname;
if weight = 700 bold = 1 ELSE bold = 0;
m_Red->SetSelFont(fontname,size,bold,flags);
m_Red->SetSelColor(textclr); 
m_Red->SetFocus();
  }
}

case C_GCD: /*ComboBox*/

    if(nNotifyCode = 0)
{
  Comb_sel = m_comb->GetCurSel();
  Select Comb_sel
  {
        case 0:
    m_Red->SetFocus();
case 1:
    m_Red->SetFocus();
case 2:
    m_Red->SetFocus();
  }
}

case B_Marge:

    if(nNotifyCode = 0)
{
}

case B_Degre:

    if(nNotifyCode = 0)
{
  m_Red->ReplaceSel("ÂÃ,°",true);
  m_Red->SetFocus();
}


//Handle richedit control
case RICHEDIT:

}
return true;
}

////////////////////////////////////////////////////////////////////////////////
// Controle les Items du Menu
PopotteMain::OnMenuPick(int nID),int
{
Select nID
{
  Case 1: /* Nouvelle Recette */
      m_Red->SetSel(0, -1,true);
  m_Red->ReplaceSel("",true);
 
  Case 3: /* Ouvrir Fichier */
      OuvrirFichier();
 
  Case 4: /* Exporter ASCII */
      filename = FILEREQUEST("Exporter Format ASCII",this,0,"Fichier Texte (txt)|*.txt||","txt");
  if filename <> ""
  {
m_Red->SaveFile(filename,0);
  }
 
  Case 5: /* Imprimer */
      m_Red->PrintDocument(0);

      Case 7: /* Quitter */
      run = 0;
 
  Case 8: /* Annuler */
      m_Red->Undo();
 
  Case 9: /* Tout SÃÆ'Ã,©lectionner */
      m_Red->SetSel(0, -1,true);
 
  Case 11:/* Couper */
      m_Red->Cut();
 
  Case 12:/* Copier */
      m_Red->Copy();
 
  Case 13:/* Coller */
      m_Red->Paste();
 
  Case 19:/* Date MM JJ AAAA */
      m_Red->ReplaceSel(Date$());
 
  Case 20:/* Date JJ MM AAAA */
      m_Red->ReplaceSel(Date$());
 
  Case 21:/* Date Longue */
      m_Red->ReplaceSel(Date$());
 
  Case 22:/* Table des caractere */
      ShellExecuteA(0,"open","charmap.exe",null,0,1);
    }

return true;
}

////////////////////////////////////////////////////////////////////////////////
// Skin de la Toolbar
PopotteMain::OnEraseBkgnd(),int
{
//simple example of skinning the toolbar with a color.
RECT rc = m_tool.GetWindowRect();
DrawRect(0,0,rc.right-rc.left+1,rc.bottom-rc.top,RGB(200,200,255),RGB(200,200,255));

return true;
}

////////////////////////////////////////////////////////////////////////////////
/* code by Sapero */
// Insert Image object to richedit control
#define S_OK 0
#define CF_BITMAP 2
// temporary guids
struct GUID {int x[4];}
struct REFIID {int x[4];}

interface IUnknown
{
  declare virtual QueryInterface(REFIID *riid, void *lplpObj),int;
  declare virtual AddRef(),int;
  declare virtual Release(),int;
}

interface IPicture : IUnknown
{
  declare virtual get_Handle(/*out*/OLE_HANDLE *pHandle),int;
  declare virtual get_hPal(/*out*/OLE_HANDLE *phPal),int;
  declare virtual get_Type(/*out*/SHORT *pType),int;
  declare virtual get_Width(/*out*/OLE_XSIZE_HIMETRIC *pWidth),int;
  declare virtual get_Height(/*out*/OLE_YSIZE_HIMETRIC *pHeight),int;
  declare virtual Render(
            /* [in] */ HDC hDC,int x,int y,int cx,int cy,
            /* [in] */ OLE_XPOS_HIMETRIC xSrc,
            /* [in] */ OLE_YPOS_HIMETRIC ySrc,
            /* [in] */ OLE_XSIZE_HIMETRIC cxSrc,
            /* [in] */ OLE_YSIZE_HIMETRIC cySrc,
            /* [in] */ RECT *pRcWBounds),int;

  declare virtual set_hPal(OLE_HANDLE hPal),int;
  declare virtual get_CurDC(/*out*/ HDC *phDC),int;
  declare virtual SelectPicture(HDC hDCIn,/*out*/HDC *phDCOut,/*out*/OLE_HANDLE *phBmpOut),int;
  declare virtual get_KeepOriginalFormat(/* [out] */ int *pKeep),int;
  declare virtual put_KeepOriginalFormat(int keep),int;
  declare virtual PictureChanged(),int;
  declare virtual SaveAsFile(IStream pStream,int fSaveMemCopy,/* [out] */ int *pCbSize),int;
  declare virtual get_Attributes(/*out*/DWORD *pDwAttr),int;
}

declare import, OleLoadPicturePath(
Pointer  *szURLorPath,
IUnknown *punkCaller,
DWORD    dwReserved,
int clrReserved,
REFIID   *riid,
void     *ppvRet
),int;

declare import, DeleteObject(int hObject),int;
extern int cdecl swprintf(...);
declare import, CoInitialize(opt void *pvReserved),int;
declare import, CoUninitialize();

CONST EM_PASTESPECIAL = 0x400 + 64;
import int SendMessage alias SendMessageA(int q,int w,int e,void *r);

declare import,OpenClipboard(opt int hWndNewOwner),int;
declare import,CloseClipboard(),int;
declare import,EmptyClipboard(),int;
declare import,SetClipboardData(UINT uFormat,opt int hMem),int;

extern _IID_IPicture as GUID;

////////////////////////////////////////////////////////////////////////////////
/* code by Sapero */
// Add Insert image object to richedit control
PopotteMain::InsertImage(string Path, CRichEdit *re1)
{
  int  hBitmap = 0;
  IPicture *pic;
  CoInitialize(0);

  pointer olepath = AllocHeap(len(Path)*2 +1);
  swprintf(olepath, "%\x00S\x00\x00", Path); // make unicode

  if S_OK=OleLoadPicturePath(olepath, 0, 0, 0, _IID_IPicture, &pic) {
    pic->get_Handle(&hBitmap);

    OpenClipboard(m_hwnd);
    EmptyClipboard();
    SetClipboardData(CF_BITMAP, hBitmap);
    CloseClipboard();

    SendMessage(re1->m_hwnd, EM_PASTESPECIAL, CF_BITMAP, null);
    DeleteObject(hBitmap);
    pic->Release();
  }
  else {
    messagebox(this,"Erreur \"OleLoadPicturePath\"","Popotte");
  }

  FreeHeap(olepath);
  CoUninitialize();
}

////////////////////////////////////////////////////////////////////////////////
PopotteMain::OuvrirFichier()
{
filename = FILEREQUEST("Ouvrir Un Fichier",this,1,"Tous les types |*.*||","");
if filename <> ""
{
   m_Red->LoadFile(filename,0);
   m_Red->SetFocus();
}
}



ExMember001

you must click on the Police button to get the program to crash
Police mean also Font in French ;)

Ionic Wind Support Team

I'll look and get back to you this evening.  Have to run to work for a few ;)

Ionic Wind Support Team

ExMember001


Ionic Wind Support Team

Tis a bug.  And I will fix soon.

FONTREQUEST is borken at the moment.
Ionic Wind Support Team

Bruce Peaslee

Quote from: Paul Turley on July 14, 2006, 03:33:28 PM
FONTREQUEST is borken at the moment.

I was borken myself once - really painful!
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

Bug found.  Actually has been there for some time.  Surprised no one noticed it until now ;)
Ionic Wind Support Team

ExMember001

Quote from: peaslee on July 14, 2006, 05:18:21 PM
Quote from: Paul Turley on July 14, 2006, 03:33:28 PM
FONTREQUEST is borken at the moment.

I was borken myself once - really painful!

lol :P

hey, i found a bug wooohoo!!!
I should not be smilling at the moment but ... :)
at least its a good time to find bug like that.
so ill put that on the side and ill attack the dialogs i have to add.