Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with MessageBoxIndirect API
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01070654
Message ID:
01070815
Vues:
23
Thank you for your reply and comments. What I did is use the rAPIdStructure class to convert from Struc to String and back, and it worked!

But... I only managed to use the Windows icons or the icons included in the VFP9 exe/runtime. Now we need to find a way to use icon files and assign them somehow to the MSGBOXPARAMS struc.

>Also lpszIcon should be a resource identifier. I don't think it can be an icon filename.

You are right about that! and the hInstance parameter tells the function where to look for the lpszIcon resource identifier, if its 0 it uses Windows standard icons.

If there was a way to load an icon file with an X lpszIcon resource identifier into a Y hInstance, we could pass those parameters to messageboxindirect and have a messagebox with custom icons, loaded from an "ico" file.

The other way I saw is to hook into the MessageBox creation, and change it "On the fly" adding a custom icon, etc. check:

...a more flexible MessageBox
http://www.gipsysoft.com/messagebox/

BindEvent on Steroids
http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,f7644db8-b155-4d43-8216-4cfde233edb7.aspx

That is something that is a liitle to much work I think. Maybe it would be easier just to recreate the messagebox function using a class with just Fox commands.

Thanks!

Carlos


Code that works: (Needs rAPIdStructure class of file rpstruct.prg in same directory as this prg, or in path, download from UT)
*	References:

*	MessageBoxIndirect Function
*	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/Windowing/DialogBoxes/DialogBoxReference/DialogBoxFunctions/MessageBoxIndirect.asp

*	MSGBOXPARAMS Structure
*	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxstructures/msgboxparams.asp

*	MessageBoxEx Function
*	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/dialogboxreference/dialogboxfunctions/messageboxex.asp

*	LoadIcon Function
*	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/icons/iconreference/iconfunctions/loadicon.asp

*	LoadImage Function
*	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/loadimage.asp

* Needs rAPIdStructure class of file rpstruct.prg in
* same directory as this prg, or in path, download from UT

#Define GWL_HINSTANCE	-6

#Define MB_ABORTRETRYIGNORE	0x2
#Define MB_CANCELTRYCONTINUE	0x6
#Define MB_HELP	0x4000
#Define MB_OK	0x0
#Define MB_OKCANCEL	0x1
#Define MB_RETRYCANCEL	0x5
#Define MB_YESNO	0x4
#Define MB_YESNOCANCEL	0x3

#Define MB_USERICON	0x80

#Define MB_ICONEXCLAMATION	0x30
#Define MB_ICONWARNING	MB_ICONEXCLAMATION
#Define MB_ICONASTERISK	0x40
#Define MB_ICONINFORMATION	MB_ICONASTERISK
#Define MB_ICONQUESTION	0x20
#Define MB_ICONHAND	0x10
#Define MB_ICONSTOP	MB_ICONHAND
#Define MB_ICONERROR	MB_ICONHAND

#Define IDI_APPLICATION	32512
#Define IDI_HAND		32513
#Define IDI_QUESTION	32514
#Define IDI_EXCLAMATION	32515
#Define IDI_ASTERISK	32516
#Define IDI_WINLOGO		32517

#Define IDI_ERROR	IDI_HAND
#Define IDI_INFORMATION	IDI_ASTERISK
#Define IDI_WARNING	IDI_EXCLAMATION

#Define MB_DEFBUTTON1	0x0
#Define MB_DEFBUTTON2	0x100
#Define MB_DEFBUTTON3	0x200
#Define MB_DEFBUTTON4	0x300

#Define MB_APPLMODAL	0x0
#Define MB_SYSTEMMODAL	0x1000
#Define MB_TASKMODAL	0x2000

#Define MB_RIGHT	0x80000
#Define MB_SETFOREGROUND	0x10000
#Define MB_TOPMOST	0x40000

#Define LANG_NEUTRAL	0x0

#Define IMAGE_ICON	1
#Define LR_LOADFROMFILE	0x10
#Define LR_DEFAULTSIZE	0x40

Clear

Declare Integer GetWindowLong In user32;
  INTEGER HWnd,;
  INTEGER nIndex

Declare Integer MessageBoxIndirect In user32;
  STRING @ lpMsgBoxParams

Declare Integer LoadImage In user32;
  INTEGER hinst,;
  STRING  lpszName,;
  INTEGER uType,;
  INTEGER cxDesired,;
  INTEGER cyDesired,;
  INTEGER fuLoad

Local cOldDefault

m.cOldDefault = Set("Default")

Set Default To Justpath(Sys(16))

Local cIconFile, lpszIcon, hInstance

m.hInstance = GetWindowLong(Application.HWnd,GWL_HINSTANCE)
*m.cIconFile = Getpict("ICO")
*m.lpszIcon = 105
*LoadImage(hInstance, cIconFile, IMAGE_ICON, 0, 0,Bitor(LR_LOADFROMFILE,LR_DEFAULTSIZE))

Local oMsgBoxParams, cMsgBoxParamsDef, clpMsgBoxParams

* Create Structure:
oMsgBoxParams = Newobject("rAPIdStructure","rpstruct.prg")

* Pass Structure definition to Structure Object:
TEXT to cMsgBoxParamsDef NOSHOW
Type MSGBOXPARAMS
 cbSize As Long
 hwndOwner As Long
 hInstance As Long
 lpszText As String
 lpszCaption As String
 dwStyle As Long
 lpszIcon As Long
 dwContextHelpId As Long
 lpfnMsgBoxCallback As Long
 dwLanguageId As Long
End Type
ENDTEXT

* Load Struc in Struc Object:
oMsgBoxParams.LoadVBDef(m.cMsgBoxParamsDef)


* Assign Values to Struct:
With oMsgBoxParams
  .hwndOwner = Application.HWnd		&& Application.HWnd or 0 for Desktop
  .hInstance = m.hInstance  && or 0 for normal icons
  .lpszText = "Text of the messagebox" + Chr(0)
  .lpszCaption = "Title of the messagebox" + Chr(0)
  .dwStyle = Bitor(MB_OKCANCEL, MB_USERICON, MB_TOPMOST,MB_SETFOREGROUND,MB_APPLMODAL)
  *.lpszIcon = m.lpszIcon
  .dwContextHelpId = 0
  .lpfnMsgBoxCallback = 0
  .dwLanguageId = LANG_NEUTRAL
Endwith

Local N

* Display Messagebox with VFP resource Icons:
For N = 101 To 110
  With oMsgBoxParams
    .lpszIcon = m.n
    .lpszText = "VFP Runtime Icon Resource # : " + Str(m.n)
    .cbSize = .CalculateBytes()

  Endwith

  * Assign Struc to String:
  clpMsgBoxParams = oMsgBoxParams.MakeStruct()

  ?MessageBoxIndirect(@clpMsgBoxParams)
Endfor


* Display Messagebox with Windows resource Icons:
oMsgBoxParams.hInstance  = 0

For N = 32512 To 32517
  With oMsgBoxParams
    .lpszIcon = m.n
    .lpszText = "Windows Icon Resource # : " + Str(m.n)
    .cbSize = .CalculateBytes()

  Endwith

  * Assign Struc to String:
  clpMsgBoxParams = oMsgBoxParams.MakeStruct()

  ?MessageBoxIndirect(@clpMsgBoxParams)
Endfor

Set Default To (m.cOldDefault)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform