7 Hal yang Tidak Bisa Kita Ubah

7 Hal yang Tidak Bisa Kita Ubah

1. Jenis kelamin. Memang ada operasi untuk mengubah kelamin. Tapi tidak bisa mengubah roh (spirit) orang yang bersangkutan.
Terimalah dirimu, apakah engkau wanita ataupun pria. Act like a woman / man!!

2. Orang tua. Tidak ada yang bisa memilih dilahirkan oleh orang tua yang mana. So, you must respect your parents!! Apakah
orang tuamu seorang pemabuk, penjudi, pelacur sekalipun, you must respect them!! Kalau tidak, itu akan terjadi dalam
kehidupanmu nanti. Your kids won’t respect you, is it terrible?

3. Hari kelahiran. Sudah ditetapkan. Amazing ha? But it’s true. Jangan menyesali, mengapa engkau harus lahir ke dunia tapi
disia-siakan oleh orang yang kau kasihi.

4. Bentuk Fisik. Kalau engkau keriting, yah keriting aja. Kalau hidungmu pesek, terima itu. Saya banyak melihat orang yang
mengubah bentuk wajahnya, apakah itu memancungkan hidung, alis matanya dicukur habis, dll, jadi kelihatan aneh dan
tidak natural.

5. Masa lalu. Ini juga sudah ditetapkan oleh Tuhan. Jangan melihat ke belakang. karena itu hanya membuat engkau “frozen” -
can not do anything! Look at the future and see how good it is.

6. Kedudukan dalam keluarga. Apakah engkau anak bungsu, sulung, atau tengah, you can not change it. Nikmati sajalah.

7. Suku bangsa/ras. Menyesal jadi orang Indonesia yang terus menerus dilanda kesulitan? Atau menyesal jadi orang Batak yang
kalau menikah perlu upacara adat yang walahhhh mahal dan lama? Atau jadi orang Cina yang suka ditindas dan diintimidasi?
hmmm…..

Nah, sekarang ubah cara berpikirmu. Tuhan sudah menetapkan engkau di bangsa ini untuk satu tujuan. So, do the best in your
job, loyal, jangan korupsi, itu sudah menolong untuk memperbaiki bangsa kita ini.

Itulah 7 hal yang tidak bisa kita ubah. Kalaupun ada yang kita bisa ubah, misalnya: bentuk fisik, itu akan membawa kita ke
dalam situasi yang tidak pernah puas. Selalu ingin ubah penampilan terus. Capek kan? Terimalah dirimu apa adanya. Apa yang
kau lakukan setiap hari itu lebih penting dari penampilanmu. Bukan berarti kau bisa berpenampilan seenaknya, tidak!! Tapi
engkau harus menerima apa yang sudah diberikan padamu. Kulitmu yang hitam (manis), hidungmu yang kurang mancung, rambut
yang lurus, kurang tinggi, dll, dsb deh.

3 TAHUN, 80 TAHUN

3 TAHUN, 80 TAHUN

Pada zaman dahulu kala, hiduplah seorang petapa yang tinggal sepanjang waktu di sebuah pohon. Tak peduli hujan angin atau terik matahari, ia tetap bertahan di pohon yang tinggi itu. Karena kebiasaan anehnya itu, orang-orang desa menjulukinya Si Sarang Burung. Continue reading

Tutorial jQuery (Part 1)

jQuery Tutorial (Part 1)

  • Apa yang harus sebelumnya anda tahu

Sebelum melanjutkan lebih jauh tentang jQuery, anda seharusnya telah memiliki pengetahuan tentang :

  1. HTML
  2. CSS
  3. JavaScript Continue reading

Memahami OpenVPN (part 1)

Memahami OpenVPN

1. Apakah VPN itu dan apakah perbedaan antara VPN dengan software security lainnya?

  • Secara mendasar, VPN adalah sekumpulan tools yang mengijinkan jaringan yang berbeda lokasi dapat terkoneksi/berhubungan dengan aman, dimana menggunakan jaringan public sebagai transport layer (transport layer).
  • VPN menggunakan cryptography dalam memberikan layanan keamanan melawan serangan dari luar jaringan
  • VPN merupakan software yang paling umum digunakan saat ini dalam komunikasi jarak jauh dan menghubungkan  kantor-kantor cabang melalui jaringan aman WAN. Continue reading

Tutorial TCP/IP

I. TCP/IP Tutorial

TCP/IP merupakan sebuah protocol komunikasi untuk internet, yang mengatur bagaimana komputer saling berkomunikasi, dimana setiap komputer yang tersambung ke internet harus mengikuti aturan-aturan tersebut.

Protokol Komunikasi Komputer

Adalah deskripsi dari aturan-aturan yang harus diikuti setiap komputer untuk berkomunikasi dengan komputer lain.

Apakah TCP/IP

TCP/IP adalah protokol komunikasi antar komputer yang tersambung di internet, TCP/IP berasal dari kata Transmission Control Protocol/Internet Protokol. TCP/IP menentukan bagimana perangkat elektronik (seperti komputer) seharusnya tersambung ke jaringan internet, dan bagaimana data seharusnya di kirimkan antar komputer-komputer tersebut.

Bagian dalam TCP/IP

Dalam TCP/IP terdapat sejumlah protokol untuk menangani komunikasi data :

  • TCP (Transmission Control Protokol) Komunikasi antar aplikasi.
  • UDP (User Datagram Protokol) Komunikasi sederhana antar aplikasi.
  • IP (Internet Protokol) Komunikasi antar komputer.
  • ICMP (Internet Control Message Protocol) untuk errors dan data statistik.
  • DHCP (Dynamic Host Configuration Protocol) untuk pengalamatan komputer dengan dinamis.

TCP menggunakan Fixed Connection

Merupakan komunikasi antara aplikasi. Apabila sebuah aplikasi akan berkomunikasi dengan aplikasi lain melalui TCP, maka aplikasi tersebut harus mengirimkan permintaan untuk melakukan komunikasi. Permintaan ini harus dikirim ke alamat yang tepat. Setelah “handshake” antar dua aplikasi selesai, maka TCP akan merubah komunikasi menjadi “Full-Duplex” antara dua aplikasi tersebut.

Komunikasi Full-duplex akan menempati komunikasi antar dua komputer sampai salah satu aplikasi menutup komunikasi tersebut. UDP sangat mirip dengan TCP, hanya saja lebih sederhana dari TCP dan kurang handal.

IP adalah Connection-less

Digunakan untuk berkomunikasi antara komputer. IP merupakan protokol komunikasi yang “Connection-less”. IP tidak menempati jalur komunikasi antara komputer. IP mengurangi kebutuhan atas jalur jaringan. Setiap jalur dapat digunakan untuk antar banyak komputer yang berbeda sekaligus. Dengan IP pesan (atau data paket lain) di pecah menajadi “paket-paket” kecil dan dikirim antar komputer yang berada dalam jaringan internet. IP bertanggungjawab untuk “merouting” paket-paket ini ke tujuan dengan benar.

IP Routers

Apabila suatu paket dikirim dari sebuah komputer, maka paket tersebut tiba pada suatu IP router. IP router betanggungjawab untuk melakukan “routing” terhadap paket agar sampai ketujuan baik secara langsung maupun melalui router lain. Jalur yang ditempuh satu paket dengan paket yang lain mungkin berbeda dalam suatu komunikasi. Routing betanggungjawab untuk pengalamatan yang benar, tergantung dari tingkat kemacetan di jalur komunikasi, masalah di jaringan, dan faktor-fator parameter lain.

Analogy Connection-less

Komunikasi via IP gambarkan sebagai mengirimkan banyak surat dengan masing-masing kartupos, dimana masing-masing surat mungkin memiliki alamat tujuan yang berbeda, sehingga jalur yang ditempuh juga dapat berbeda untuk sampai ke tujuan.

TCP/IP

TCP/IP merupakan perpaduan kerjasama antara TCP dan IP, dimana TCP bertanggungjawab atas komunikasi antar aplikasi (misalnya : browser, aplikasi internet lain), sedangkan IP betanggungjawab atas komunikasi dengan komputer lain. TCP betanggungjawab untuk memecah data menjadi paket-paket kecil sebelum di kirim dan kembali di gabungkan menjadi satu paket (dari paket-paket kecil sebelumnya) di komputer tujuan. Dan IP akan betanggungjawab untuk membawa paket-paket kecil tadi ke tujuan.

II. Pengalamatan TCP/IP

TCP/IP menggunakan 32 bits, atau empat nomor antara 0 sampai 255 untuk pengalamatan komputer.

Sebuah alamat IP  terdiri 4 nomor

Setiap komputer harus memiliki sebuah alamat IP sebelum dapat tersambng ke jaringan internet, setiap paket IP harus memiliki alamat sebelum dikirim ke komputer tujuan, contoh dari alamat IP adalah : 192.68.20.50

Ini mungkin merupakan alamat yang sama dengan alamat IP diatas : www.niclogic.com

Setiap komputer harus memiliki alamat IP yang unik. TCP/IP menggunakan empat angka untuk memberi alamat sebuah komputer, angka-angka tersebut selalu terdiri antara 0 – 255. Alamat IP ini lazimnya dipisahkan dengan titik, seperti ini : 192.168.0.155

32 bits = 4 byte

TCP/IP menggunakan pengalamatan 32 bits,satu byte komputer adalah 8 bits, jadi TCP/IP menggunakan 4 byte, satu byte dapat berisi 256 nilai :

00000000,00000001,00000010,00000100,00000101,00000110,00000111, … 11111111

nah sekarang kita tahu kenapa pengalamatan TCP/IP berada antara angka 0 – 255

Nama domain

Sebuah nama akan lebih mudah diingat dibandingkan dengan deretan sejumlah angka, nama yang diperuntukkan untuk pengalamatan IP dikenal dengan nama domain (domain names).

Niclogic.com adalah nama domain. Ketika kita mengetikan di browser www.niclogic.com maka nama tersebut akan diterjemahkan ke dalam angka oleh Domain Name Server (DNS). DNS tersambung keseluruh jaringan internet di dunia, dimana DNS server tersebut bertanggungjawab untuk menterjemahkan nama domain ke alamat TCP/IP. Ketika nama domain di daftarkan bersama dengan alamat TCP/IP makan DNS server diseluruh dunia akan di update dengan informasi baru tersebut.

III. Protokol TCP/IP

Keluarga dari protocol

TCP/IP merupakan kumpulan dari berbagai protokol komunikasi yang berbeda beradasarkan dari protokol dasar TCP dan IP.

TCP – Transmission Control Protocol

Digunakan untuk transmisi data dari suatu aplikasi ke internet, dimana TCP bertanggungjawab untuk memecah suatu data paket menjadi paket-paket yang lebih kecil sebelum dikirm dan menyatukannya kembali setelah sampai ditujuan.

IP – Internet Protokol

Menangani komunikasi dengan komputer lain, dimana IP betanggungjawab atas pengiriman dan penerimaan paket data dari dan ke internet.

HTTP – Hyper Text Transfer Protocol

Untuk menangani komunikasi antara web server dan web browser, dimana HTTP digunakan untuk mengirim permintaan dari client (browser)  ke web server dan mengembalikan web konten (halaman web) dar server kembali ke client.

HTTPS – Secure HTTP

Untuk menangani komunikasi aman (secure communication)antara web server dan web browser, biasanya untuk menangani transaksi kartu kredit dan data sensitif lain.

