WebGadget et Interfaces...

Programmation d'applications complexes
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

WebGadget et Interfaces...

Message par Chris »

Cette commande permet de changer la couleur du texte sélectionné dans un WebGadget en mode "Edition".
Le problème, c'est que je n'arrive pas à passer le paramètre concernant la couleur.

Code : Tout sélectionner

CmdTarget\Exec(?CGID_MSHTML, #IDM_FORECOLOR,#OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
Voilà ce que dit la doc à propos de la commande IOleCommandTarget::Exec :
HRESULT Exec(
const GUID *pguidCmdGroup, // Pointer to command group
DWORD nCmdID, // Identifier of command to execute
DWORD nCmdExecOpt, // Options for executing the command
VARIANTARG *pvaIn, // Pointer to input arguments
VARIANTARG *pvaOut // Pointer to command output
);

Parameters
pguidCmdGroup
[unique][in] Pointer to unique identifier of the command group; can be NULL to specify the standard group.
nCmdID
[in] The command to be executed. This command must belong to the group specified with pguidCmdGroup.
nCmdExecOpt
[in] Values taken from the OLECMDEXECOPT enumeration, which describe how the object should execute the command.
pvaIn
[unique][in] Pointer to a VARIANTARG structure containing input arguments. Can be NULL.
pvaOut
[unique][in,out] Pointer to a VARIANTARG structure to receive command output. Can be NULL.
Return Values
This method supports the standard return values E_FAIL and E_UNEXPECTED, as well as the following:

S_OK
The command was executed successfully.
OLECMDERR_E_UNKNOWNGROUP
The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.
OLECMDERR_E_NOTSUPPORTED
The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.
OLECMDERR_E_DISABLED
The command identified by nCmdID is currently disabled and cannot be executed.
OLECMDERR_E_NOHELP
The caller has asked for help on the command identified by nCmdID, but no help is available.
OLECMDERR_E_CANCELED
The user canceled the execution of the command.
Remarks
The list of input and output arguments of a command and how they are packaged is unique to each command. Such information should be documented with the specification of the command group. (See the description of OLECMDID_ZOOM in the OLECMDID enumeration.) In the absence of any specific information the command is assumed to take no arguments and have no return value.

Notes to Callers
The pguidCmdGroup and nCmdID parameters together uniquely identify the command to invoke. The nCmdExecOpt parameter specifies the exact action to be taken. (See the OLECMDEXECOPT enumeration for more details.)

Most commands neither take arguments nor return values. For such commands, the caller can pass NULL in pvaIn and pvaOut. For commands that expect one or more input values, the caller can declare and initialize a VARIANTARG variable and pass a pointer to that variable in pvaIn. If the input to the command is a single value, the argument can be stored directly in the VARIANTARG structure and passed to the function. If the command expects multiple arguments, those arguments must be packaged appropriately within the VARIANTARG, using one of the supported types (such as IDispatch or SAFEARRAY).

If a command returns one or more arguments, the caller is expected to declare a VARIANTARG, initialize it to VT_EMPTY, and pass its address in pvaOut. If the command returns a single value, then the object can store that value directly in pvaOut. If the command has multiple output values, then it will package those in some way appropriate for the VARIANTARG.

Because pvaIn and pvOut are both caller-allocated, stack variables are permitted for both the caller and the object receiving the call. For commands that take zero or one argument on input and return zero or one value, no additional memory allocation is necessary. Most of the types supported by VARIANTARG do not require memory allocation. Exceptions include SAFEARRAY and BSTR.
Et la doc dit ça à propos de #IDM_FORECOLOR
Command group CGID_MSHTML (defined in mshtmhst.h)
Symbolic constant IDM_FORECOLOR
User interface None. Set nCmdExecOpt to OLECMDEXECOPT_DONTPROMPTUSER.
IOleCommandTarget::Exec parameters pvaIn VARIANT of type VT_BSTR or VT_I4 that specifies the new color. If pvaIn is a VT_BSTR, the value can be a color name or a string representing a six-digit hexadecimal RGB color value, with or without a leading hash mark, as defined in the Color Table. If pvaIn is a VT_I4, the value will be in interpreted as a COLORREF.
pvaOut VARIANT of type VT_I4 that receives a COLORREF value. If the current selection uses more than one foreground color, pvaOut will return a VARIANT of type VT_NULL. Set pvaIn to NULL to retrieve information to pvaOut.

Header file mshtmcid.h
Applies to IHTMLDocument2::execCommand, IHTMLDocument2::queryCommandEnabled, IHTMLDocument2::queryCommandIndeterm, IHTMLDocument2::queryCommandState, IHTMLDocument2::queryCommandSupported, IHTMLDocument2::queryCommandValue, IOleCommandTarget::Exec, IOleCommandTarget::QueryStatus.
Alors si quelqu'un a une idée, parce que moi, je sèche! :(
Ca marche bien pour passer le texte en gras, en italique, en souligné, parce qu'il n'y a pas de paramètre à passer dans les deux dernières valeurs de la fonction, mais pour les couleurs... Nada!
KarLKoX
Messages : 1191
Inscription : jeu. 26/févr./2004 15:36
Localisation : France
Contact :

Message par KarLKoX »

En utilisant le pseudo type p-variant, ça devrait fonctionner ;)
"Qui baise trop bouffe un poil." P. Desproges
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

