Results 1 to 5 of 5

Thread: Hooks-sometimes hard to use them

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Slovakia
    Posts
    5

    Hooks-sometimes hard to use them

    Hi for all.
    i have a problem with using hook procedure in Choosefont Api funct.
    Can me help somebody?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Please be more specific. If you need info on how to use the ChooseFont API then:
    VB Code:
    1. ' This code is licensed according to the terms and conditions listed here.
    2.  
    3. ' Display a Choose Font dialog box.  Print out the typeface name, point size,
    4. ' and style of the selected font.  More detail about topics in this example can be found in
    5. ' the pages for CHOOSEFONT_TYPE and LOGFONT.
    6. Dim cf As CHOOSEFONT_TYPE  ' data structure needed for function
    7. Dim lfont As LOGFONT  ' receives information about the chosen font
    8. Dim hMem As Long, pMem As Long  ' handle and pointer to memory buffer
    9. Dim fontname As String  ' receives name of font selected
    10. Dim retval As Long  ' return value
    11.  
    12. ' Initialize the default selected font: Times New Roman, regular, black, 12 point.
    13. ' (Note that some of that information is in the CHOOSEFONT_TYPE structure instead.)
    14. lfont.lfHeight = 0  ' determine default height
    15. lfont.lfWidth = 0  ' determine default width
    16. lfont.lfEscapement = 0  ' angle between baseline and escapement vector
    17. lfont.lfOrientation = 0  ' angle between baseline and orientation vector
    18. lfont.lfWeight = FW_NORMAL  ' normal weight i.e. not bold
    19. lfont.lfItalic = 0  ' not italic
    20. lfont.lfUnderline = 0  ' not underline
    21. lfont.lfStrikeOut = 0  ' not strikeout
    22. lfont.lfCharSet = DEFAULT_CHARSET  ' use default character set
    23. lfont.lfOutPrecision = OUT_DEFAULT_PRECIS  ' default precision mapping
    24. lfont.lfClipPrecision = CLIP_DEFAULT_PRECIS  ' default clipping precision
    25. lfont.lfQuality = DEFAULT_QUALITY  ' default quality setting
    26. lfont.lfPitchAndFamily = DEFAULT_PITCH Or FF_ROMAN  ' default pitch, proportional with serifs
    27. lfont.lfFaceName = "Times New Roman" & vbNullChar  ' string must be null-terminated
    28.  
    29. ' Create the memory block which will act as the LOGFONT structure buffer.
    30. hMem = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(lfont))
    31. pMem = GlobalLock(hMem)  ' lock and get pointer
    32. CopyMemory ByVal pMem, lfont, Len(lfont)  ' copy structure's contents into block
    33.  
    34. ' Initialize dialog box: Screen and printer fonts, point size between 10 and 72.
    35. cf.lStructSize = Len(cf)  ' size of structure
    36. cf.hwndOwner = Form1.hWnd  ' window Form1 is opening this dialog box
    37. cf.hdc = Printer.hDC  ' device context of default printer (using VB's mechanism)
    38. cf.lfLogFont = pMem  ' pointer to LOGFONT memory block buffer
    39. cf.iPointSize = 120  ' 12 point font (in units of 1/10 point)
    40. cf.flags = CF_BOTH Or CF_EFFECTS Or CF_FORCEFONTEXIST Or CF_INITTOLOGFONTSTRUCT Or CF_LIMITSIZE
    41. cf.rgbColors = RGB(0, 0, 0)  ' black
    42. cf.lCustData = 0  ' we don't use this here...
    43. cf.lpfnHook = 0  ' ...or this...
    44. cf.lpTemplateName = ""  ' ...or this...
    45. cf.hInstance = 0  ' ...or this...
    46. cf.lpszStyle = ""  ' ...or this
    47. cf.nFontType = REGULAR_FONTTYPE  ' regular font type i.e. not bold or anything
    48. cf.nSizeMin = 10  ' minimum point size
    49. cf.nSizeMax = 72  ' maximum point size
    50.  
    51. ' Now, call the function.  If successful, copy the LOGFONT structure back into the structure
    52. ' and then print out the attributes we mentioned earlier that the user selected.
    53. retval = ChooseFont(cf)  ' open the dialog box
    54. If retval <> 0 Then  ' success
    55.   CopyMemory lfont, ByVal pMem, Len(lfont)  ' copy memory back
    56.   ' Now make the fixed-length string holding the font name into a "normal" string.
    57.   fontname = Left(lfont.lfFaceName, InStr(lfont.lfFaceName, vbNullChar) - 1)
    58.   ' Display font name and a few attributes.
    59.   Debug.Print "FONT NAME: "; fontname
    60.   Debug.Print "FONT SIZE (points):"; cf.iPointSize / 10  ' in units of 1/10 point!
    61.   Debug.Print "FONT STYLE(S): ";
    62.   If lfont.lfWeight >= FW_BOLD Then Debug.Print "Bold ";
    63.   If lfont.lfItalic <> 0 Then Debug.Print "Italic ";
    64.   If lfont.lfUnderline <> 0 Then Debug.Print "Underline ";
    65.   If lfont.lfStrikeOut <> 0 Then Debug.Print "Strikeout";
    66.   Debug.Print  ' end the line
    67. End If
    68.  
    69. ' Deallocate the memory block we created earlier.  Note that this must
    70. ' be done whether the function succeeded or not.
    71. retval = GlobalUnlock(hMem)  ' destroy pointer, unlock block
    72. retval = GlobalFree(hMem)  ' free the allocated memory
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Slovakia
    Posts
    5
    I have problems with 2 lines of your code))

    cf.lCustData = 0 ' we don't use this here...
    cf.lpfnHook = 0 ' ...or this...
    I need to execute funct. a as hook procedure

    Public Function a(ByVal hdlg As Long, ByVal uiMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    MsgBox "This is hook Procedure
    End Function

    How to do it??Ok

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Slovakia
    Posts
    5
    My exact problem is :

    I have a collection of fonts,
    1. Arial,bold,underline
    2.Ms Sans serif, italic
    ........etc.

    I need to modify these fonts:
    for example:
    if user sets in commondialog bold=true, then set the bold to true in all fonts, and not modify other prop's.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Location
    Slovakia
    Posts
    5
    the bold property has 3 states:
    1.all fonts have bold= true
    2.all fonts have bold= false
    3. some fonts have true and some false.

    and commondialog has only 2 states bold= true or false.this is, why i need to capture users click in bold or other property in listbox.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width