SSL – Secure Socket Layer

Digunakan untuk enkripsi data untuk transmisi aman (secure transmision).

SMTP – Simple Mail Transfer Protocol

Digunakan untuk transmisi e-mail

MIME – Multi-purpose Internet Mail Extesions

Memungkinan SMTP untuk mentransmisikan file multimedia seperti suara,music, melalui jaringan TCP/IP

IMAP – Internet Message Access Protocol

Digunakan untuk menyimpan dan mengambil e-mail.

POP – Post Office Protocol

Digunakan untuk mengunduh e-mail dari e-mail server ke local komputer.

FTP – File Transfer Protocol

Menghandel pengiriman file antar komputer.

NTP – Network Time Protocl
DHCP – Dynamic Host Configuration Protocol

Digunakan untuk mengalokasikan alamat IP yang dinamis dalam suatu jaringan.

SNMP – Simple Network Management Protocol

Digunakan untuk administrasi dari komputer yang ada di jaringan.

LDAP – Lightweight Directory Access Protocol

Digunakan untuk mengumpulkan email dan dan informasi tentang pengguna (users) di jaringan internet

ICMP – Internet Control Message protocol

Untuk menangani kesalahan/error pada jaringan.

ARP – Address Resolution Protocol

Digunakan oleh IP untuk menemukan alamat perangkat keras kartu jaringan berdasarkan alamat IP dari sebuah komputer.

RARP – Reverse Address Resolution Protocol

Digunakan oleh IP untuk menemukan alamat IP berdasarkan alamat perangat keras dari kartu jaringan dari sebuah komputer.

BOOTP – Boot Protocol

Digunakan untuk merestart komputer dari jaringan.

PPTP – Point to Point Tunnel Protocol

Digunakan untuk mengatur koneksi (tunnel) antar jaringan pribadi (private network).

IV. TCP/IP Email

Email merupakan salah satu hal yang paling penting yang digunakan di TCP/IP

You don’t

Ketika kita menulis e-mail, kita tidak menggunakan TCP/IP, tetapi kita menggunakan program email seperti : Lotus notes,Microsoft Outlook, atau Netscape Communicato

Program email kita

Program email kita menggunakan protokol TCP/IP yang berbeda    :

  • Yang mengirim email kita menggunakan SMTP
  • Mengunduh email dari email server menggunakan POP
  • Melakukan koneksi ke suatu email server menggunakan IMAP

SMTP – Simple Mail Transfer Protocol

Protokol SMTP digunakan transmisi email. SMTP bertanggungjawab dalam pengiriman email anda ke komputer lain. Biasanya email anda dikirim ke email server (server SMTP), kemudian ke server lain sampai tiba di tujuan. SMTP hanya dapat mengirimkan data yang murni text,SMTP tidak dapat mengirimkan data berupa data binary (exe),suara,film. SMTP menggunakan MIME untuk mengirimkan data binary melalui jaringan TCP/IP,dmana protokol MIME mengkonversikan data binary ke text.

POP – Post Office Protocol

Digunakan oleh program email untuk (seperti OutLook) untuk mengambil email dari email server, jika program email kita menggunakan POP,semua email kita akan di unduh ke program email (sering disebut emai client) setiap kali program email tersambung ke email server.

IMAP – Internet Message Access Protocol

Protokol IMAP digunakan program email (seperti OutLook) sama halnya dengan POP, perbedaan utama IMAP dengan POP adalah IMAP tidak secara otomatis mengunduh email dari email server ketika program email tersambung ke email server.

Protokol IMAP mengijinkan kita untuk hanya melihat email kita, dan dapat menghapus email yang ingin kita hapus, salah satu keuntungan menggunakan protokol ini adalah kita dapat mengakses email kita dari berbagai lokasi, dan hanya mendownload email kita kita kita berada di komputer kita.