KarLKoX a écrit :En utilisant le pseudo type p-variant, ça devrait fonctionner ;)
Et ça marche comment, c't'affaire ?? :lol: :oops:
KarLKoX
Messages : 1191
Inscription : jeu. 26/févr./2004 15:36
Localisation : France
Contact :

Message par KarLKoX »

J'ai trouvé ça (cf la réponse de Fred) : je ne sais pas à quoi sert le membre vt (à définir le type ?), tu dois surement donner la couleur rgb (00FFFFFF), quelque chose dans le genre.
"Qui baise trop bouffe un poil." P. Desproges
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

KarLKoX a écrit :J'ai trouvé ça (cf la réponse de Fred) : je ne sais pas à quoi sert le membre vt (à définir le type ?), tu dois surement donner la couleur rgb (00FFFFFF), quelque chose dans le genre.
Je l'avais trouvé, ça. Mais j'ai pas compris non plus comment ça fonctionne.

J'ai essayé de passer la couleur à v\vt, à v\lVal, mais rien!

Ou alors j'ai rien compris au truc :oops:
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Ca y est! Ca fonctionne. :)

Par contre, j'ai toujours pas trop compris l'utilité de la variable Vt, mais en la mettant à 3, ça fonctionne.

Si Fred ou quelqu'un qui connaît bien le sujet passe par là...

Je suis en train d'essayer de faire un petit éditeur wysiwyg pour créer des messages pour les forums.

On tape le texte comme dans un traitement de texte, avec les couleurs, la taille des caractères, les attributs, et on récupère le texte formaté en BBCode pour le coller dans la fenêtre d'édition du forum. :roll:

On verra si ça marche
KarLKoX
Messages : 1191
Inscription : jeu. 26/févr./2004 15:36
Localisation : France
Contact :

Message par KarLKoX »

D'apres ceci, selon le vt (et donc le type, bon feeling sur ce coup :-p), il faut passer la valeur sur le membre adéquate.
Exemple pour un VT_I4 (pour ton cas) : lVal.
v\vt = #VT_I4
v\lVal = $00FFFFFF ; ABGR
"Qui baise trop bouffe un poil." P. Desproges
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

D'accord!

En fait, la variable Vt donne le type de traitement qu'on recherche.
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Ben du coup, j'utilise #VT_BSTR comme paramètre Vt Ca me permet d'utiliser directement les noms des couleurs, comme dans les forums.

Par contre, pour que ça marche, il faut que je compile le programme en Unicode. C'est normal, ça?

Voilà ce que donne le code. (Je me sers d'un combo pour les couleurs)

Code : Tout sélectionner

Case #Cmb_Color
  If EventType() = #PB_EventType_RightClick
    SelectElement(Color(), GetGadgetState(#Cmb_Color))
    Cl_bstr = SysAllocString_(Color())
  EndIf
            
  Cl.VARIANT
  Cl\vt = #VT_BSTR
  Cl\bstrVal = Cl_bstr
  CmdTarget\Exec(?CGID_MSHTML, #IDM_FORECOLOR,#OLECMDEXECOPT_DONTPROMPTUSER, @Cl, 0)
  SysFreeString_(Cl_bstr)
Répondre