Archive for the ‘Tutorials’ Category
July 20, 2008
This is a simple guide to basic use of Doxygen-compliant commenting of source code. The guide is written from my point - C/C++ - but it’s valid for all supported languages, except of Python. See Doxygen documentation for use for Python. Doxygen is very flexible when it comes to the form of how the documentation is written, the layout presented here is simply my preference.
Read the rest of this entry ?
Posted in C/C++, Computers, Linux, Programming, Tips and Tricks, Troubleshooting, Tutorials, Windows | Tagged Documentation, Doxygen | No Comments »
May 18, 2008
There is no big science to it, but thanks to a “bad choice of title”, the appropriate MSDN-KB-HOWTO article is not easy to find. So, here’s a link:
MSDN KB 126897: How to Change Default Printer Settings in an MFC Application
The above link takes you directly to the code snippet that sets print orientation to landscape; to change the orientation to portrait, you only need to change the DMORIENT_LANDSCAPE to DMORIENT_PORTRAIT; of course, the easiest way is to change the function to allow user to choose the orientation.
Note: The presented code, of course, also changes the orientation of the print preview.
To use the above code, simply surround your printing (or print preview) code with (provided you changed the function to accept bool to choose orientation, and to return previous setting):
CMyApp* app = (CMyApp*) ::AfxGetApp();
bool old_po = app->SetPrintOrientation(*your choice of orientation*);
// printing (or print preview) code comes here
app->SetPrintOrientation(old_po);
Note: So far, I didn’t manage to find a way to change the print orientation for individual pages; seems like you have to print portrait and landscape oriented pages in separate print jobs (?).
Posted in C/C++, Computers, Programming, Tips and Tricks, Troubleshooting, Tutorials, Windows | Tagged MFC, Orientation, Print, Print Preview | No Comments »
May 16, 2008
It’s possible to refer to e.g. My Documents folder on your own computer by the path you know, and it’ll work. But if you want to distribute your program among users, you cannot expect the fixed path to work. E.g. Windows allow you to save user’s profile folders anywhere on the disk you want; it’s not a rule that all are saved under Documents and Settings; e.g. mine are saved under folder called Profiles, since I wanted to preserve the original Documents and Settings from my previous Windows installation. Also, Windows need not to be installed under C:\Windows; mine are under C:\Windows.1.
But, there is a (quite) simple way to find all the necessary system folders in Windows. All you have to do is be a bit careful.
Read the rest of this entry ?
Posted in C/C++, Computers, Programming, Tips and Tricks, Tutorials, Windows | Tagged Registry, Shell, System Folders, Win32 | 2 Comments »
May 4, 2008
This is a simple tutorial on how to create panoramas in Photoshop (in my case version 7, but applies to any Photoshop from version 6 up).
Read the rest of this entry ?
Posted in Panorama, Photography, Photoshop, Tips and Tricks, Tutorials | No Comments »
March 5, 2008
Once you’ve obtained the Win32 archive for NASM, nasmw-inst-xxx.exe (where xxx denotes the version number of NASM contained in the archive), install the NASM into its own directory (for example “C:Program FilesNASM”).
The archive will contain two executable files: the NASM executable files nasmw.exe, and the NDISASM executable files ndisasm.exe and ndisasmw.exe. In each case, the file whose name ends in w is a Win32 executable, designed to run under Windows 95 or Windows NT Intel.
Since 0.95.36, NASM is fully officially compatible with Microsoft Visual Studio 6/2003.NET.
Integration within Microsoft Visual Studio 6
- In Tools/Options/Directories , select “Show directories for:” into “Executable files”. Add a new path “C:Program FilesNASM” (or where you have installed NASM).
- In your project workspace, create a new folder “Assembler Files”.
- On this folder, right click and select “Settings”.
- In General, enable “Always use custom build step”.
- In Custom Build, change the following settings:
Commands:
nasmw.exe -f win32 -Xvc -o “$(IntDir)$(InputName).obj” $(InputDir)$(InputName).asm
Outputs:
“$(IntDir)$(InputName).obj”
Integration within Microsoft Visual 2003.NET
- In Tools/Options/Projects, Select “VC++ Directories” and “Show directories for:” “Executable files” - should be the default. Press Ctrl+Insert or press the “New Line” icon. Select the path “C:Program FilesNASM” (or where you have installed NASM).
- In your project workspace, create a new folder “Assembler Files”.
- On this folder, right click and select “Settings”.
- In General, enable “Always use custom build step”.
- In Custom Build, change the following settings:
Commands:
nasmw.exe -f win32 -Xvc -o “$(IntDir)$(InputName).obj” $(InputDir)$(InputName).asm
Outputs:
“$(IntDir)$(InputName).obj”
Using Inline Assembler in C/C++ Code
.asm file:
[bits 32]
[section .bss align=16]
[section .data align=16]
[section .text align=16]
[global _myFunction]
_myFunction:
push ebp
mov ebp,esp
mov eax, [ebp + 8] ; your code goes here, instead of this line...
pop ebp
ret
END
in .c/.cpp file call the function:
under MSVS:
int cdecl myFunction(int parameter);
under GCC you’d call the function with ‘_’ prefix:
int _myFunction(int parameter);
For more information see NASM Documentation, chapter 8.
Posted in C/C++, Computers, Programming, Tips and Tricks, Tutorials, Windows | Tagged Assembler, NASM, Visual Studio | No Comments »
March 1, 2008
Often you wanna make sure some tables in database exist, but you want to avoid getting the error message “There is already an object named ‘yourtable’ in the database.”, that you would get by simply issuing the CREATE TABLE command.
For these cases, MSSQL offers keyword EXISTS (most SQL engines provide similar facilities; e.g. MySQL C API allows you to directly check for the existance of database and/or table).
All you have to do in MSSQL is make sure the table is not yet registered in the sysobjects table, using the following SQL command:
IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N’[dbo].[tablename]‘)
AND OBJECTPROPERTY(id, N’IsUserTable’) = 1)
CREATE TABLE [dbo].[tablename] ( columns specification );
where “tablename” is name of table you want to create, and “columns specification” is the usual definition of table’s columns. Feel free to extend the table definition to your liking.
Or you might want to DROP the table before re-creating it:
IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N’[dbo].[tablename]‘)
AND OBJECTPROPERTY(id, N’IsUserTable’) = 1)
DROP TABLE [dbo].[tablename];
CREATE TABLE [dbo].[tablename] ( columns specification );
Yes, that’s all. Good luck!
Posted in C/C++, Computers, Linux, Programming, SQL, Tips and Tricks, Troubleshooting, Tutorials, Windows | Tagged MSSQL, Microsoft SQL Server, SQL, Create Table | No Comments »
March 1, 2008
Windows provide means for a more precise time measurement than just the standard C-function clock().
The basic definitions and declarations are as follows (typedef is for readability):
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
typedef LARGE_INTEGER timeStamp;
void getCurrentTimeStamp(timeStamp& _time);
timeStamp getCurrentTimeStamp();
double getTimeMili(const timeStamp& start, const timeStamp& end);
double getTimeSecs(const timeStamp& start, const timeStamp& end);
Notes:
* LARGE_INTEGER is 8B big, so it’s faster to use reference than direct copy, but this may vary compiler to compiler - test before using!
* Value stored in LARGE_INTEGER variable is by itself useless - it’s something of the sort “number of ticks since the computer booted”; but two of them define interval with quite a useable resolution. (check MSDN for more info)
Usage is trivial - to measure intervals, simply use one of getCurrentTimeStamp() functions to get current “timestamp” of beginning and end of interval, and then use getTimeMili() go get interval’s length in miliseconds, or getTimeSecs() for length in seconds.
Implementation pretty much just uses what’s readily available (both versions of getCurrentTimeStamp() are obvious candidates for inline’s):
void getCurrentTimeStamp(timeStamp& _time)
{
QueryPerformanceCounter(&_time);
}
timeStamp getCurrentTimeStamp()
{
timeStamp tmp;
QueryPerformanceCounter(&tmp);
return tmp;
}
double getTimeMili(const timeStamp& start, const timeStamp& end)
{
timeStamp dwFreq;
QueryPerformanceFrequency(&dwFreq);
return double(end.QuadPart - start.QuadPart) /
double(dwFreq.QuadPart) * 1000;
}
double getTimeSecs(const timeStamp& start, const timeStamp& end)
{
timeStamp dwFreq;
QueryPerformanceFrequency(&dwFreq);
return double(end.QuadPart - start.QuadPart) / double(dwFreq.QuadPart);
}
Note:
* The QueryPerformanceFrequency(&dwFreq); in getTimeMili() returns the same value on each call - storing this value at the start of the program might be a good idea. (most probably - on multiprocessor computers this might be false!)
Posted in C/C++, Computers, Programming, Tips and Tricks, Tutorials, Windows | Tagged Time Measurement | 2 Comments »
February 28, 2008
LaTeX, or more generally TeX, is undoubtly the best typesetting tool available, and what’s more, it’s for free (for Windows users - check out MiKTeX!). Yet, there are few things that should work in a certain “obvious” way, yet they don’t (fortunately, there’s very few of them).
One of them is quite a surprising thing - pagestyle{empty} command does not affect first page of the table of contents. Yet, all the other pages of ToC it does! The same holds for list of figures and list of tables.
This is quite an annoyance, especially if you put ToC at the beginning of the document, and want to have all the pages, before the real contents starts, without the page numbering.
So, how to get rid of the page number on the first page of table of contents in LaTeX? You have to dig into the header and footer setting for this.
First thing is to use fancyhdr package - put usepackage{fancyhdr} command anywhere before the begin{document}.
Second, right before issuing the tableofcontents command, redefine the “plain page style” to an empty one, like this:
fancypagestyle{plain}
{
fancyhead{}
fancyfoot{}
} % clear header and footer of plain page because of ToC
And after the ToC, just get back to the “classical” plain page style (this is important - even if you use your “fancy” page style, each page containing first page of chapter is “plain”, unless you redefine this behaviour), like this:
fancypagestyle{plain}
{
fancyhead{}
fancyfoot[C]{thepage}
} % re-define plain page after the ToC
This block has to be “on a new page” - either after you issue newpage or cleardoublepage command, or after your first chapter{…} command.
Posted in Books, Computers, Linux, Programming, Tips and Tricks, Troubleshooting, Tutorials, Windows | Tagged LaTeX, Page Numbering, Table of Contents, TeX, ToC, Typesetting | 4 Comments »
February 11, 2008
Restricting to localhost Access Only
To restrict access globally, all you have to do is to restrict access in httpd.conf in Apache’s conf directory.
First, locate the Directory settings for your htdocs directory (under Windows it’s e.g. C:/Apache2/htdocs, C:/Program Files/xampp/htdocs, etc., under Linux it’s e.g. /usr/htdocs, /usr/local/htdocs, /usr/local/www/htdocs, /usr/share/htdocs, etc.).
Then, you have to edit the Order subsection as follows (comments left out for readability):
<Directory "htdocs_path">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All</directory>
Order deny,allow
Deny from all
Allow from localhost
</Directory>
Note: Order of the Deny and Allow lines is important! - just guessing, but I think that Apache simply applies the rules one after another, and the output of last rule that applies to the IP is used.
It can be also sometimes useful to disallow overrides of settings; if needed, simply change AllowOverride All to AllowOverride None, to disallow override of settings using .htaccess files.
See Apache documentation for complete list of options; just like with Options, it’s recommended to list the settings explicitely in AllowOverride to know what exactly is allowed.
Restricting Access to Certain Files
Great example of how to do this is contained in the httpd.conf itself, but many people seem to somehow miss it there, so here it is:
# The following lines prevent .htaccess and .htpasswd files
# from being viewed by Web clients.
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>
Of course, don’t forget to restart Apache after each edit of httpd.conf file, so it reloads the settings. Good luck!
Posted in Computers, Linux, Programming, Tips and Tricks, Troubleshooting, Tutorials, Windows | Tagged Apache, File, Folder, Networking, Security | 4 Comments »
January 27, 2008
“Quick Mask” is an extremely powerful, yet often neglected and forgotten, feature of Photoshop. It is a very simple and fast way to create complex selections.
Read the rest of this entry ?
Posted in Computers, Photoshop, Tips and Tricks, Tutorials | Tagged Graphics, Photoshop, Quick Mask, Tutorial | No Comments »