유돌이

calendar

1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

Notice

2019. 9. 23. 10:50 델파이

VK_LBUTTON = $1, //Dec 1; The left mouse button
VK_RBUTTON = $2, //Dec 2; The right mouse button
VK_CANCEL = $3, //Dec 3; The Cancel virtual key, used for control-break processing
VK_MBUTTON = $4, //Dec 4; The middle mouse button
VK_BACK = $8, //Dec 8; Backspace
VK_TAB = $9, //Dec 9; Tab
VK_CLEAR = $C, //Dec 12; 5 (keypad without Num Lock)
VK_RETURN = $D, //Dec 13; Enter
VK_SHIFT = $10, //Dec 16; Shift (either one)
VK_CONTROL = $11, //Dec 17; Ctrl (either one)
VK_MENU = $12, //Dec 18; Alt (either one)
VK_PAUSE = $13, //Dec 19; Pause Break
VK_CAPITAL = $14, //Dec 20; Caps Lock
VK_ESCAPE = $1B, //Dec 27; Esc
VK_SPACE = $20, //Dec 32; Spacebar
VK_PRIOR = $21, //Dec 33; Page Up
VK_NEXT = $22, //Dec 34; Page Down
VK_END = $23, //Dec 35; End
VK_HOME = $24, //Dec 36; Home
VK_LEFT = $25, //Dec 37; Left Arrow
VK_UP = $26, //Dec 38; Up Arrow
VK_RIGHT = $27, //Dec 39; Right Arrow
VK_DOWN = $28, //Dec 40; Down Arrow
VK_SELECT = $29, //Dec 41; Select
VK_PRINT = $2A, //Dec 42; Print (only used by Nokia keyboards)
VK_EXECUTE = $2B, //Dec 43; Execute (not used)
VK_SNAPSHOT = $2C, //Dec 44; Print Screen
VK_INSERT = $2D, //Dec 45; Insert
VK_DELETE = $2E, //Dec 46; Delete
VK_HELP = $2F, //Dec 47; Help
VK_0 = $30, //Dec 48; 0
VK_1 = $31, //Dec 49; 1
VK_2 = $32, //Dec 50; 2
VK_3 = $33, //Dec 51; 3
VK_4 = $34, //Dec 52; 4
VK_5 = $35, //Dec 53; 5
VK_6 = $36, //Dec 54; 6
VK_7 = $37, //Dec 55; 7
VK_8 = $38, //Dec 56; 8
VK_9 = $39, //Dec 57; 9
VK_A = $41, //Dec 65; A
VK_B = $42, //Dec 66; B
VK_C = $43, //Dec 67; C
VK_D = $44, //Dec 68; D
VK_E = $45, //Dec 69; E
VK_F = $46, //Dec 70; F
VK_G = $47, //Dec 71; G
VK_H = $48, //Dec 72; H
VK_I = $49, //Dec 73; I
VK_J = $4A, //Dec 74; J
VK_K = $4B, //Dec 75; K
VK_L = $4C, //Dec 76; L
VK_M = $4D, //Dec 77; M
VK_N = $4E, //Dec 78; N
VK_O = $4F, //Dec 79; O
VK_P = $50, //Dec 80; P
VK_Q = $51, //Dec 81; Q
VK_R = $52, //Dec 82; R
VK_S = $53, //Dec 83; S
VK_T = $54, //Dec 84; T
VK_U = $55, //Dec 85; U
VK_V = $56, //Dec 86; V
VK_W = $57, //Dec 87; W
VK_X = $58, //Dec 88; X
VK_Y = $59, //Dec 89; Y
VK_Z = $5A, //Dec 90; Z
VK_STARTKEY = $5B, //Dec 91; Start Menu key
VK_CONTEXTKEY = $5D, //Dec 93; Context Menu key
VK_NUMPAD0 = $60, //Dec 96; 0 (keypad with Num Lock)
VK_NUMPAD1 = $61, //Dec 97; 1 (keypad with Num Lock)
VK_NUMPAD2 = $62, //Dec 98; 2 (keypad with Num Lock)
VK_NUMPAD3 = $63, //Dec 99; 3 (keypad with Num Lock)
VK_NUMPAD4 = $64, //Dec 100; 4 (keypad with Num Lock)
VK_NUMPAD5 = $65, //Dec 101; 5 (keypad with Num Lock)
VK_NUMPAD6 = $66, //Dec 102; 6 (keypad with Num Lock)
VK_NUMPAD7 = $67, //Dec 103; 7 (keypad with Num Lock)
VK_NUMPAD8 = $68, //Dec 104; 8 (keypad with Num Lock)
VK_NUMPAD9 = $69, //Dec 105; 9 (keypad with Num Lock)
VK_MULTIPLY = $6A, //Dec 106; * (keypad)
VK_ADD = $6B, //Dec 107; + (keypad)
VK_SEPARATOR = $6C, //Dec 108; Separator (never generated by the keyboard)
VK_SUBTRACT = $6D, //Dec 109; - (keypad)
VK_DECIMAL = $6E, //Dec 110; . (keypad with Num Lock)
VK_DIVIDE = $6F, //Dec 111; / (keypad)
VK_F1 = $70, //Dec 112; F1
VK_F2 = $71, //Dec 113; F2
VK_F3 = $72, //Dec 114; F3
VK_F4 = $73, //Dec 115; F4
VK_F5 = $74, //Dec 116; F5
VK_F6 = $75, //Dec 117; F6
VK_F7 = $76, //Dec 118; F7
VK_F8 = $77, //Dec 119; F8
VK_F9 = $78, //Dec 120; F9
VK_F10 = $79, //Dec 121; F10
VK_F11 = $7A, //Dec 122; F11
VK_F12 = $7B, //Dec 123; F12
VK_F13 = $7C, //Dec 124; F13
VK_F14 = $7D, //Dec 125; F14
VK_F15 = $7E, //Dec 126; F15
VK_F16 = $7F, //Dec 127; F16
VK_F17 = $80, //Dec 128; F17
VK_F18 = $81, //Dec 129; F18
VK_F19 = $82, //Dec 130; F19
VK_F20 = $83, //Dec 131; F20
VK_F21 = $84, //Dec 132; F21
VK_F22 = $85, //Dec 133; F22
VK_F23 = $86, //Dec 134; F23
VK_F24 = $87, //Dec 135; F24
VK_NUMLOCK = $90, //Dec 144; Num Lock
VK_OEM_SCROLL = $91, //Dec 145; Scroll Lock
VK_OEM_1 = $BA, //Dec 186; ;
VK_OEM_PLUS = $BB, //Dec 187; =
VK_OEM_COMMA = $BC, //Dec 188;,
VK_OEM_MINUS = $BD, //Dec 189; -
VK_OEM_PERIOD = $BE, //Dec 190; .
VK_OEM_2 = $BF, //Dec 191; /
VK_OEM_3 = $C0, //Dec 192; `
VK_OEM_4 = $DB, //Dec 219; [
VK_OEM_5 = $DC, //Dec 220; \
VK_OEM_6 = $DD, //Dec 221; ]
VK_OEM_7 = $DE, //Dec 222; '
VK_OEM_8 = $DF, //Dec 223; (unknown)
VK_ICO_F17 = $E0, //Dec 224; F17 on Olivetti extended keyboard (internal use only)
VK_ICO_F18 = $E1, //Dec 225; F18 on Olivetti extended keyboard (internal use only)
VK_OEM_102 = $E2, //Dec 226; < or | on IBM-compatible 102 enhanced non-U.S. keyboard
VK_ICO_HELP = $E3, //Dec 227; Help on Olivetti extended keyboard (internal use only)
VK_ICO_00 = $E4, //Dec 228; 00 on Olivetti extended keyboard (internal use only)
VK_ICO_CLEAR = $E6, //Dec 230; Clear on Olivette extended keyboard (internal use only)
VK_OEM_RESET = $E9, //Dec 233; Reset (Nokia keyboards only)
VK_OEM_JUMP = $EA, //Dec 234; Jump (Nokia keyboards only)
VK_OEM_PA1 = $EB, //Dec 235; PA1 (Nokia keyboards only)
VK_OEM_PA2 = $EC, //Dec 236; PA2 (Nokia keyboards only)
VK_OEM_PA3 = $ED, //Dec 237; PA3 (Nokia keyboards only)
VK_OEM_WSCTRL = $EE, //Dec 238; WSCTRL (Nokia keyboards only)
VK_OEM_CUSEL = $EF, //Dec 239; CUSEL (Nokia keyboards only)
VK_OEM_ATTN = $F0, //Dec 240; ATTN (Nokia keyboards only)
VK_OEM_FINNISH = $F1, //Dec 241; FINNISH (Nokia keyboards only)
VK_OEM_COPY = $F2, //Dec 242; COPY (Nokia keyboards only)
VK_OEM_AUTO = $F3, //Dec 243; AUTO (Nokia keyboards only)
VK_OEM_ENLW = $F4, //Dec 244; ENLW (Nokia keyboards only)
VK_OEM_BACKTAB = $F5, //Dec 245; BACKTAB (Nokia keyboards only)
VK_ATTN = $F6, //Dec 246; ATTN
VK_CRSEL = $F7, //Dec 247; CRSEL
VK_EXSEL = $F8, //Dec 248; EXSEL
VK_EREOF = $F9, //Dec 249; EREOF
VK_PLAY = $FA, //Dec 250; PLAY
VK_ZOOM = $FB, //Dec 251; ZOOM
VK_NONAME = $FC, //Dec 252; NONAME
VK_PA1 = $FD, //Dec 253; PA1
VK_OEM_CLEAR = $FE //Dec 254; CLEAR

