⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windows api函数使用技巧i.htm

📁 对于学习很有帮助
💻 HTM
📖 第 1 页 / 共 2 页
字号:
    另一个component VersionInfo.zip<br>    </td>  </tr>  <tr>    <td><font color="0000FF"><a name="16">防止程序运行多个例程? </a></font></td>  </tr>  <tr>    <td>More than one instance of program?<br>    回答<br>    &nbsp;This is copied direct from my *.dpr file. You can work it for your own<br>    use.<br>    var<br>    &nbsp;&nbsp;hMutex : Thandle;<br>    &nbsp;&nbsp;WaitResult : word;<br>    &nbsp;&nbsp;BroadcastList : DWORD;<br>    begin<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageID := RegisterWindowMessage('Check For Choice     Previous Inst');<br>    // register a message to use later on<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hMutex := createMutex(nil,false,pchar('App_Choice')); //     grab a mutex<br>    handle<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WaitResult := WaitForSingleObject(hMutex,10); // wait to see<br>    if we can have exclusive use of the mutex<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( waitResult = WAIT_TIMEOUT ) then // if we can't then     broadcast<br>    the message to make the owner of the mutex respond<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ request that the running application takes focus }<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BroadcastList :=     BSM_APPLICATIONS;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BroadcastSystemMessage(<br>    BSF_POSTMESSAGE,@BroadcastList,MessageID,0,0); //32 bit - broadcast the<br>    message to all apps - only a prev inst will hear it.<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ do the normal stuff}<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.Title := 'Choice Organics Purchase &amp;     Sales System';<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.CreateForm(TMainForm, MainForm);<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Application.Run;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReleaseMutex(hMutex); // release the mutex as a     politeness<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CloseHandle(hMutex); // close the mutex handle<br>    end.<br>    This goes in the MainForm<br>    procedure Tmainform.OnAppMessage(var Msg : TMsg ; Var Handled : Boolean);<br>    begin<br>    { If it's the special message then focus on this window}<br>    if Msg.Message = MessageID then // if we get the broadcast message from an<br>    another instance of this app that is trying to start up<br>    &nbsp;&nbsp;&nbsp;begin<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;show;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WindowState := wsMaximized;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BringToFront;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetFocus;<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Handled := true;<br>    &nbsp;&nbsp;&nbsp;end;<br>    end;<br>    //And this goes in the TMainForm.FormCreate ;-<br>    Application.OnMessage:= OnAppMessage;<br>    </td>  </tr>  <tr>    <td><font color="0000FF"><a name="17">4.得到Win 95 的计算机名字? </a></font></td>  </tr>  <tr>    <td>问 How can I learn Windows'95 Machine Name?<br>    答function ComputerName : String;<br>    var<br>    &nbsp;&nbsp;&nbsp;CNameBuffer : PChar;<br>    &nbsp;&nbsp;fl_loaded : Boolean;<br>    &nbsp;&nbsp;CLen : ^DWord;<br>    begin<br>    &nbsp;&nbsp;&nbsp;&nbsp;GetMem(CNameBuffer,255);<br>    &nbsp;&nbsp;&nbsp;&nbsp;New(CLen);<br>    &nbsp;&nbsp;&nbsp;&nbsp;CLen^:= 255;<br>    &nbsp;&nbsp;&nbsp;&nbsp;fl_loaded := GetComputerName(CNameBuffer,CLen^);<br>    &nbsp;&nbsp;&nbsp;&nbsp;if fl_loaded then<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ComputerName := StrPas(CNameBuffer)<br>    &nbsp;&nbsp;&nbsp;&nbsp;else<br>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ComputerName := 'Unkown';<br>    &nbsp;&nbsp;&nbsp;&nbsp;FreeMem(CNameBuffer,255);<br>    &nbsp;&nbsp;&nbsp;&nbsp;Dispose(CLen);<br>    end;<br>    </td>  </tr>  <tr>    <td><font color="0000FF"><a name="18">7. 停止一个线程? </a></font></td>  </tr>  <tr>    <td>问 Stop A Thread?<br>    回答<br>    You can Terminate your thread in two ways:<br>    1) Assign ThreadDone to OnTerminate when you create it.<br>    &nbsp;&nbsp;&nbsp;In the Execute method, exit when the terminated property is True.<br>    &nbsp;&nbsp;&nbsp;At the point where you want to stop, issue the Terminate method.<br>    2) Just call the Suspend method.<br>    After one of these steps you may free the thread.<br>    I hope the following snippets will help.<br>    // -------------------------------------------------------------- //<br>    interface<br>    type<br>    &nbsp;&nbsp;Txyz = class(TThread)<br>    &nbsp;&nbsp;published<br>    &nbsp;&nbsp;&nbsp;&nbsp;procedure Execute; override;<br>    &nbsp;&nbsp;end;<br>    var<br>    &nbsp;&nbsp;XYZThread: Txyz;<br>    implementation<br>    procedure Txyz.Execute;<br>    begin<br>    &nbsp;&nbsp;while True do Application.ProcessMessages;<br>    end;<br>    procedure TForm1.Button1Click(Sender: TObject);<br>    begin<br>    &nbsp;&nbsp;XYZThread := Txyz.Create(False);<br>    end;<br>    procedure TForm1.Button2Click(Sender: TObject);<br>    begin<br>    &nbsp;&nbsp;XYZThread2.Suspend;<br>    &nbsp;&nbsp;XYZThread2.Free;<br>    end;<br>    end.<br>    </td>  </tr>  <tr>    <td><font color="0000FF"><a name="19">如何在WINDOWS中象在UCDOS下控制打印字体的长宽,而不受限于SIZE     的限制。</a></font></td>  </tr>  <tr>    <td>首先为了达到这个功能,可以采用Windows的逻辑字体(LogFont)<br>    可以使用 CreateFont 或 CreateFontIndirect 这两个Windows API<br>    函数来定义任何想要的字体,由于 CreateFont 所需的参数甚多通常<br>    我们使用 CreateFontIndirect 来建立所需的逻辑字体,这个API函数<br>    在Delphi中的声明为<br>    function CreateFontIndirect(const p1: TLogFont): HFONT; stdcall;<br>    其中只有一个参数 p1: TLogfont, 所有有关字体的参数完全通过这个<br>    TLogfont结构来传送,Windows将根据结构中的内容创建出相应的逻辑<br>    字体,在Delphi的Windows.pas中TLogFont是这样定义的<br>    TLogFontA = packed record<br>    lfHeight: Longint;<br>    lfWidth: Longint;<br>    lfEscapement: Longint;<br>    lfOrientation: Longint;<br>    lfWeight: Longint;<br>    lfItalic: Byte;<br>    lfUnderline: Byte;<br>    lfStrikeOut: Byte;<br>    lfCharSet: Byte;<br>    lfOutPrecision: Byte;<br>    lfClipPrecision: Byte;<br>    lfQuality: Byte;<br>    lfPitchAndFamily: Byte;<br>    lfFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;<br>    end;<br>    TLogFontW = packed record<br>    lfHeight: Longint;<br>    lfWidth: Longint;<br>    lfEscapement: Longint;<br>    lfOrientation: Longint;<br>    lfWeight: Longint;<br>    lfItalic: Byte;<br>    lfUnderline: Byte;<br>    lfStrikeOut: Byte;<br>    lfCharSet: Byte;<br>    lfOutPrecision: Byte;<br>    lfClipPrecision: Byte;<br>    lfQuality: Byte;<br>    lfPitchAndFamily: Byte;<br>    lfFaceName: array[0..LF_FACESIZE - 1] of WideChar;<br>    end;<br>    TLogFont = TLogFontA;<br>    其中涉及到很多参数,其中<br>    lfHeight: Longint;<br>    指定以逻辑单位标定的字体高度,取值可为正负或零,对于需要随意<br>    定义字体高度的情况下通常取负值,以保证获得实际尺寸的字体。<br>    lfWidth: Longint;<br>    用于指定字体的平均宽度,由于Windows系统下的大多数字体都是比例<br>    字体因而采用平均宽度这个表示方法。若指定为0,则系统会自动根据<br>    适当的比例自动处理宽度。<br>    lfEscapement: Longint;<br>    指定输出方向与当前坐标系X轴之间的以十分之一度为单位的角度。<br>    lfOrientation: Longint;<br>    指定每个字符与当前坐标系X轴之间的以十分之一度为单位的角度。在<br>    Windows95中这个值等同于lfEscpement。<br>    lfWeight: Longint;<br>    指定范围为从0至1000的字体加重程度,400是标准字体700为加重字体,<br>    0表示采用默认值。<br>    lfItalic: Byte;<br>    不为0表示采用斜体字。<br>    lfUnderline: Byte;<br>    不为0表示带下划线。<br>    lfStrikeOut: Byte;<br>    不为0表示带穿透线。<br>    lfCharSet: Byte;<br>    指定字体集。<br>    lfOutPrecision: Byte;<br>    指定输出精度。用于确定对前面一些设定值的精确程度。<br>    lfClipPrecision: Byte;<br>    指定裁剪精度。裁剪是Windows图形环境下的一种特殊处理,简单说就是<br>    去掉图形中落在视图以外的部分,有助于提高图形的处理速度。<br>    lfQuality: Byte;<br>    指定输出质量。<br>    lfPitchAndFamily: Byte;<br>    指定字体的Pitch和Family。<br>    lfFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;<br>    指定采用的字体名称。<br>    在建立逻辑字体时,我们通常使用<br>    lfHeight和lfWidth来确定字体的尺寸,使用lfEscapement和lfOrientation<br>    来确定字体的输出方向,使用lfWeight, lfItalic, lfUnderline,<br>    lfStrikeOut, 来确定字体的加重,斜体,下划线和穿透线,使用lfCharSet<br>    来确定字体的字符集,通常采用系统默认的字符集。<br>    对于lfOutPrecision, lfClipPrecision, lfQuality一般应用于对屏幕之外<br>    的输出设备,通常采用默认值。采用lfPitchAndFamily来确定采用定宽或可<br>    变字体和字体的家族。以lfFaceName来通过名称选择采用的字体。<br>    另外应当注意在Windows环境下,每种字体具体输出为何种形式取决于很多<br>    因素,需要对以上这些参数进行有效的组合才能达到所要的效果。<br>    </td>  </tr></table><p align="center"> </p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -