Exemplo de criação de uma aplicação simples usando apenas chamadas de api puras. Eu também crio um ToolTip que aparece em cima de dois botões que existem na janela. O Tooltip que aparece no botão nomeado "nada" tem o flag TTF_CENTERTIP e, no caso deste exemplo, este ToolTip aparece com um estilo antigo (bug da API?)

Format
Delphi
Post date
2022-03-28 09:33
Publication Period
Unlimited
  1. program Project4;
  2. {$R 'resourcesDialog.res' 'resourcesDialog.rc'}
  3. uses
  4. Windows, Messages, CommCtrl;
  5. const
  6. IDD_MAINDIALOG = 100;
  7. IDC_BUTTON1 = 10;
  8. IDC_BUTTON2 = 11;
  9. function WndProc(AHwnd: HWND; AMessage: UINT; AWParam: WPARAM; ALParam: LPARAM): LRESULT; stdcall;
  10. begin
  11. Result := 0;
  12. case AMessage of
  13. WM_INITDIALOG: begin
  14. var HwndToolTip: HWND := CreateWindowEx(WS_EX_NOACTIVATE or WS_EX_TOPMOST,TOOLTIPS_CLASS,nil,TTS_ALWAYSTIP or TTS_BALLOON, 0, 0, 0, 0, AHwnd, 0, HInstance, nil);
  15. if HwndToolTip <> 0 then
  16. begin
  17. SendMessage(HwndToolTip, TTM_SETTITLE, TTI_INFO, LPARAM(PChar('Title')));
  18. SendMessage(HwndToolTip, TTM_SETMAXTIPWIDTH, 0, 300);
  19. var TI: TToolInfo;
  20. ZeroMemory(@TI,SizeOf(TToolInfo));
  21. TI.cbSize := SizeOf(TToolInfo);
  22. TI.hwnd := AHwnd;
  23. TI.uId := GetDlgItem(AHwnd,IDC_BUTTON1);
  24. TI.lpszText := 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt dictum dui vel luctus. Duis ornare arcu a varius pharetra. Curabitur tempor sit amet dui id malesuada. Aliquam efficitur, massa consectetur tristique iaculis, dolor diam tincidunt.';
  25. TI.uFlags := TTF_IDISHWND or TTF_SUBCLASS;
  26. SendMessage(HwndToolTip, TTM_ADDTOOL, 0, LPARAM(@TI));
  27. TI.uId := GetDlgItem(AHwnd,IDC_BUTTON2);
  28. TI.lpszText := 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tincidunt dictum dui vel luctus. Duis ornare arcu a varius pharetra. Curabitur tempor sit amet dui id malesuada. Aliquam efficitur, massa consectetur tristique iaculis, dolor diam tincidunt.';
  29. ti.uFlags := TTF_IDISHWND or TTF_SUBCLASS or TTF_CENTERTIP;
  30. SendMessage(HwndToolTip, TTM_ADDTOOL, 0, LPARAM(@TI));
  31. end;
  32. end;
  33. WM_COMMAND: begin
  34. end;
  35. WM_DESTROY: begin
  36. PostQuitMessage(0);
  37. end;
  38. else
  39. Result := DefWindowProc(AHwnd,AMessage,AWParam,ALParam);
  40. end;
  41. end;
  42. // No pascal o WinMain é bloco begin..end do arquivo dpr
  43. begin
  44. var MainWnd: HWND := CreateDialog(HInstance, MakeIntResource(IDD_MAINDIALOG), 0,@WndProc);
  45. if MainWnd = 0 then
  46. Halt(MessageBox(0,'Não foi possível criar a janela!','Erro',MB_ICONERROR))
  47. else
  48. begin
  49. ShowWindow(MainWnd,SW_SHOWNORMAL);
  50. UpdateWindow(MainWnd);
  51. var Msg: TMsg;
  52. // Main Loop :)
  53. while GetMessage(Msg,0,0,0) do
  54. begin
  55. TranslateMessage(Msg);
  56. DispatchMessage(Msg);
  57. end;
  58. ExitCode := Msg.wParam;
  59. end;
  60. (*
  61. Adicionalmente, para que este exemplo compile e rode como deve, execute os
  62. passos a seguir
  63. 1. Crie um arquivo de nome resourcesDialog.rc com o conteúdo a seguir
  64. #define MANIFEST_RESOURCE_ID 1
  65. #define RT_MANIFEST 24
  66. #define IDD_MAINDIALOG 100
  67. #define IDC_BUTTON1 10
  68. #define IDC_BUTTON2 11
  69. MANIFEST_RESOURCE_ID RT_MANIFEST "manifest.xml"
  70. IDD_MAINDIALOG DIALOGEX 0, 0, 345, 177
  71. STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
  72. EXSTYLE WS_EX_APPWINDOW
  73. CAPTION "Win32TipTest"
  74. FONT 8, "MS Shell Dlg", 400, 0
  75. BEGIN
  76. PUSHBUTTON "Button1", IDC_BUTTON1, 69, 73, 50, 14
  77. PUSHBUTTON "Button2", IDC_BUTTON2, 188, 74, 50, 14
  78. PUSHBUTTON "Close", IDCLOSE, 288, 156, 50, 14
  79. END
  80. 2. Crie um arquivo de nome manifest.xml com o conteúdo a seguir
  81. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  82. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  83. <asmv3:application>
  84. <asmv3:windowsSettings>
  85. <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
  86. <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
  87. </asmv3:windowsSettings>
  88. </asmv3:application>
  89. <dependency>
  90. <dependentAssembly>
  91. <assemblyIdentity
  92. type="win32"
  93. name="Microsoft.Windows.Common-Controls"
  94. version="6.0.0.0"
  95. publicKeyToken="6595b64144ccf1df"
  96. language="*"
  97. processorArchitecture="*"/>
  98. </dependentAssembly>
  99. </dependency>
  100. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  101. <security>
  102. <requestedPrivileges>
  103. <requestedExecutionLevel
  104. level="asInvoker"
  105. uiAccess="false"
  106. />
  107. </requestedPrivileges>
  108. </security>
  109. </trustInfo>
  110. <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  111. <application>
  112. <!--The ID below indicates app support for Windows Vista -->
  113. <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
  114. <!--The ID below indicates app support for Windows 7 -->
  115. <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
  116. <!--The ID below indicates app support for Windows 8 -->
  117. <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
  118. <!--The ID below indicates app support for Windows 8.1 -->
  119. <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
  120. <!--The ID below indicates app support for Windows 10 -->
  121. <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
  122. </application>
  123. </compatibility>
  124. </assembly>
  125. 3. Coloque os dois arquivos criados na mesma pasta onde se encontra este arquivo
  126. .dpr
  127. *)
  128. end.
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text