posted by 유돌이
2019. 9. 23. 10:50 델파이

procedure TFPAT070M.CaptureForm; 
var 
    Pt  :TPoint;     // 캡쳐할 화면의 Left, Top 좌표 
    DC  :HDC; 
    Bmp :TBitmap; 
begin 
 
  // 폼전체를 하기 위해 (0, 0) 으로 설정하였다. 
  Pt.x := 0;   // x => 폼에서의 Left 값 
  Pt.y := 0;   // y => 폼에서의 Top  값 
 
  // 폼의 좌표를 스크린 좌표로 변환한다. 
  Pt := ClientToScreen(Pt);                    
 
  // 캡쳐할 비트맵 생성 
  Bmp := TBitMap.Create; 
 
  try 
     // 비트맵 크기 지정 => 폼전체를 하기위해 폼의 크기를 지정하였다. 
     Bmp.Width  := Width; 
     Bmp.Height := Height; 
     DC := GetDC(0); 
     BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, DC, Pt.x , Pt.y, SRCCOPY); 
     ReleaseDC(0,DC); 
 
     Bmp.SaveToFile(Name + '.bmp')    // 비트맵 파일로 저장 
     // Clipboard.Assign(Bmp);        // 클립보드로 복사 
  finally 
     Bmp.Free; 
  end; 
 
