Advertisement
2_2002-2004 Windows API Call/ Explanation #117255

WinKill

WinKill destroys a window if you know its title bar caption.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
'*************************************************************************
'WinKill Form Code
'*************************************************************************
Private Function Kill(hWnd&) 
 Dim Res& ' Ask it politely to close
 Res = SendMessageA(hWnd, WM_CLOSE, 0, 0)
 ' Kill it (just in case)
 Res = SendMessageA(hWnd, WM_DESTROY, 0, 0)
End Function
Private Sub cmdKill_Click()
 Dim hWnd& ' Get the window handle
 hWnd = FindWindowA(vbNullString, txtName.Text) ' Call the kill function
 Kill (hWnd)
End Sub
Well, We are going to look into Sequential access files and how to make and use them with a C++ program. Its not so hard... below I have fully commented code that will tell you step by step what each thing does. As while this is beginner, you should atleast know a few things like loops and variables before doing this. THe first one is the complete source to a program, the second bit is a commented snippet to companion the first. Please rate me even if a bad rating:
<font color="blue">#include</font> <iostream.h><iostream.h><br>
<font color="blue">#include</font> <fstream.h><font color="#339900"> //Has 
the info for opening the file, and input/output </font><br>
<font color="blue">int</font> main() <br>
{ 
<pre><font color="#339900">	//declare variable</font> 
	float number; 
<font color="#339900">	//open file </font>
	ofstream Out_File;<font color="#0000FF"> <font color="#339900">//associates it(object (Out_File) with this class, used to ouput info to a file </font></font>
	Out_File.open("datafile.dat", ios::app);<font color="#339900">//commented on heavily at end </font>
<font color="#339900">	//Check for open</font> 
<font color="#0000FF">	if</font> (!Out_File.fail()) <font color="#339900">//checks to make sure it DIDNT fail (! operator) </font>
	{ 
<font color="#339900">		//input names and write to file </font>
		cout << "Please enter a number(enter a negative to exit): "; 
		cin >> number; 
<font color="#0000FF">		while</font> (number >= 0) <font color="#339900">//loops to check for a negative number </font>
		{
		Out_File << number << endl; <font color="#339900">//adds the line to the data file you opened. </font>
		cout << "Please enter a number(enter a negative to exit): "; 
		cin >> number; 
		}<font color="#339900">//end while </font>
<font color="#339900">		//close the file</font> 
		Out_File.close(); 
	} 
<font color="#0000FF">	else</font> <font color="#339900">//incase it didnt open for any reason.... </font>
	cout << "Sorry, error opening file... " << endl; 
<font color="#339900">	//end if </font>
}<font color="#339900">//end main function(close program, no other prototypes) </font>
 
 </pre>
<pre>	<font color="#339900">/* Now, the 'Out_File.open("datafile.dat", ios::app)'works like so. The open part is 
	fairly obvious, it opens the Object Out_file. The first part, "datafile.dat" is the
	filename you wish to open, or create(incase it doesnt exist).the second is the type 
	of I/O you want, they follow the 'ios::' command and are as follows:
 
	ios::in Opens file for input into the program, Default mode for input files(will talk about later)
	ios::app Opens file for 'append', If the file doesnt exist it will create a new one, but if it 
	does it will actually just continue writing to it with whatever you had on there before still on 
 
	ios::out Opes a file for output to it, creates a new one, or deletes all the info in an old one so
	that it it starts of new. Very different then the append....
 
	on a side note: Out_File << number << endl; the endl actually makes a newline
 on the data file so that the data is on different lines and can be differentiated.
 
	Hopes this helps :) */</font>
 </pre>
