Expanding This Forum...(Programmers Unite) - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming > Programming Tips and FAQ
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 04-02-2003, 10:13 PM   #1 (permalink)
Newb Techie
 
Join Date: Apr 2003
Posts: 11
Lightbulb Expanding This Forum...(Programmers Unite)

Let's all post some of our favorite code snippets for any language we choose. Be sure to label what it does and add any extra info that would be required. I'll start...

Language: Visual Basic 6.0
Purpose: Change the Windows Wallpaper


Code:
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _ 
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long As Long

Public Const SPI_SETDESKWALLPAPER = 20

Public Sub ChangePaper(strFilename as string)
   Dim lngSuccess As Long

   lngSuccess = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strFilename, 0)
End Sub

- Please Post...
__________________

__________________
D.Viddy is offline  
Old 04-03-2003, 10:40 AM   #2 (permalink)
Monster Techie
 
Join Date: Nov 2002
Posts: 1,364
Send a message via AIM to shan
Default

PHP
Alternating talbe row colors.
PHP Code:

<?
$usr 
"usr";
$pass "pass";
$db "database";

mysql_connect(localhost,$usr,$pass);
mysql_select_db($db) or die("Unable to locate database becuase: mysqlerror()");

$qry = ("SELECT * FROM table ORDER by id")or die(mysql_error());
$result mysql_query($qry);
$numrows mysql_num_rows($result);

echo 
"<table width='100%' border=1 cellpadding=2 cellspacing=2>\n";
echo 
"<tr><th bgcolor='#FFFFFF'><font color='black'>Something</th>
<th bgcolor='#FFFFFF'><font color='black'>Something else</th>
<th bgcolor='#FFFFFF'><font color='black'>Something different</font></th></tr>\n"
;

$bg "#000000";
for (
$cur 0$cur $numrows$cur++){
if (
$bg == "#000000"){
$bg "#123456";
}else{
$bg "#000000";
}
$row mysql_fetch_array($result);
echo 
"<tr>\n";
echo 
"<td bgcolor='$bg'>".$row['something']."</td>\n";
echo 
"<td bgcolor='$bg'>".$row['somethingelse']."</td>\n";
echo 
"<td bgcolor='$bg'>".$row['somethingdifferent']."</td>\n";
echo 
"</tr>\n";
}

print 
"</table>\n";
mysql_close();
?>
__________________

__________________
<center><h2><font color=\"red\">C:\\ Is the root of all evil</font></h2>
<hr width=\"50%\">
phiber@sysdum.com
spam this account, it's fun.
shan is offline  
Old 04-03-2003, 01:21 PM   #3 (permalink)
the flaming hermit
 
Join Date: Jul 2002
Posts: 950
Send a message via ICQ to þÄ®âÐÖx Send a message via Yahoo to þÄ®âÐÖx
Default

Registry Access
(Visual Basic)

Code:
'This program needs 3 buttons
Const REG_SZ = 1 ' Unicode nul terminated string
Const REG_BINARY = 3 ' Free form binary
Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
    Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
    'retrieve nformation about the key
    lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
    If lResult = 0 Then
        If lValueType = REG_SZ Then
            'Create a buffer
            strBuf = String(lDataBufSize, Chr$(0))
            'retrieve the key's content
            lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
            If lResult = 0 Then
                'Remove the unnecessary chr$(0)'s
                RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
            End If
        ElseIf lValueType = REG_BINARY Then
            Dim strData As Integer
            'retrieve the key's value
            lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
            If lResult = 0 Then
                RegQueryStringValue = strData
            End If
        End If
    End If
End Function
Function GetString(hKey As Long, strPath As String, strValue As String)
    Dim Ret
    'Open the key
    RegOpenKey hKey, strPath, Ret
    'Get the key's content
    GetString = RegQueryStringValue(Ret, strValue)
    'Close the key
    RegCloseKey Ret
End Function
Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Save a string to the key
    RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
    'close the key
    RegCloseKey Ret
End Sub
Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Set the key's value
    RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
    'close the key
    RegCloseKey Ret
End Sub
Sub DelSetting(hKey As Long, strPath As String, strValue As String)
    Dim Ret
    'Create a new key
    RegCreateKey hKey, strPath, Ret
    'Delete the key's value
    RegDeleteValue Ret, strValue
    'close the key
    RegCloseKey Ret
End Sub
Private Sub Command1_Click()
    Dim strString As String
    'Ask for a value
    strString = InputBox("Please enter a value between 0 and 255 to be saved as a binary value in the registry.", App.Title)
    If strString = "" Or Val(strString) > 255 Or Val(strString) < 0 Then
        MsgBox "Invalid value entered ...", vbExclamation + vbOKOnly, App.Title
        Exit Sub
    End If
    'Save the value to the registry
    SaveStringLong HKEY_CURRENT_USER, "KPD-Team", "BinaryValue", CByte(strString)
End Sub
Private Sub Command2_Click()
    'Get a string from the registry
    Ret = GetString(HKEY_CURRENT_USER, "KPD-Team", "BinaryValue")
    If Ret = "" Then MsgBox "No value found !", vbExclamation + vbOKOnly, App.Title: Exit Sub
    MsgBox "The value is " + Ret, vbOKOnly + vbInformation, App.Title
End Sub
Private Sub Command3_Click()
    'Delete the setting from the registry
    DelSetting HKEY_CURRENT_USER, "KPD-Team", "BinaryValue"
    MsgBox "The value was deleted ...", vbInformation + vbOKOnly, App.Title
End Sub
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Command1.Caption = "Set Value"
    Command2.Caption = "Get Value"
    Command3.Caption = "Delete Value"
End Sub
__________________
þÄ®âÐÖx is offline  
Old 04-10-2004, 11:09 PM   #4 (permalink)
Junior Techie
 
Join Date: Mar 2004
Posts: 56
Send a message via AIM to raylu
Default

This code screws up your computer when placed into IE's address bar when JavaScript is enabled deleted...

Please do not post destructive code.

Note: this forum adds spaces between java and script...take thouse out.
__________________
\"Only when the last tree is dead, the last field paved, and the last river dammed, only then will we realize that we can\'t eat money.\"
http://raylu.uni.cc
raylu is offline  
Old 05-04-2004, 10:35 AM   #5 (permalink)
True Techie
 
Join Date: Apr 2004
Posts: 216
Send a message via Yahoo to Fahim
Default

do any of you know aboout the registry editor
__________________
Intel Pentium 4 Hyperthread Buspeed 845 bus speed
512 RAM
3D Graphics
Fahim is offline  
Old 05-04-2004, 12:03 PM   #6 (permalink)
Banned
 
Join Date: May 2003
Posts: 105
Default

See þÄ®âÐÖx's post for the registry edit functions.
__________________
_Jack is offline  
Old 06-16-2006, 02:23 PM   #7 (permalink)
Junior Techie
 
Join Date: Oct 2005
Posts: 72
Default

Javascript
The never ending Prompt Alert

NOTE : You may have to end your explorer window to get rid of this!

Code:
<script language="javascript">
<!--
while (1) {
     alert("AAARRGHHH!!");
}
__________________

__________________
<a href="http://www.flashyflashy.net" target="_blank">flashyflashy.net</a>
darkninja is offline  
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 03:13 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2019, vBulletin Solutions, Inc.