end; 

'델파이' 카테고리의 다른 글

E1026 File not found: Controls.res  (0) 2019.09.24
Virtual Key Codes  (0) 2019.09.23
델파이 기초 - WebBrowser 기능 정리  (0) 2011.09.22
TWebBrowser에 직접 HTML 소스코드 넣기  (0) 2011.07.05
Creating and Using DLLs from Delphi  (0) 2011.07.05
posted by 유돌이
2011. 9. 22. 16:08 델파이

델파이 기초 - WebBrowser 기능 정리

 

WebBrowser에 글추가

 

procedure WebString(Web: TWebBrowser; msg : string);
var tmp : string;
begin
  tmp := Web.OleObject.Document.Body.innerHTML;
  tmp := tmp + msg;
  Web.OleObject.Document.Body.innerHTML := tmp;
  Web.OleObject.Document.Body.Doscroll('PageDown');
end;

웹브라우져 컨트롤을 이용할때, enter key와 ctrl+c/x 동작 하도록 하기

 

작성자   : 임기택 [xor74] 

IOleInPlaceActiveObject로 검색을 해보니 비슷한 문서들이 많이 있긴 하던데,
대부분 enter key에 대한 언급 뿐이더군요.
그래서 ctrl+c/ctrl+x에 대해서도 처리하도록 조금 수정 해 봤습니다.
참고하세요..

-------------------------------------------------------------------------------------
uses
 ActiveX, ClipBrd;

var
 Form1: TForm1;
 FOleInPlaceActiveObject: IOleInPlaceActiveObject;
 SaveMessageHandler: TMessageEvent;

procedure TForm1.FormActivate(Sender: TObject);
begin
 SaveMessageHandler := Application.OnMessage;
 Application.OnMessage := MyMessageHandler;
end;

procedure TForm1.FormDeactivate(Sender: TObject);
begin
 Application.OnMessage := SaveMessageHandler;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 Application.OnMessage := SaveMessageHandler;
 FOleInPlaceActiveObject := nil;
end;