Sending an image to the printer

Question:

How can I reliably print an image to the printer?

Answer:

Sending a bitmap based on the screen to the printer is an invalid operation that will usually fail, unless the print driver has been designed to detect this error condition and compensate for the error. This means you should use the VCL canvas methods Draw, StretchDraw,CopyRect, BrushCopy, and the like to transfer a bitmap to the printer, since the underlying bitmap is based on the screen, and is device dependent. The only way to reliably print an image is to use DIBs (Device Independent Bitmaps). Getting a valid DIB can be difficult, as there are many Windows API functions that must be used correctly. Further, many video drivers incorrectly fill in the DIB structure in regards to the color table in the DIB.

The following example demonstrates an attempt to overcome some of these problems and limitations. The example should compile successfully under all versions of Delphi/C++ Builder.

The core function in the example, BltTBitmapAsDib(), accepts a handle to a device to image to, the x and y coordinates you wish the bitmap to be imaged at, the width and height you wish the image to be (stretching and shrinking is acceptable), and the TBitmap you wish to image.

Example:

uses Printers;

type

PPalEntriesArray = ^TPalEntriesArray; {for palette re-construction}

TPalEntriesArray = array[0..0] of TPaletteEntry;

procedure BltTBitmapAsDib(DestDc : hdc; {Handle of where to blt}

x : word; {Bit at x}

y : word; {Blt at y}

Width : word; {Width to stretch}

Height : word; {Height to stretch}

bm : TBitmap); {the TBitmap to Blt}

var

OriginalWidth :LongInt; {width of BM}

dc : hdc; {screen dc}

IsPaletteDevice : bool; {if the device uses palettes}

IsDestPaletteDevice : bool; {if the device uses palettes}

BitmapInfoSize : integer; {sizeof the bitmapinfoheader}

lpBitmapInfo : PBitmapInfo; {the bitmap info header}

hBm : hBitmap; {handle to the bitmap}

hPal : hPalette; {handle to the palette}

OldPal : hPalette; {temp palette}

hBits : THandle; {handle to the DIB bits}

pBits : pointer; {pointer to the DIB bits}

lPPalEntriesArray : PPalEntriesArray; {palette entry array}

NumPalEntries : integer; {number of palette entries}

i : integer; {looping variable}

begin

{If range checking is on – lets turn it off for now}

{we will remember if range checking was on by defining}

{a define called CKRANGE if range checking is on.}

{We do this to access array members past the arrays}

{defined index range without causing a range check}

{error at runtime. To satisfy the compiler, we must}

{also access the indexes with a variable. ie: if we}

{have an array defined as a: array[0..0] of byte,}

{and an integer i, we can now access a[3] by setting}

{i := 3; and then accessing a[i] without error}

{$IFOPT R+}

{$DEFINE CKRANGE}

{$R-}

{$ENDIF}

{Save the original width of the bitmap}

OriginalWidth := bm.Width;

{Get the screen’s dc to use since memory dc’s are not reliable}

dc := GetDc(0);

{Are we a palette device?}

IsPaletteDevice :=

GetDeviceCaps(dc, RASTERCAPS) and RC_PALETTE = RC_PALETTE;

{Give back the screen dc}

dc := ReleaseDc(0, dc);

{Allocate the BitmapInfo structure}

if IsPaletteDevice then

BitmapInfoSize := sizeof(TBitmapInfo) + (sizeof(TRGBQUAD) * 255)

else

BitmapInfoSize := sizeof(TBitmapInfo);

GetMem(lpBitmapInfo, BitmapInfoSize);

{Zero out the BitmapInfo structure}