<pre> 
 
	Now... the code for the input of info from the file to the program is as follows...
	This is just a snippet and lacks header files, variable declaration, and main function call as you have seen all that in the last bit:
 
 <font color="#339900">//open file for for input</font>
 ifstream input_file;
 input_file.open("datafile.dat", ios::in); <font color="#339900">//make sure open was successful(more important in this one then the last)</font>
 <font color="#0000FF">if </font>( !input_file.fail() )
 {
		<font color="#339900">//read from file</font>
 		input_file >> score; 
		<font color="#0000FF">while</font> ( !input_file.eof() )
 		{
 		<font color="#339900">	//increment counter and average</font>
 			index++;<font color="#339900"> //same as index = index + 1, shortens it </font>
 			totalscore += score;<font color="#339900"> //same as totalscore = totalscore + score, shortens it </font>
 			input_file >> score; <font color="#339900">//takes from file into the program.</font>
 		}<font color="#339900">//end while loop
 		
		//close input_file</font>
 		input_file.close();
 <font color="#339900">		
		//display average</font>
 		average = (float) totalscore / (float) index; 
 		cout << "The average of the numbers you entered was " << average << endl;
 }
 <font color="#0000FF">else</font><font color="#339900"> //failed to open...</font>
 		cout << "cant open file";
 <font color="#339900">//end if</font>
 
 
 <font color="#339900">/* Pretty straight forward, we used to ifstream (input file) instead of ofstream this time,
	and it is to be noted that you dont have to assign it a value to read from as an array, since
	it does it in order. One by one. Hopes this helps to! */
 
 </font>