procedure TForm1.MyMessageHandler(var Msg: TMsg; var Handled: Boolean);
const
 DialogKeys: set of Byte = [VK_LEFT, VK_RIGHT, VK_BACK, VK_UP, VK_DOWN,
   $30..$39, $41..$42, $44..$55, $57, $59..$5A];
begin
 { exit if we don't get back a webbrowser object }
 if WebBrowser1 = nil then
 begin
   Handled := False;
   Exit;
 end;

 if (Msg.hwnd = WebBrowser1.Handle) or (IsChild(WebBrowser1.Handle, Msg.hwnd)) then
 begin
   if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) and (GetKeyState(VK_CONTROL) < 0) then
   begin
     Handled := (WebBrowser1.Application as IOleInPlaceActiveObject).TranslateAccelerator(Msg)=S_OK;
     if (Msg.wParam = 67) then
     Clipboard.AsText := WebBrowser1.OleObject.Document.selection.createRange().text;
     if (Msg.wParam = 88) then
       WebBrowser1.OleObject.Document.selection.createRange().text := ';
     WebBrowser1.OleObject.Document.selection.createRange().select();
   end
   else
   begin
     Handled := not word(Msg.wParam) in [byte('A')..byte('Z'),VK_RETURN];
     if Handled or (Msg.wParam = VK_RETURN) then
       Handled := (WebBrowser1.Application as IOleInPlaceActiveObject).TranslateAccelerator(Msg)=S_OK;
   end
 end;

end;

 

WebBrowser에 메인과 프레임 읽기 완료 알기

 

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
 CurWebrowser: IWebBrowser;
 TopWebBrowser: IWebBrowser;
 Document: OleVariant;
 WindowName: string;
begin
 CurWebrowser := pDisp as IWebBrowser;
 TopWebBrowser := (Sender as TWebBrowser).DefaultInterface;
 if CurWebrowser = TopWebBrowser then
   Memo1.Lines.Add('Complete document was loaded')
 else;
 begin
   Document := CurWebrowser.Document;
   WindowName := Document.ParentWindow.Name;
   Memo1.Lines.Add(Format('Frame "%s" was loaded', [WindowName]));
 end;
end;

 

TWebBrowser에서 특정문자를 부각시키고 위치하기

 

TWebBrowser에 불려진 윕분서에서 특정 문자열을 찾아서 부각시키고
찾은 문자열에 화면을 스크롤하여 보여줍니다.

아래의 코드는 찾은 문자열의 배경을 빨간색으로 바꾸어 줍니다.
prefix 를 바꾸어주면 다르게도 가능하겠죠. ^^

TEmbeddedWB에서도 WBLocateHighlight(WB: TWebBrowser; Text: string)을
WBLocateHighlight(WB: TEmbeddedWB; Text: string)으로 바꾸어주면 사용 할 수 있습니다.


uses mshtml;

procedure WBLocateHighlight(WB: TWebBrowser; Text: string) ;
const
  prefix = '<span style="color:white; background-color: red;">';
  suffix = '</span>';
var
  tr: IHTMLTxtRange;
begin
  if Assigned(WB.Document) then
  begin
    tr := ((wb.Document AS IHTMLDocument2).body AS IHTMLBodyElement).createTextRange;
    while tr.findText(Text, 1, 0) do
    begin
      tr.pasteHTML(prefix + tr.htmlText + suffix) ;
      tr.scrollIntoView(True) ;
    end;
  end;
end;

사용 방법은 
WBLocateHighlight(WebBrowser1,'musk95') ;
입니다.

 

WebBrowser를 이용하여 폼 필드에 값 할당과 submit

 

i) 직접 접근 방법

 WebBrowser1.OleObject.Document.frmMain.userID.value := 'k133';
                             // 폼 이름과 폼 필드 이름을 직접 코딩
 WebBrowser1.OleObject.Document.frmMain.submit;
 => "구성원이 없습니다." 라는 에러 발생합니다.


ii) 이름으로 접근 방법

 WebBrowser1.OleObject.Document.all.item('userID').value := 'k133';

 WebBrowser1.OleObject.Document.all.item('submit').Click;

 

빈화면을 만들기


procedure NewDocument;
var
 C: array[0..MAX_PATH-1] of Char;
 FileName: String;
begin
 GetTempPath( MAX_PATH, C );
 FileName := C;
 if FileName[ Length( FileName ) ] <> '\' then FileName := FileName + '\';
 FileName := FileName + 'test.htm';
 with TFileStream.Create( FileName, fmCreate ) do Free;
 WebBrowser.Navigate( FileName );
