PDA

View Full Version : [Dev-C++] SetWindowLong e WindowProcedure


DanieleC88
02-01-2004, 21:59
Sto cercando in tutti i modi di impostare una WindowProcedure personalizzata per un RichEdit, ma purtroppo SetWindowLong ha bisogno di un valore long, invece la WindowProcedure che sto cercando di impostare mi restituisce LRESULT, e sembra che MinGW non passi automaticamente l'indirizzo alla funzione.

Sto usando:
RichWndProc = (WNDPROC) SetWindowLong (hWnd, GWL_WNDPROC, EditWndProc);

e MinGW mi restituisce:
dllmain.cpp:47: cannot resolve overloaded function `EditWndProc' based on conversion to type `long int'.

Come posso fare ?

cionci
02-01-2004, 23:29
Fai un cast a LONG !!!

RichWndProc = (WNDPROC) SetWindowLong (hWnd, GWL_WNDPROC, (LONG)EditWndProc);

DanieleC88
03-01-2004, 20:05
E secondo te non ci ho provato :cry: ?
Mi sembra che MinGW provi a farlo da solo, ma mi dà lo stesso risultato. Anzi mi pare che mi risponda "aggregated value when long expected" o qualcosa di simile.

:cry: :cry: :cry: :cry: :cry:

cionci
03-01-2004, 20:28
Non è che mi dai un esempio corto che ripresenta il problema ?

DanieleC88
04-01-2004, 18:52
In questo momento non posso. Windows e i suoi crash... in pratica ho solo una finestra di Mozilla e il desktop vuoto...
Appena posso ti mando il codice incriminato...

DanieleC88
04-01-2004, 23:31
Allora...

In dllmain.cpp:


#include <richedit.h>
#include <windows.h>

#include "codeedit.h"

const char *richedit20 = "riched20.dll";
const char *richedit32 = "riched32.dll";

HINSTANCE hInstance;
HINSTANCE hRichInst;
HWND hWnd;

CodeEdit::CodeEdit ()
{
}
CodeEdit::~CodeEdit ()
{
}

int
CodeEdit::Create (HWND hwOwner)
{
int ownWidth, ownHeight;
RECT ownClientRect;

GetClientRect (hwOwner, &ownClientRect);
ownWidth = ownClientRect.right;
ownHeight = ownClientRect.bottom;

hRichInst = LoadLibrary (richedit20);
if (!hRichInst) hRichInst = LoadLibrary (richedit32);
if (!hRichInst) return ERR_NORICHEDIT;
hWnd = CreateWindow (RICHEDIT_CLASS, NULLSTR, EditWndStyle, 0, 0, ownWidth,
ownHeight, hwOwner, (HMENU) IDCODEEDIT, hInstance, NULL);
if (!hWnd) return ERR_NOCONTROL;

RichWndProc = (WNDPROC) SetWindowLong (hWnd, GWL_WNDPROC, (LONG) EditWndProc);
SendMessage (hWnd, EM_SETOPTIONS, (WPARAM) ECOOP_OR, (LPARAM) ECO_AUTOWORDSELECTION);
SendMessage (hWnd, EM_SETBKGNDCOLOR, (WPARAM) FALSE, (LPARAM) COLOR_WHITE);
return ERR_NOERROR;
}

void
CodeEdit:: Destroy () //Incredibile, senza spazio, HardwareUpgrade me lo converte in uno smiley!
{
DestroyWindow (hWnd);
FreeLibraryAndExitThread (hRichInst, 0);
}

LPSTR
CodeEdit::GetText ()
{
LPSTR result;

GetWindowText (hWnd, result, GetWindowTextLength (hWnd));
return result;
}

void
CodeEdit::SetText (LPSTR text)
{
SetWindowText (hWnd, text);
}

void
CodeEdit::SetFont (LPSTR fName, int fSize)
{
HFONT hNewFont;

hNewFont = GetFont (fName, fSize);
SendMessage (hWnd, WM_SETFONT, (WPARAM) hNewFont, MAKELPARAM (TRUE, 0));
DeleteObject (hNewFont);
}

LRESULT CALLBACK
CodeEdit::EditWndProc (HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar)
{
switch (msg) {
case WM_KEYDOWN:
int *key, *data;

key = (int*)wpar;
data = (int*)lpar;
OnKeyDown (key);
break;
default:
LRESULT RichResult;

RichResult = RichWndProc (hwnd, msg, wpar, lpar);
return RichResult;
//return DefWindowProc (hwnd, msg, wpar, lpar);
}
return 0;
}

void
CodeEdit::SetKeyDownEvent (LPKEYDOWN EventKeyDown)
{
OnKeyDown = *EventKeyDown;
}

BOOL APIENTRY
DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
hInstance = hInst;
break;
case DLL_PROCESS_DETACH:
break;

case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}

return TRUE;
}


In CodeEdit.h:


#ifndef _CODEEDIT_H_
#define _CODEEDIT_H_

#if BUILDING_DLL
#define dllspec __declspec (dllexport)
#else /* Not BUILDING_DLL */
#define dllspec __declspec (dllimport)
#endif /* Not BUILDING_DLL */

#include <windows.h>

//----------------------------------------------------------------------------//
#define IDCODEEDIT 0x00CDED
//----------------------------------------------------------------------------//
#define ERR_BASE 0x0CACCA
#define ERR_NOERROR 0x000000
#define ERR_NORICHEDIT ERR_BASE + 0x01
#define ERR_NOCONTROL ERR_BASE + 0x02
//----------------------------------------------------------------------------//
#define NULLSTR ""
//----------------------------------------------------------------------------//
#define COLOR_BLACK 0x000000
#define COLOR_WHITE 0xFFFFFF
//----------------------------------------------------------------------------//



//----------------------------------------------------------------------------//
typedef void (FAR *KEYDOWN)(int*); typedef KEYDOWN *LPKEYDOWN;
//----------------------------------------------------------------------------//

class dllspec CodeEdit
{
public:
// constructor / destructor procedures
CodeEdit ();
virtual ~CodeEdit (void);

// initialization / termination procedures
int Create (HWND hwOwner);
void Destroy ();

// event handlers
KEYDOWN OnKeyDown;
void SetKeyDownEvent (LPKEYDOWN EventKeyDown);

// standard functions and procedures
void SetFont (LPSTR fName, int fSize);
void SetText (LPSTR newtext);
LPSTR GetText ();

private:
const static int EditWndStyle = WS_VISIBLE | WS_CHILD | WS_VSCROLL |
WS_HSCROLL | ES_MULTILINE | ES_NOHIDESEL |
ES_WANTRETURN | DS_CONTEXTHELP;

// Window procedures
WNDPROC RichWndProc;
LRESULT CALLBACK EditWndProc (HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar);
};

#endif /* _CODEEDIT_H_ */


E che nessuno mi rubi questo codice!

DanieleC88
06-01-2004, 19:43
up