Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this VB code ?

Status
Not open for further replies.

fkkchung

Programmer
Oct 12, 2006
4
HK
Hi,

I was sent the following codes when I bump into some problem within VFP. This is suppose to be some API source code for changing the window printers settings without going thru Window's interactive dialog. Is this in VB? If it is, what do I have to do to make it 'Window API'?


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

BOOL SetPrinterDeviceOrientation(LPTSTR pszPrinterName, int Orientation)
{
// if NULL is passed, then assume we are setting app object's devmode and devnames

// Open printer
HANDLE hPrinter;
if( OpenPrinter( pszPrinterName, &hPrinter, NULL ) == FALSE )
return FALSE;

// obtain PRINTER_INFO_2 structure and close printer
DWORD dwBytesReturned, dwBytesNeeded;
GetPrinter( hPrinter, 2, NULL, 0, &dwBytesNeeded );
PRINTER_INFO_2* p2 = (PRINTER_INFO_2*)GlobalAlloc( GPTR, dwBytesNeeded);
if( GetPrinter( hPrinter, 2, (LPBYTE)p2, dwBytesNeeded, &dwBytesReturned) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}

p2->pDevMode->dmFields |= DM_ORIENTATION;

p2->pDevMode->dmOrientation = Orientation;

if( SetPrinter(
hPrinter, // handle to printer object
2, // information level
(LPBYTE) p2, // printer data buffer
0 // printer-state command
) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}


ClosePrinter( hPrinter );




// Allocate a global handle for DEVMODE

return TRUE;
}

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

Sorry if I am in the wrong terrain.

 
Tks tsuji,

Can the same process be written in VB codes? If I am to learn C++ or VB to make an API to solve my problem, I would rather take VB (I think it is easier to learn it, right?)
 
<what do I have to do to make it 'Window API'?

You might think of the "windows API" as an extension of VB, rather than a different programming language. It's actually a library (well, three libraries) of functions, (most of) which you can call using VB.

Generally, you would try to do what you're trying to do using VB, and when you can't, look into using some function from the Windows API. A good, simple example is the Sleep function, which suspends processing for a specifed number of microseconds. That's not a function that's "native" to VB, so you have to go into the WinAPI and use the one you find there.

I hope this clarifies things a bit for you.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top