end;

소스보기

 

procedure 프로시져명;
var MyDocument: OleVariant;
begin
  MyDocument := WebBrowser1.Document;
  Memo1.Lines.Clear;
  // HTML 소스 보기
  Memo1.Lines.Add(MyDocument.DocumentElement.InnerHTML);
  // 일반 내용 보기
  Memo1.Lines.Add(WebBrowser1.OleObject.Document.DocumentElement.InnerText);
  Memo1.Visible:= True;
  Memo1.Align:= alClient;
  if Memo1.CanFocus then
  Memo1.SetFocus;
end;

 

싸이트이동

WebBrowser1.Navigate('싸이트명');

WebBrowser1.Navigate('About:Blank'); //웹브라우져초기화

 

현재오픈된 URL가지고 오기

procedureOKGetURL(AStrings:TStrings); 

functionWebBrowserCheck(constWebb:IWebBrowser2):Boolean; 
var WebV:Variant; 
    Buf:string; 
begin
  WebV:=Webb; 
  Result:=False; 
  if Assigned(Webb)then 
  try 
    Buf:=WebV.Document.URL; 
    Result:=True; 
  except; 
  end; 
end; 

var 
  Count,i:integer; 
  mShellWindow:IShellWindows; 
  Webb:IWebBrowser2; 
  WebV:Variant; 
begin 
  mShellWindow:=CreateComObject(CLASS_ShellWindows) as IShellWindows; 
  Count:=mShellWindow.Count; 
  fori:=0 to Count-1 do
  begin 
    ifWebBrowserCheck(mShellWindow.Item(i)asIWebBrowser2) then
    begin 
      try
        Webb:=IWebBrowser2(mShellWindow.Item(i));
        WebV:=Webb; 
        AStrings.Add(WebV.Document.URL);
      except; 
      end;     
    end;
  end;
end;

 

WebBrowser에서 이미지 찾아서 클릭하기

 

uses
  
MSHTML;

var
  
iDoc: IHtmlDocument2;
  i: integer;
  ov: OleVariant;
  iDisp: IDispatch;
  iColl: IHTMLElementCollection;
  InputImage: HTMLInputImage;
begin
  
WebBrowser1.ControlInterface.Document.QueryInterface(IHtmlDocument2, iDoc);
  if not Assigned(iDoc) 
then
  begin
    
Exit;
  end;
  ov := 'INPUT';
  iDisp := iDoc.all.tags(ov);
  if Assigned(IDisp) 
then
  begin
    
IDisp.QueryInterface(IHTMLElementCollection, iColl);
    if Assigned(iColl) 
then
    begin
      for 
i := 1 to iColl.Get_length 
do
      begin
        
iDisp := iColl.item(pred(i), 0);
        iDisp.QueryInterface(HTMLInputImage, InputImage);
        if Assigned(InputImage) 
then
        begin
          if 
InputImage.Name = 'submit' 
then
          
// if the name is submit / falls der name submit lautet
          
begin
            
InputImage.Click;  
// click it / klick es
          
end;
        end;
      end;
    end;
  end;
end;

// 2.

procedure TForm1.Button1Click(Sender: TObject);
var
  
i: Word;
  Document: IHtmlDocument2;
  str: string;
begin
  
// Schleife über alle Bilder im Webbrowser
  
for i := 0 to WebBrowser1.OleObject.Document.Images.Length - 1 
do
  begin
    
Document := WebBrowser1.Document as IHtmlDocument2;
    
// URL auslesen
    
Str := (Document.Images.Item(i, 0) as IHTMLImgElement).Href;
    
// Dateiname des Bildes überprüfen
    
if Pos('submit_icon.gif', str) <> 0 
then
    begin
      
((Document.Images.Item(i, 0) as IHTMLImgElement) as IHTMLElement).Click;
    end;
  end;
end;


'델파이' 카테고리의 다른 글

Virtual Key Codes  (0) 2019.09.23
화면 캡쳐하기  (0) 2019.09.23
TWebBrowser에 직접 HTML 소스코드 넣기  (0) 2011.07.05
Creating and Using DLLs from Delphi  (0) 2011.07.05
유니코드로 인코딩 된 텍스트 파일 읽기  (0) 2011.07.05
posted by 유돌이
2011. 7. 5. 13:11 델파이
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, ActiveX;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure WBLoadHTML(WebBrowser: TWebBrowser; HTMLCode: string) ;
var
   sl: TStringList;
   ms: TMemoryStream;
