This is how you get the current day of the week in a string format in csharp. Example... Monday, Tuesday, etc.....
string dayoftheweek = DateTime.Today.DayOfWeek.ToString();
Monday, October 20, 2008
Friday, October 10, 2008
Adding a menu item to SOL.exe - Solitaire
If using Visual Studio 2005, go ahead and create a project via....
Visual C++, Win32, Win32 Project
and let visual studio plug in all that code for you.
Plug in the function below, in which you probably need to create a prototype for and call it from somewhere in the program.
Note: That this blog chops of source code into the other line. Make sure to adjust accordingly...
void insertMenu(void)
{
HWND hWnd = FindWindow(_T("Solitaire"),_T("Solitaire"));
//getting a handle what that find window returns.
//I'm passing the Window Name and the Class Name of
//Solitaire
if(hWnd == NULL)
//checking if I did not receive a handle to SOL.
{
MessageBox(NULL, _T("Error getting handle to SOL"), _T("Error"), NULL);
exit (1);
}
HMENU hMenu = GetMenu(hWnd);
//Getting a handle to Sol Menu
HMENU hNewMenu = CreateMenu();
//Create an instance of a new menu item
AppendMenu(hMenu, MF_STRING MF_POPUP, (UINT_PTR)hNewMenu, _T("My Sol &Hack"));
//Append the main menu bar
AppendMenu(hNewMenu, MF_STRING, IDTEST, _T("&Test"));
//Append the submenu
DrawMenuBar(hWnd);
// Drawing the menu bar
}
Visual C++, Win32, Win32 Project
and let visual studio plug in all that code for you.
Plug in the function below, in which you probably need to create a prototype for and call it from somewhere in the program.
Note: That this blog chops of source code into the other line. Make sure to adjust accordingly...
void insertMenu(void)
{
HWND hWnd = FindWindow(_T("Solitaire"),_T("Solitaire"));
//getting a handle what that find window returns.
//I'm passing the Window Name and the Class Name of
//Solitaire
if(hWnd == NULL)
//checking if I did not receive a handle to SOL.
{
MessageBox(NULL, _T("Error getting handle to SOL"), _T("Error"), NULL);
exit (1);
}
HMENU hMenu = GetMenu(hWnd);
//Getting a handle to Sol Menu
HMENU hNewMenu = CreateMenu();
//Create an instance of a new menu item
AppendMenu(hMenu, MF_STRING MF_POPUP, (UINT_PTR)hNewMenu, _T("My Sol &Hack"));
//Append the main menu bar
AppendMenu(hNewMenu, MF_STRING, IDTEST, _T("&Test"));
//Append the submenu
DrawMenuBar(hWnd);
// Drawing the menu bar
}
You will also need to create a string reference to IDTEST, so that the compiler understands it.....
Convert normal string to LPCWSTR - Visual C++
Whenever you need to convert a normal string into a LPCWSTR (most likely to pass it into an Windows API function), use the _T function.
Check out this madness...
MessageBox(_T("test"), _T("test"));
Check out this madness...
MessageBox(_T("test"), _T("test"));
Sunday, September 28, 2008
Creating a C++ DLL in Visual Studio 2005
It's real freaking easy...
1-File,New,Project,Select Visual C++, and Select Win32 Project. Give it a name. Click OK.
2-It will take you to a new screen. Click on Application Settings, and select the DLL
radio button. Click on Finish.
Paste the following code....
int _stdcall addTwoNumbers(int x, int y)
{
// _stdcall is the calling convention is used to call Win32 API functions.
return (x+y);
}
3-Now let's make sure we export this function, so other applications can use it. We export it as a symbol(don't worry about this fancy word symbol for now). As you can see this function simply just receives 2 values and then returns their sum. We export it by creating a .def file. Right-click on your project and select add, new item. Give it a name and click OK.
4-Paste the following code below the LIBRARY line...
EXPORTS
addTwoNumbers @1
5-Rebuild the solution.
6-Create a simple vb.net console application, just compile it's skeleton for now.Copy the dll you created to the bin\Debug of the vb.net project you just created.Paste the following code. Make sure to replace.. dll2forScreenShots.dll with the name of your dll.
Private Declare Function addTwoNumbers _
Lib "dll2forScreenShots.dll" _
(ByVal x As Integer, ByVal y As Integer) _
As Integer
Sub Main()
Console.WriteLine(addTwoNumbers(9, 7))
'should display 16
Console.ReadLine()
End Sub
7-Compile and run, and you should have the number 16 displaying.
1-File,New,Project,Select Visual C++, and Select Win32 Project. Give it a name. Click OK.
2-It will take you to a new screen. Click on Application Settings, and select the DLL
radio button. Click on Finish.
Paste the following code....
int _stdcall addTwoNumbers(int x, int y)
{
// _stdcall is the calling convention is used to call Win32 API functions.
return (x+y);
}
3-Now let's make sure we export this function, so other applications can use it. We export it as a symbol(don't worry about this fancy word symbol for now). As you can see this function simply just receives 2 values and then returns their sum. We export it by creating a .def file. Right-click on your project and select add, new item. Give it a name and click OK.
4-Paste the following code below the LIBRARY line...
EXPORTS
addTwoNumbers @1
5-Rebuild the solution.
6-Create a simple vb.net console application, just compile it's skeleton for now.Copy the dll you created to the bin\Debug of the vb.net project you just created.Paste the following code. Make sure to replace.. dll2forScreenShots.dll with the name of your dll.
Private Declare Function addTwoNumbers _
Lib "dll2forScreenShots.dll" _
(ByVal x As Integer, ByVal y As Integer) _
As Integer
Sub Main()
Console.WriteLine(addTwoNumbers(9, 7))
'should display 16
Console.ReadLine()
End Sub
7-Compile and run, and you should have the number 16 displaying.
Tuesday, September 23, 2008
Iterating through a string
'String.GetEnumerator Method
'Retrieves an object that can iterate
'through the individual characters in the string
Dim mystring As String = "Madness123"
Dim myCharEnumerator As CharEnumerator
myCharEnumerator = mystring.GetEnumerator()
While myCharEnumerator.MoveNext
Console.WriteLine(myCharEnumerator.Current.ToString())
End While
'Will display...
'M
'a
'd
'n
'e
's
's
'1
'2
'3
Console.ReadLine()
'Retrieves an object that can iterate
'through the individual characters in the string
Dim mystring As String = "Madness123"
Dim myCharEnumerator As CharEnumerator
myCharEnumerator = mystring.GetEnumerator()
While myCharEnumerator.MoveNext
Console.WriteLine(myCharEnumerator.Current.ToString())
End While
'Will display...
'M
'a
'd
'n
'e
's
's
'1
'2
'3
Console.ReadLine()
Tuesday, September 16, 2008
RadioButtonList
'When you want to make sure that they select something from a group
'of radiobuttons, use a radionbuttonlist, and check the selectedindex.
'Add the radio buttons to the items collections.
If (RadioButtonList1.SelectedIndex <= -1) Then
Response.Write("Please select something")
Else
Response.Write("You have selected: " + RadioButtonList1.SelectedItem.Text)
End If
'of radiobuttons, use a radionbuttonlist, and check the selectedindex.
'Add the radio buttons to the items collections.
If (RadioButtonList1.SelectedIndex <= -1) Then
Response.Write("Please select something")
Else
Response.Write("You have selected: " + RadioButtonList1.SelectedItem.Text)
End If
Friday, September 12, 2008
Reading a text file stream asp.net
'You must first select a file with the browse button
'before you can run the code below.
Dim TempFile As String = System.IO.Path.GetTempFileName()
'Creates a uniquely named, zero-byte temporary file on
'disk and returns the full path of that file.
'This method creates a temporary file with a .TMP file extension.
File1.PostedFile.SaveAs(TempFile)
'File1 is my html input file object after using the browse
'button and selecting a file.
Dim TextSTR As String
TextSTR = My.Computer.FileSystem.ReadAllText(TempFile)
'My.Computer.FileSystem.ReadAllText returns the
'contents of a text file as a String
Response.Write(TextSTR)
System.IO.File.Delete(TempFile)
'Deletes the file
'before you can run the code below.
Dim TempFile As String = System.IO.Path.GetTempFileName()
'Creates a uniquely named, zero-byte temporary file on
'disk and returns the full path of that file.
'This method creates a temporary file with a .TMP file extension.
File1.PostedFile.SaveAs(TempFile)
'File1 is my html input file object after using the browse
'button and selecting a file.
Dim TextSTR As String
TextSTR = My.Computer.FileSystem.ReadAllText(TempFile)
'My.Computer.FileSystem.ReadAllText returns the
'contents of a text file as a String
Response.Write(TextSTR)
System.IO.File.Delete(TempFile)
'Deletes the file
Subscribe to:
Posts (Atom)