Set Default Printer in VB using API calls 
Author Message
 Set Default Printer in VB using API calls

Quote:

>Below are my current calls.  These were derived from an example I found in MS-
>OnLine.

>WriteProfileString("windows","device","Distiller Assistant v3.01,Pdfwritr.drv,
>\DISTSST.PS")

>SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0, (LPARAM) (LPCTSTR)
>"windows", SMTO_BLOCK,1000,NULL)

>The 4th parameter calls for a Long.  The example used the (LPARAM) (LPCTSTR)
>"windows".  My question is, what is (LPARAM) and why are they passing the
>string "windows" to a Long parameter?

>Thank You in advance,

>Eric

Eric,

The Declare in Visual Basic, the 4th parameter is long, but the code
you have got above is C++ code, and the Declare for C++ is slightly
different (in windows.h) it is as follows:

LRESULT SendMessageTimeout( HWND hWnd,
 // handle of destination window

UINT Msg,
 // message to send

WPARAM wParam,
 // first message parameter

LPARAM lParam,
 // second message parameter

UINT fuFlags,
 // how to send the message

UINT uTimeout,
 // time-out duration

LPDWORD lpdwResult
 // return value for synchronous call

);

As you notice, there is a lot more types that can be used for passing
to the DLL.  In this case there is a specfic LPARAM data type.  So in
C++ it is possibe to pass what they are passing.

In the Case of VB the declare is as follows:

Declare Function SendMessageTimeout Lib "user32" Alias
"SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal
wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal
uTimeout As Long, lpdwResult As Long) As Long

So the following code should work:

In a module:

Option Explicit

Declare Function SendMessageTimeout Lib "user32" Alias
"SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal
wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal
uTimeout As Long, lpdwResult As Long) As Long

Public Const HWND_BROADCAST = -1
Public Const WM_WININICHANGE = &H1A
Public Const SMTO_BLOCK = &H1

In a Form:

Private Sub Command1_Click()
    Dim ReturnVal As Long
    Dim lBuff As Long
    ReturnVal = SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE,
0&, 0&, SMTO_BLOCK, 1000, lBuff)
    If ReturnVal <> 0 Then
        MsgBox "Success"
    Else
        MsgBox "ERROR"
    End If
End Sub

Try it out...

Donkey

????????????????????????????????????????????
DOS never says "EXCELLENT command or filename"
-
Note: remove "NOSPAM" from my address
to e-mail me
????????????????????????????????????????????



Wed, 01 Nov 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to Set default Printer.Orientation using API Call

2. Help - API Call To Get and Set the Default Printer

3. Changing default printer using API calls

4. Using VB to set default printer

5. setting default printer to landscape using vbscript/vb

6. setting default printer to landscape using vbscript/vb

7. setting default printer to landscape using vbscript/vb

8. Setting the default printer through WinApi call?

9. API to set default Printer

10. Setting via API the default printer settings

11. Setting Default Printer by API

12. Setting default printer with APIs

 

 
Powered by phpBB® Forum Software