begin
   WebBrowser.Navigate('about:blank') ;
   while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
    Application.ProcessMessages;

   if Assigned(WebBrowser.Document) then
   begin
     sl := TStringList.Create;
     try
       ms := TMemoryStream.Create;
       try
         sl.Text := HTMLCode;
         sl.SaveToStream(ms);
         ms.Seek(0, 0);
         (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms)) ;
       finally
         ms.Free;
       end;
     finally
       sl.Free;
     end;
   end;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
var
  sHTML : string;
begin
  sHTML := '<a href="http://www.howto.pe.kr">GOTO</a>' +
           '<b>howto.pe.kr</b>';
  WBLoadHTML(WebBrowser1,sHTML) ;
end;

end.

posted by 유돌이
2011. 7. 5. 13:10 델파이

Creating a Dynamic Link Library

The following few lines will demonstrate how to create a simple DLL using Delphi.

For the beginning start Delphi and select File | New ... DLL. This will create a new DLL template in the editor window. Select the default text and replace it with the next piece of code.

 library TestLibrary;
 
 uses SysUtils, Classes, Dialogs;
 
 procedure DllMessage; export;
 begin
   ShowMessage('Hello world from a Delphi DLL') ;
 end;
 
 exports DllMessage;
 
 begin
 end. 
If you look at the project file of any Delphi application, you’ll see that it starts with the reserved word Program. By contrast, DLLs always begin with the reserved word Library. This is then followed by a uses clause for any needed units. In this simple example, there then follows a procedure called DllMessage which does nothing except showing a simple message.

At the end of the source code we find an exports statement. This lists the routines that are actually exported from the DLL in a way that they can be called by another application. What this means is that we can have, let's say, 5 procedures in a DLL and only 2 of them (listed in the exports section) can be called from an external program (the remaining 3 are "sub procedures" in a DLL).

In order to use this simple DLL, we have to compile it by pressing Ctrl+F9. This should create a DLL called SimpleMessageDLL.DLL in your projects folder.

Finally, let's see how to call the DllMessage procedure from a (statically loaded) DLL.

To import a procedure contained in a DLL, we use the keyword external in the procedure declaration. For example, given the DllMessage procedure shown earlier, the declaration in the calling application would look like :

 procedure DllMessage; external 'SimpleMessageDLL.dll' 
the actual call to a procedure will be nothing more than
 DllMessage; 
The entire code for a Delphi form (name: Form1) with a TButton on it (name: Button1) that's calls the DLLMessage function could be:
 unit Unit1;
 
 interface
 
 uses
    Windows, Messages, SysUtils, Variants, Classes,
    Graphics, Controls, Forms, Dialogs, StdCtrls;
 
 type
    TForm1 = class(TForm)
      Button1: TButton;
      procedure Button1Click(Sender: TObject) ;
    private
      { Private declarations }
    public
      { Public declarations }
    end;
 
 var
    Form1: TForm1;
 
   procedure DllMessage; external 'SimpleMessageDLL.dll'
 
 implementation
 
 {$R *.dfm}
 
 procedure TForm1.Button1Click(Sender: TObject) ;
 begin
    DllMessage;
 end;
 
 end. 

posted by 유돌이
2011. 7. 5. 13:08 델파이

function ReadUnicode(fName: String): WideString;
var
  F: File;
  FileSize, ReadSize: Cardinal;
  SearchRec: TSearchRec;
  Buffer: WideString;


begin
  FileSize:=0;
  if FindFirst(fName, faAnyFile, SearchRec)=0 then begin
    FileSize:=SearchRec.Size;
    FindClose(SearchRec);
  end;

 

  AssignFile(F, fName);
  SetLength(Buffer, FileSize);
  Reset(F, 1);
  BlockRead(F, PAnsiChar(Buffer)^, FileSize, ReadSize);

 

  Result:=Buffer;
  CloseFile(F);
end;

 

 

사용예

procedure TForm1.Button1Click(Sender: TObject);

const 파일경로 = 'C:\유니코드파일.dat';

var sList: TStringList;

begin

  sList:=TStringList.Create;

  try

    sList.Text:=ReadUnicode(파일경로);

    Memo1.Text:=sList.Text;

  finally

    FreeAndNil(sList);

  end;

end

posted by 유돌이
2010. 1. 11. 14:37 델파이