<UL>
<LI><FONT face=Verdana>1. Introduction<BR></FONT>
<LI><FONT face=Verdana>2. MySQL/PHPMyAdmin Introduction<BR></FONT>
<UL>
<LI><FONT face=Verdana>i - What is a database?<BR></FONT>
<LI><FONT face=Verdana>ii - Relational?<BR></FONT>
<LI><FONT face=Verdana>iii - Table Schematics<BR></FONT>
<LI><FONT face=Verdana>iv - Creating your MySQL table with appropriate datatypes</FONT></LI></UL>
<LI><FONT face=Verdana>3. Query By Example (QBE) and Basic SQL Statements<BR></FONT>
<UL>
<LI><FONT face=Verdana>i - SELECT, WHERE, ORDER BY<BR></FONT>
<LI><FONT face=Verdana>ii - Working Code Examples<BR></FONT>
<LI><FONT face=Verdana>iii - QBE</FONT></LI></UL>
<LI><FONT face=Verdana>4. The Role of PHP4<BR></FONT>
<UL>
<LI><FONT face=Verdana>i - Performing a simply query using mysql_fetch_array()<BR></FONT>
<LI><FONT face=Verdana>ii - phpMyAdmin - The secret weapon in internet db design ;)<BR></FONT>
<LI><FONT face=Verdana>iii - Useful links for PHP and MySQL</FONT></LI></UL>
<LI><FONT face=Verdana>5. Greets/Bibliography<BR></FONT></LI></UL><CONT><BR><BR><FONT face=Verdana><B>Introduction:</B><BR><BR>This article will assume working knowledge of SQL and PHP4 of some kind. I will not<BR>be assuming you've not used PHP4 in the past and simply reading this article in order<BR>to grasp internet databases will not really work in practice.<BR><BR>If you have absolutely no idea of SQL or PHP4, please visit www.php.net and download<BR>their PHP4 manual and download "Teach yourself SQL in 21 days" (search on google...its free ;-)&nbsp; ). After reading both of those you may find you understand this article a lot<BR>better.<BR><BR><B>2 - i - What is a database?</B><BR><BR><BR>The word "database" is one that is used overly in the world of information technology.<BR>Personally, I do not think enough people are aware of what a database actually is. Sure,<BR>many many people I know are excellent C coders, they can effectively use UNIX and Linux,<BR>perform all kinds of exploits on various systems yet... cannot administer a simple<BR>database. This I find very strange.<BR><BR>We can define a database as a collection of data stored in some structural way<BR>which can be "groped" in order to extract information from it.<BR><BR>Databases are used and accessed every day. For those of you who are not too confident<BR>with databases, Yahoo! is one huge database of links... and this is the same for all<BR>directory search engines. Meta searches are something completely different and not<BR>to be confused and not something I will divulge into due to the constraints of this<BR>article.<BR><BR><BR><B>2 - ii - Relational?</B><BR><BR><BR>One database server can have many databases to serve, of which those databases can have<BR>many fields, those fields can have many attributes.<BR><BR>In order for me to explain how a relational database works, take a look at the previous<BR>paragraph. We can see that a database server and a singular database would have what<BR>we would refer to as a "One to Many" relationship. There can be "one" database server<BR>to "many" databases to be served. If this is still unclear, bare with me.<BR><BR>Consider the following two tables, which I will use for the purposes of this paper<BR>and is in fact a database I am currently constructing.<BR><BR>We shall go through the various stages of building a links database to serve to the<BR>public via the web.<BR></FONT><PRE><BR>
<BR>
<FONT face=Verdana>links    sectionname<BR>
<BR>
linkid    section  <BR>
url<BR>
description<BR>
sectionid  &lt;---------------------------------- sectionid<BR>
</FONT></PRE><BR><BR><FONT face=Verdana>Above we can see two tables, 'links' and 'sectionname'. First of all, let us define<BR>the content which shall be held in the two named tables.<BR><BR>The links table shall hold the main data. Every link shall be entered into this table<BR>manually via using phpMyAdmin or 'hand entered' via a shell or command prompt (win32).<BR><BR>There are four fields present in links: linkid, url, description and sectionid.<BR>There are only two fields present in sectionname: section and sectionid.<BR><BR>sectionid is an identical field to the sectionid field which was held in the previous table.<BR>The sectionid here would also directly relate to section field in row order. We can assume<BR>the following record layout within the sectionname table:<BR><BR><BR><B>2. iii - Table Schematics</B><BR><BR></FONT><PRE><FONT face=Verdana> ____________________________<BR>
|section     | sectionid |<BR>
|-----------------------------|<BR>
|Security     | 1     |<BR>
|Fun Links    | 2     |<BR>
|Misc Stuff    | 3     |<BR>
_______________________________</FONT></PRE><BR><BR><BR><FONT face=Verdana>Above we see the table schematics for the sectionname table. We see security has an id of<BR>1, fun links has an id of 2 and finally misc stuff has an id of 3. Each one of these is<BR>going to be related to many many records in the links table. So, if we look at both tables<BR>in turn:<BR><BR>Links and Sectionname<BR><BR>we can understand that the relationship between the links table the sectionname table is<BR>said to be "many to one", as mentioned. There is MANY links to ONE section.<BR><BR>By understanding this basic database concept, we can start to grasp the fundamentals<BR>concerned with database design and relational web development.<BR><BR>note: when entering data manually into the links table, the sectionid<BR><BR><BR><B>2. iv - Creating your MySQL table with appropriate datatypes</B><BR><BR><BR>Those of you who have programmed before, will be more than adapted to datatypes.<BR>SQL is like C, in that it requires each field (or variable in C) to be given a datatype.<BR>This is where the SQL and PHP4 programming language differs from most other programming<BR>languages, it does not require variables to be given a signed data type.<BR>For instance $foo = 1.523 will be automatically assigned a doublevar by PHP (float in C).<BR>However datatypes can be forced upon variables in PHP if the need arises.<BR><BR>So, this section is going to be written as if the user was at a mysql&gt; prompt. I'm writing<BR>this way because administering a MySQL database from phpMyAdmin is extremely simple.<BR>Ok so here goes. The create table function is used then the fields to be used, table<BR>name and datatypes for fields shall be passed to the create table function as arguements<BR>in order to setup the table. Here we go:<BR><BR>mysql&gt; CREATE TABLE links (<BR><BR>linkid BIGINT(20) not null AUTO_INCREMENT,<BR>url TINYTEXT not null, <BR>description LONGTEXT not null,<BR>PRIMARY KEY (linkid));<BR><BR><BR>Above we can see the SQL used to create a table with the name of links, and add 4 very<BR>important fields to this table.<BR><BR>Firstly we notice:<BR><BR>linkid BIGINT(20) not null AUTO_INCREMENT,<BR><BR>This is to set the linkid field which is going to be used for the primary key,<BR>I'll mention why later. The bigint datatype of size 20 has been set to linkid with<BR>the AUTO_INCREMENT tag on it. This means that whenever entering data into the database,<BR>there is no need to add any data into the linkid field. It will simply be incremented by<BR>1, for instance (linkid++ for you C programmers) everytime a new record is added to<BR>the database. We've assigned bigint because it can handle extrememly large numbers.<BR>Of course one wouldn't expect there to be more than 12,000 links in<BR>a database. If you're creating databases so large, you seriously shouldn't be<BR>reading this article. The NOT NULL flag has been added to this field, and many others.<BR>NOT NULL means simply what it says, this field cannot be left<BR>with a NULL entry, meaning that something must be entered into that field in order for<BR>the record to be added<BR>to the database table.<BR><BR><BR>Secondly we can notice the remanining two fields:<BR><BR>url TINYTEXT not null, <BR>description LONGTEXT not null,<BR><BR><BR>The field 'url' and 'description' have been assigned TINYTEXT and LONGTEXT datatypes.<BR>We wouldn't expect a mass amount of data to be entered into url where as we would<BR>expect a fair amount of data to be placed into description. For example the description<BR>for an url could be:<BR><BR><BR>"This is a really really cool site. It has loads of stuff on it blah blah blah" and<BR>this kinda' thing could go on for maybe 500 or more chars which exceeds the TINYTEXT<BR>length boundaries. LONGTEXT would suffice this kind of data entry and therefore is a<BR>much better data type to assign.<BR><BR><BR>Lastly we can notice:<BR><BR>PRIMARY KEY (linkid));<BR><BR>This is the final statement in the SQL code which assigns a valid primary key to the<BR>table based on one of the previous fields that have been defined in the CREATE TABLE()<BR>function. As mentioned, the primary key is a unique way of identifying records within a<BR>database with the means to not have duplicate data.<BR><BR>Note: if you're wondering where there's 2 closing brackets (parantheses), the trailing )<BR>comes to close the CREATE TABLE() funtion. The semi-colon ; is the character used to<BR>terminate any SQL statement to a database server.<BR><BR><BR><B>3. i - SELECT, WHERE, ORDER BY</B><BR><BR>We must consider what commands we're going to use in order to select which data we<BR>want from the database, on what condition we want this data to be included in the<BR>results of our query and lastly... how we want the data to be returned and sorted<BR>in the query.<BR><BR>We can simply answer all three of these questions by looking at three commands<BR><BR>SELECT: This is used in order to manually SELECT what fields we want to display<BR><BR>WHERE: This is used as a condition statement with SELECT to take records from<BR><BR>fields within the SELECT section which match the results of the WHERE<BR>assignment.<BR><BR>ORDER BY: We use ORDER BY to sort the data, usually by field in ascending or descending<BR>order.<BR><BR><BR><B>3. ii - Working Code Examples</B><BR><BR><BR>SELECT:<BR><BR>mysql&gt; SELECT * FROM SECTIONNAME;<BR><BR>The following basic SELECT statement uses a * (wildcard) in order to select all fields<BR>from the table name in the format SELECT [fields_to_be_selected] FROM<BR>[the_table_you_want_to_select_fields_from];<BR><BR><BR>security 1<BR>fun stuff 2<BR>misc links 3<BR><BR><BR>WHERE and ORDER BY:<BR><BR>Well, supposing we only wanted to select all urls from the links table which were to do<BR>with security? By using relational database development and linking the two tables,<BR>as shown earlier, it's very easy to use WHERE statement as follows:<BR><BR>mysql&gt; SELECT * FROM links<BR>WHERE sectionid = 1<BR>ORDER BY url;<BR><BR>Above, we can see how we have selected all fields from the links table but we've added a<BR>condition to which records we want outputting in our query. We have effectively used<BR>the WHERE statement to show that the only records we want outputting in our query are<BR>the ones that have a sectionid of 1. If we go back and look at the sectionname table as<BR>shown:<BR><BR></FONT><PRE><FONT face=Verdana> ____________________________<BR>
|section     | sectionid |<BR>
|-----------------------------|<BR>
|Security     | 1     |<BR>
|Fun Links    | 2     |<BR>
|Misc Stuff    | 3     |<BR>
_______________________________</FONT></PRE><BR><BR><FONT face=Verdana>we can see that the record with a sectionid of 1 is security. All links concerned with<BR>security would have been previously entered with a '1' in the sectionid field on the<BR>links table. The database would not know this otherwise.<BR><BR>The ORDER BY statement used in this way would output the query and sort ascending on<BR>the 'url' field.<BR><BR><BR><B>3. iii - QBE (Query By Example)</B><BR><BR><BR>QBE is a function that can be used with a web application called phpMyAdmin.<BR>It's an extremely quick way of performing a query on a database by giving the GUI<BR>an example of what you'd like to search for, how you want to search for it and how<BR>you want the results displaying. This will be discussed briefly in the next<BR>chapter.<BR><BR><BR><B>4. The Role of PHP4</B><BR><BR><B>i - Performing a simply query using mysql_fetch_array()</B><BR><BR><BR><BR>This code is HEAVILY commented, basically I've went on writing the article while<BR>coding at the same time it maybe advisable to take out the comments to leave just<BR>the source code and save as query.php or something then have another code<BR>version with comments, whichever you decide ;)<BR><BR><BR>//removethesecomments<?php<br /> <BR>//PHP4 Query on MySQL Database<BR><BR><BR>//Variables to open database socket/connection with<BR><BR>$user = "username";<BR>$pass = "password";<BR>$db = "database_name";<BR><BR>//Database Socket<BR>$socket = mysql_connect('localhost', $user, $pass);<BR>if ( ! $socket)<BR>die ("Could not connect to MySql Server");<BR><BR>//Database selection function, with previous 2 variables passed as args to function<BR>mysql_select_db($db, $socket)<BR>or die ("Could not connect to database: $db".mysql_error() );<BR><BR>//The use of the "or die" statement is the error message that will be returned if the<BR>//socket or database name is null<BR>//The error code will also be returned for fault finding with the mysql_error() function<BR><BR><BR>//This is the query that is being sent to the mysql database and is returned to the<BR>//variable $result<BR>//This is a static query and is not suitable for a search engine, as only one specific<BR>//query can be sent not the results of a text box on a php form etc.<BR><BR>$result = mysql_query("SELECT * FROM LINKS");<BR><BR>//We can easily assign the results of mysql_num_rows to return the amount of results<BR>//found by the<BR>//query and assign it to a differntly named variable $num_rows and pass the $result<BR>//var which holds<BR>//our query to it as arguements<BR><BR><BR>$num_rows = mysql_num_rows($result);<BR><BR>//notice how a simple table structure has been used to store the output of the query<BR>//on the database :)<BR><BR>echo "&lt;table = \"100%\"&gt;";<BR><BR><BR>//The $rows variable holds the array contents and "steps through the array" row by row<BR><BR>while ($rows = mysql_fetch_array($result))<BR>{ <BR>echo "&lt;tr&gt;";<BR>echo "&lt;td&gt;";<BR>echo "$rows[linkid]";<BR>echo "&lt;/td&gt;";<BR>echo "&lt;td&gt;";<BR>echo "&lt;a href=\"$rows[url\"&gt;$rows[url]&lt;/a&gt;";<BR>echo "&lt;/td&gt;&lt;td&gt;";<BR>echo "$rows[description]";<BR>echo "&lt;/td&gt;";<BR>echo "&lt;/tr&gt;";<BR>}<BR><BR>echo "&lt;/table&gt;";<BR><BR>//Here we use our previously declared $num_rows variable in order to find the number of<BR>//returned results<BR><BR>echo "&lt;small&gt;Your query on database $db returned $num_rows result(s)&lt;/small&gt;";<BR><BR>//Above we can see we used the function mysql_fetch_array(). This returns the<BR>//contents of the query in an array and therefore we would access such results as we<BR>//would any normal array. We could return them as objects or even<BR>//by using mysql_fetch_rows() but that isn't deemed as the more modern way to use<BR>//PHP4 and was used a lot more in the PHP3 days. <BR><BR>//removethesecomments?&gt;<BR><B>4. ii - phpMyAdmin : The secret weapon in internet db design ;)</B><BR><BR>phpMyAdmin is an excellent program which can be used for the administration of small or<BR>large MySQL databases. It is a complete web interface developed with php4 and allows<BR>logins to the database on a given host. The latest copy of phpMyAdmin can be<BR>found at http://www.phpwizard.net and deserved a special mention because it is an<BR>excellent tool for beginners who'd like to get into database design. It does however<BR>look very much like MS Access but, oh well ;)<BR><BR><BR><B>4.iii - Useful links for PHP and MySQL</B><BR><BR>http://www.php.net Official PHP website<BR>http://www.mysql.org Official MySQL website<BR>http://www.phpwizard.net Developers of phpMyAdmin<BR>http://www.zend.com Home of Zend Engine<BR><BR>Recommended Books:<BR><BR>Teach Yourself PHP4 in 24 Hours<BR>PHP4 Bible<BR>MySQL and PHP From Scratch<BR>Web Application Development with PHP<BR>O'Reilly's MySQL and mSQL<BR><BR>Check those books out at: http://www.amazon.com<BR><BR><BR><B>5. Greets/Biliography</B><BR><BR>Nothing I referred to was more than maybe 1 or 2 lines of information and wasn't copied,<BR>so I dont think anyone else or any other piece of information or website deserves<BR>recognition for this paper.</FONT>
Upload
Original Comments (3)
Recovered from Wayback Machine