FillChar(lpBitmapInfo^, BitmapInfoSize, #0);

{Fill in the BitmapInfo structure}

lpBitmapInfo^.bmiHeader.biSize := sizeof(TBitmapInfoHeader);

lpBitmapInfo^.bmiHeader.biWidth := OriginalWidth;

lpBitmapInfo^.bmiHeader.biHeight := bm.Height;

lpBitmapInfo^.bmiHeader.biPlanes := 1;

if IsPaletteDevice then

lpBitmapInfo^.bmiHeader.biBitCount := 8

else

lpBitmapInfo^.bmiHeader.biBitCount := 24;

lpBitmapInfo^.bmiHeader.biCompression := BI_RGB;

lpBitmapInfo^.bmiHeader.biSizeImage :=

((lpBitmapInfo^.bmiHeader.biWidth *

longint(lpBitmapInfo^.bmiHeader.biBitCount)) div 8) *

lpBitmapInfo^.bmiHeader.biHeight;

lpBitmapInfo^.bmiHeader.biXPelsPerMeter := 0;

lpBitmapInfo^.bmiHeader.biYPelsPerMeter := 0;

if IsPaletteDevice then begin

lpBitmapInfo^.bmiHeader.biClrUsed := 256;

lpBitmapInfo^.bmiHeader.biClrImportant := 256;

end else begin

lpBitmapInfo^.bmiHeader.biClrUsed := 0;

lpBitmapInfo^.bmiHeader.biClrImportant := 0;

end;

{Take ownership of the bitmap handle and palette}

hBm := bm.ReleaseHandle;

hPal := bm.ReleasePalette;

{Get the screen’s dc to use since memory dc’s are not reliable}

dc := GetDc(0);

if IsPaletteDevice then begin

{If we are using a palette, it must be}

{selected into the dc during the conversion}

OldPal := SelectPalette(dc, hPal, TRUE);

{Realize the palette}

RealizePalette(dc);

end;

{Tell GetDiBits to fill in the rest of the bitmap info structure}

GetDiBits(dc,

hBm,

0,

lpBitmapInfo^.bmiHeader.biHeight,

nil,

TBitmapInfo(lpBitmapInfo^),

DIB_RGB_COLORS);

{Allocate memory for the Bits}

hBits := GlobalAlloc(GMEM_MOVEABLE,

lpBitmapInfo^.bmiHeader.biSizeImage);

pBits := GlobalLock(hBits);

{Get the bits}

GetDiBits(dc,

hBm,

0,

lpBitmapInfo^.bmiHeader.biHeight,

pBits,

TBitmapInfo(lpBitmapInfo^),

DIB_RGB_COLORS);

if IsPaletteDevice then begin

{Lets fix up the color table for buggy video drivers}

GetMem(lPPalEntriesArray, sizeof(TPaletteEntry) * 256);

{$IFDEF VER100}

NumPalEntries := GetPaletteEntries(hPal,

0,

256,

lPPalEntriesArray^);

{$ELSE}

NumPalEntries := GetSystemPaletteEntries(dc,

0,

256,

lPPalEntriesArray^);

{$ENDIF}

for i := 0 to (NumPalEntries – 1) do begin

lpBitmapInfo^.bmiColors[i].rgbRed :=

lPPalEntriesArray^[i].peRed;

lpBitmapInfo^.bmiColors[i].rgbGreen :=

lPPalEntriesArray^[i].peGreen;

lpBitmapInfo^.bmiColors[i].rgbBlue :=

lPPalEntriesArray^[i].peBlue;

end;

FreeMem(lPPalEntriesArray, sizeof(TPaletteEntry) * 256);

end;

if IsPaletteDevice then begin

{Select the old palette back in}

SelectPalette(dc, OldPal, TRUE);

{Realize the old palette}

RealizePalette(dc);

end;

{Give back the screen dc}

dc := ReleaseDc(0, dc);

{Is the Dest dc a palette device?}

IsDestPaletteDevice :=

GetDeviceCaps(DestDc, RASTERCAPS) and RC_PALETTE = RC_PALETTE;

if IsPaletteDevice then begin

{If we are using a palette, it must be}

{selected into the dc during the conversion}

OldPal := SelectPalette(DestDc, hPal, TRUE);

{Realize the palette}

RealizePalette(DestDc);

end;

{Do the blt}

StretchDiBits(DestDc,

x,

y,

Width,

Height,

0,

0,

OriginalWidth,

lpBitmapInfo^.bmiHeader.biHeight,

pBits,

lpBitmapInfo^,

DIB_RGB_COLORS,

SrcCopy);

if IsDestPaletteDevice then begin

{Select the old palette back in}

SelectPalette(DestDc, OldPal, TRUE);

{Realize the old palette}

RealizePalette(DestDc);

end;

{De-Allocate the Dib Bits}

GlobalUnLock(hBits);

GlobalFree(hBits);

{De-Allocate the BitmapInfo}

FreeMem(lpBitmapInfo, BitmapInfoSize);

{Set the ownership of the bimap handles back to the bitmap}

bm.Handle := hBm;

bm.Palette := hPal;

{Turn range checking back on if it was on when we started}

{$IFDEF CKRANGE}

{$UNDEF CKRANGE}

{$R+}

{$ENDIF}

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

if PrintDialog1.Execute then begin

Printer.BeginDoc;

BltTBitmapAsDib(Printer.Canvas.Handle,

0,

0,

Image1.Picture.Bitmap.Width,

Image1.Picture.Bitmap.Height,

Image1.Picture.Bitmap);

Printer.EndDoc;

end;

end;

Control Panel Applets

How To Create Control Panel Applet ?

Creating a Control Panel Applet is a straight forward process. Simply create a Dynamic Link Library with the extension of .cpl (Control Panel Library) and place it in the Windows system directory. Each cpl file can support multiple control panel applets. The cpl will have a single function entry point called CPlApplet() that must be exported by name. All the following control panel messages will come through this single entry point:

Message:

CPL_INIT – Sent to indicate CPlApplet() was found. Return TRUE to continue the loading process.

CPL_GETCOUNT – Return the number of applets supported by the cpl.

CPL_INQUIRE – Sent for information about each applet supported by the cpl.lParam1 contains the zero based applet number for the inquiry. lParam2 points to a TCplInfo structure. The idIcon field of the TClpInfo structure should be initialized with the resource id for an icon to display, and the idName and idInfo fields should be initialized with the resource string id for the name and description string id.lData can contain applet defined data for use by the applet.

CPL_SELECT – Sent when the applet’s icon has been selected by the user. lParam1 contains the applet number that was selected. lParam2 contains the applet’s user defined lData value. Continue reading

Allow your Delphi Forms to Accept Dropped Files from Window Explorer

Drag and drop operations are commonly used operations in Windows applications. When working with Window Explorer you can copy, move and even delete files by using drag and drop.

Moving an object with the mouse button pressed is usually called dragging, and what happens when we end dragging by releasing the mouse button is called dropping.

While drag and drop is implemented in the VCL, to accept files from dragged from the Windows Explorer you need to handle a few shell api messages.

I can accept files!

For an object (window), like a Delphi form, to be able to accept files from the Windows shell a call to DragAcceptFiles is required. Next, a handler for the WM_DROPFILES message needs to be provided. Continue reading

How to Retrieve the Users Current IP address using Delphi code

In this tutorial you will learn how to retrieve the users current IP address using Delp
hi code. You can use this method in a variety of network applications or internet utilities.

If you would like to learn how to retrieve the user IP address follow the steps below.

Make sure to add this code to the beginning of your project:

uses

Winsock;

Step One – IP Finding Function

To make it easier to find and read the users current IP address create a function called getIPS using the code provided below. It is recommended that you copy and paste so you don’t miss anything. However be encouraged to read through the code to learn from it and how it works.

function getIPs: Tstrings;

type

TaPInAddr = array[0..10] of PInAddr;

PaPInAddr = ^TaPInAddr;

var

phe: PHostEnt;

pptr: PaPInAddr;

Buffer: array[0..63] of Char;

I: Integer;

GInitData: TWSAData;

begin

WSAStartup($101, GInitData);

Result := TstringList.Create;

Result.Clear;

GetHostName(Buffer, SizeOf(Buffer));

phe := GetHostByName(buffer);

if phe = nil then Exit;

pPtr := PaPInAddr(phe^.h_addr_list);

I := 0;

while pPtr^[i] nil do

begin

Result.Add(inet_ntoa(pptr^[i]^));

Inc(I);

end;

WSACleanup;

end;

Conclusion

Here is an example usage of the above function:

procedure TForm1.Button1Click(Sender: TObject);

begin

Memo1.Lines := GetIps;

end;

You now know a very simple yet affective function on how to get and read the users current IP address using Delphi code.

Printing With Richedit

James V. Bacus <bacuslab@mcs.net>

I have written a program that collects information that a user selects, by
a number of checkboxes and buttons, to a non visible RichEdit box.  The
program was written under Windows 95 and works fine.  But under NT 4.0 the
line ...

RichEdit1.Print(''); 

returns a Divide by Zero Error.  The only way I have found round this is to
save the file and use Word to print the final file.

Does anyone have or know of any workrounds?

Yes, I have a solution and a fix...
To fix this problem requires a minor change to the VCL unit ComCtrls.pas.

I've tested this on many different systems running NT 4.0 and Win95, and all seems to work well now. It's actually a very simple fix, and here it is...

--------------------------------------------------------------------------------

{
A compatibility problem exists with the original RichEdit.Print method
code and the release of NT 4.0.  A EDivByZero exception is caused because
accessing the Printer.Handle property outside of a BeginDoc/EndDoc block
returns an Information Context (IC) handle under NT 4.0 instead of a
Device Context (DC) handle.  The EM_FORMATRANGE attempts to use this IC
instead of a real printer DC, which causes the exception.  If the Handle
property is accessed AFTER the BeginDoc, a true Device Context handle is
returned, and I have modified the code to handle this correctly.  I have
left the original position of BeginDoc in the code but remarked it out to
indicate the difference.    J.V.Bacus 11/12/96
}
procedure TCustomRichEdit.Print(const Caption: string);
var
  Range: TFormatRange;
  LastChar, MaxLen, LogX, LogY: Integer;
begin
  FillChar(Range, SizeOf(TFormatRange), 0);
  with Printer, Range do
  begin
    LogX := GetDeviceCaps(Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(Handle, LOGPIXELSY);
    // The repositioned BeginDoc to now be compatible with
    // both NT 4.0 and Win95
    BeginDoc;
    hdc := Handle;
    hdcTarget := hdc;
    if IsRectEmpty(PageRect) then
    begin
      rc.right := PageWidth * 1440 div LogX;
      rc.bottom := PageHeight * 1440 div LogY;
    end
    else begin
      rc.left := PageRect.Left * 1440 div LogX;
      rc.top := PageRect.Top * 1440 div LogY;
      rc.right := PageRect.Right * 1440 div LogX;
      rc.bottom := PageRect.Bottom * 1440 div LogY;
    end;
    rcPage := rc;
    Title := Caption;
    // The original position of BeginDoc
    { BeginDoc; }
    LastChar := 0;
    MaxLen := GetTextLen;
    chrg.cpMax := -1;
    repeat
      chrg.cpMin := LastChar;
      LastChar := SendMessage(Self.Handle, EM_FORMATRANGE, 1, Longint(@Range));
      if (LastChar < MaxLen) and (LastChar <> -1) then NewPage;
    until (LastChar >= MaxLen) or (LastChar = -1);
    EndDoc;
  end;
  SendMessage(Handle, EM_FORMATRANGE, 0, 0);
end;
Follow

Get every new post delivered to your Inbox.