프로그램을 띄우거나 파일을 실행할경우 ShellAPI 함수인 ShellExecute() 를 사용합니다.
이 함수는 윈도우즈 탐색기에서 파일을 선택하고 더블클릭하는 기능과 동일한 동작을 합니다.
다음은 ShellExecute() 의 몇가지 사용예입니다.

(1) 파일과 연관(association)된 프로그램으로 파일을 엽니다
    ShellExecute(Handle, 'open', PChar('test.txt'), nil, nil, SW_SHOW);

(2) notepad.exe 에 파라미터로 config.sys 파일을 주어 메모장을 실행합니다
    ShellExecute(Handle, 'open', 'notepad', 'c:\config.sys', nil, SW_SHOW);

(3) PC에 설치된 기본 웝브라우저로 지정한 사이트를 엽니다.
    ShellExecute(Handle, 'open', 'www.howto.pe.kr', nil, nil, SW_SHOW);

(4) 특정 폴더를 시작 폴더로 하는 윈도우즈 탐색기를 엽니다
    ShellExecute(Handle, 'explore', PChar('c:\windows)', nil, nil, SW_SHOW);

(5) readme.doc 파일을 연결된 프로그램으로 인쇄하고 화면을 닫습니다
    ShellExecute(Handle, 'print', 'readme.doc', nil, nil, SW_SHOW);
   
(6) rMyDelphiFile.pas 파일을 wordpad 프로그램으로 인쇄하고 화면을 닫습니다
    ShellExecute(Handle, 'print', 'wordpad.wxe', 'MyDelphiFile.pas', nil, SW_SHOW);

(7) readme.doc 파일을 프린터를 선택하여 연결된 프로그램으로 인쇄하고 화면을 닫습니다
    var
      Device : array[0..255] of char;
      Driver : array[0..255] of char;
      Port   : array[0..255] of char;
      S: String;
      hDeviceMode: THandle;
    begin
      Printer.PrinterIndex := -1;  // 프린터 인덱스를 지정합니다. 여기서는 기본 프린터(-1) 선택
      Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
      S := Format('"%s" "%s" "%s"',[Device, Driver, Port]);
      ShellExecute(Handle, 'printto', 'readme.doc', Pchar(S), nil, SW_HIDE);

(8) 기본 메일 프로그램을 실행합니다.
    ShellExecute(Handle, nil, 'mailto:cozy@howto.pe.kr', nil, nil, SW_SHOW);

(9) DOS 명령어를 실행하고 화면을 닫습니다
    ShellExecute(Handle, 'open', PChar('command.com'), PChar('/c copy file1.txt file2.txt'), nil, SW_SHOW);

(10) DOS 명령어를 실행하고 화면을 닫지 않습니다
     ShellExecute(Handle, 'open', PChar('command.com'), PChar('/k dir'), nil, SW_SHOW);

(11) ShellExecute()의 리턴값은 실행된 프로그램의 핸들이거나 에러코드입니다
     리턴값이 32 이하이면 에러가 발생한것으로 각각은 아래와 같은 의미가 있습니다

  var
    code: Integer;
  begin
    code := ShellExecute(...);
    if code <= 32 then ShowMessage(ShowShellExecuteError(code));
  end;
    
  // ShellExecute()의 리턴코드에 대한 에러 메시지
  function ShowShellExecuteError(i: integer): String;
  begin
    case i of 0: result := 'The operating system is out of memory or resources.';
      ERROR_FILE_NOT_FOUND: result := 'The specified file was not found.';
      ERROR_PATH_NOT_FOUND: result := 'The specified path was not found.';
      ERROR_BAD_FORMAT: result := 'The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).';
      SE_ERR_ACCESSDENIED: result := 'The operating system denied access to the specified file.';
      SE_ERR_ASSOCINCOMPLETE: result := 'The filename association is incomplete or invalid.';
      SE_ERR_DDEBUSY: result := 'The DDE transaction could not be completed because other DDE transactions were being processed.';
      SE_ERR_DDEFAIL: result := 'The DDE transaction failed.';
      SE_ERR_DDETIMEOUT: result := 'The DDE transaction could not be completed because the request timed out.';
      SE_ERR_DLLNOTFOUND: result := 'The specified dynamic-link library was not found.';
      //SE_ERR_FNF          : result:='The specified file was not found.';
      SE_ERR_NOASSOC           : result:='Unbekannter Extender.';
      SE_ERR_OOM: result := 'There was not enough memory to complete the operation.';
      //SE_ERR_PNF          : result:='The specified path was not found.';
      SE_ERR_SHARE: result := 'A sharing violation occurred.';
    end;
  end;

(12) ShellExecuteEX()를 이용하여 notepad.exe 를 실행한 후 종료될때까지 기다립니다
  var
    SEInfo: TShellExecuteInfo;
    ExitCode: DWORD;
    ExecuteFile, ParamString, StartInString: string;
  begin
    ExecuteFile   := 'notepad.exe';   // 실행할 프로그램
    ParamString   := 'c:\winzip.log'; // 프로그램의 명령행 파라미터
    StartInString := 'c:\';           // 시작 위치
    FillChar(SEInfo, SizeOf(SEInfo), 0);
    SEInfo.cbSize := SizeOf(TShellExecuteInfo);

    with SEInfo do
    begin
      fMask        := SEE_MASK_NOCLOSEPROCESS;
      Wnd          := Application.Handle;
      lpFile       := PChar(ExecuteFile);
      lpParameters := PChar(ParamString);
      lpDirectory  := PChar(StartInString);
      nShow        := SW_SHOWNORMAL;
    end;
    if ShellExecuteEX(@SEInfo) then
    begin
      repeat
        Application.ProcessMessages;
        GetExitCodeProcess(SEInfo.hProcess, ExitCode);
      until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
      ShowMessage('프로그램이 종료되었습니다');
    end
    else ShowMessage('프로그램을 실행할 수 없습니다');

 

출처 : http://www.howto.pe.kr 작성자 : 김영대님!


posted by 유돌이
2010. 1. 11. 14:36 델파이

간단한 예제 입니다.

[uses : ShellApi 추가!]

 

function DeleteDirectory(Const DirPath: String): Boolean;
var
  SHFileOpStruct: TSHFileOpStruct;
  DirBuf: array [0..255] of char;
  Directory: string;

begin
  try
    Directory := ExcludeTrailingPathDelimiter(DirPath);
    Fillchar(SHFileOpStruct, sizeof(SHFileOpStruct), 0);
    FillChar(DirBuf, sizeof(DirBuf), 0);
    StrPCopy(DirBuf, Directory);

    with SHFileOpStruct do
    begin
      Wnd := 0;
      pFrom := @DirBuf;
      wFunc := FO_DELETE;
      //fFlags := fFlags or FOF_ALLOWUNDO; // 휴지통에 담기
      fFlags := fFlags or FOF_NOCONFIRMATION;
      fFlags := fFlags or FOF_SILENT;
    end;
    Result := (SHFileOperation(SHFileOpStruct) = 0);
  except
    Result := False;
  end;
end;


posted by 유돌이
2010. 1. 11. 14:35 델파이

function ResponseCodeCheck(URL: String): Boolean;
var
  IdHTTP1: TIdHTTP;

begin
  Result := False;
  IdHTTP1 := TIdHTTP.Create;
  try
    IdHTTP1.Get(URL);

    case IdHTTP1.ResponseCode of
      200:
      begin
        Result := True;
        OutputDebugString('OK');
      end;

     403:OutputDebugString('Forbidden');
     404:OutputDebugString('Not Found');
     500:OutputDebugString('Server Error');

      else begin

        OutputDebugString('The Others ');

      end;
    end;
 finally
    FreeAndNil(IdHTTP1);
  end;


posted by 유돌이
2010. 1. 11. 14:35 델파이
[발생하기 쉬운 HTTP상태코드]

200 : request가 성공적으로 완료되었음.
204 : request가 실행되었으나 클라이언트에게 보낼 데이터가 없음.
300 : 요구된 request가 여러 위치에 존재하는 자원을 필요로 하므로
request는 위에대한 정보를 보낸다. 클라이언트는 가장 적당한
위치를 선택하여야 함.
302 : request가 요구한 데이터를 발견하였으나 실제 다른 url에 존재함.
400 : request의 문법이 잘못되었음.
403 : request는 금지된 자원을 요구하였음.
404 : 서버는 요구된 url을 찾을 수 없음.
500 : 서버에 내부적으로 오류가 발생하여 더 이상을 진행할 수 없음.
501 : 요청된 request는 합법적이나 서버는 요구된 method를 지원하지 않음.
503 : 서버가 바쁘기 때문에 서비스를 할 수 없음. 
posted by 유돌이
prev 1 2 3 4 5 6 ··· 9 next