Author Topic: Bricscad application window handle  (Read 6249 times)

0 Members and 1 Guest are viewing this topic.

bty

  • Guest
Bricscad application window handle
« on: June 14, 2012, 11:11:24 AM »
Anyone have any idea how to access the Application window handle in Bricscad?  I'm new to Brics VBA, and can't find any info in their help files.

Have been playing around with something like this:
 
Dim BricsApp As AcadApplication
Dim AppHandle As Long

AppHandle = BricsApp.HWND


But all it does is throw a runtime error "Object variable or With block variable not set"

Intelli sense shows HWND as a property of the application object but.....
Any suggestions?  Long term goal is to turn off screen updating during a long batch-plot program.
Thanks

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Bricscad application window handle
« Reply #1 on: June 14, 2012, 11:41:59 AM »
you would use ThisDrawing.Application.HWND  :-)

Cheers

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Bricscad application window handle
« Reply #2 on: June 14, 2012, 11:46:07 AM »
You have not set the variable BricsApp

You can try something like this:

Code: [Select]
Function GetAppHandle(ByRef Drawing As AcadDocument) As Long
 GetAppHandle = Drawing.Application.HWND
End Function

Alternatively

Code: [Select]
Dim BricsApp As AcadApplication
Dim AppHandle As Long

Set BricsApp = ThisDrawing.Application
AppHandle = BricsApp.HWND
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

bty

  • Guest
Re: Bricscad application window handle
« Reply #3 on: June 14, 2012, 11:52:52 AM »
Got it - realized I hadn't set the BricsApp- that cleared the error, thanks.

Anyone have any idea how to prevent screen updating in Bricscad thru VBA?
Basic approach:
 
Dim BricsApp As AcadApplication
Set BricsApp = ThisDrawing.Application


Then using:
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
with:
LockWindowUpdate BricsApp.HWND
To turn off updating

Any suggestions?  Goal is to turn off screen updating during a long batch-plot program.  So far the above has no effect- screen continues to update- running WIn7 64
Thanks

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Bricscad application window handle
« Reply #4 on: June 14, 2012, 12:23:35 PM »
hmm ... have you tried this?
Code: [Select]
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, _
                                                                ByVal wMsg As Integer, _
                                                                ByVal wParam As Integer, _
                                                                ByVal lParam As Integer) As Integer

Private Const WM_SETREDRAW As Integer = 11

SendMessage hWnd, WM_SETREDRAW, CInt(False), 0

Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

bty

  • Guest
Re: Bricscad application window handle
« Reply #5 on: June 14, 2012, 12:43:21 PM »
I get an "Overflow" error at the SendMessage line when I run it- however I am totaly unfamiliar with the whole SendMessage function, consequently, I may not have it set up correctly.  I'm assuming the hwnd in your code needs the be the bricsapp main window handle?

Any explanation onwhat's happeining in the execution?
Thx

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Bricscad application window handle
« Reply #6 on: June 14, 2012, 01:09:11 PM »
Technically, when you SendMessage, you are pumping the message stream of the control referenced by the handle. The WM_SETREDRAW flag tells the window to discard calls to paint. Passing "False" prevents the control referenced by the handle from updating when the invalidate rectangle function is called. As a result, you must ALWAYS call the function once to disable it and once to enable it. If you don't you will lose all access to the application window.

You might try passing the arguments as different types:
Code: [Select]
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
                                                                ByVal wMsg As Long, _
                                                                ByVal wParam As Long, _
                                                                ByVal lParam As Any) As Integer


Private Const WM_SETREDRAW As Integer = 11
 
Public Sub LockUpdates(ByVal hWnd As Long, ByVal Redraw As Boolean)
  SendMessage hWnd, WM_SETREDRAW, Redraw, ByVal 0&
End Sub

As an aside, you don't have to pass the application window to the function if you are dealing with open drawings, you can merely pass the handle of the drawing.

If you are opening and then plotting, you will probably want to disable the entire window.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

bty

  • Guest
Re: Bricscad application window handle
« Reply #7 on: June 14, 2012, 01:22:02 PM »
Thanks Keith- beginning to make sense.

To restore window updates when done (and on error) would I use the exact same call to the function except "True" instead of "False"?:
SendMessage AppWinHandle, WM_SETREDRAW, CInt(True), 0

Also - what is the purpose of the final parameter "0"?

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Bricscad application window handle
« Reply #8 on: June 14, 2012, 01:31:34 PM »
You would pass True as the third parameter. The fourth parameter is not used for WM_SETREDRAW

Also, if you use the function to pass the values as long (as in my second example) you could use the value True or False .. or Clng(True) Clng(False)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

bty

  • Guest
Re: Bricscad application window handle
« Reply #9 on: June 14, 2012, 02:12:54 PM »
Thanks again Keith - workin like a charm, Plots fast and clean!
Can you tell me where I'd find more info on using SendMessage just to get familiar with it?  For example a list of codes (i.e. WM_SETREDRAW at 11) corresponding to what else is available for hwnd?
I've learned a lot today- Next I want to figure out how to display a progress bar and suppress the print notification boxes that pop up ea time a dwg plots.

 

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Bricscad application window handle
« Reply #10 on: June 14, 2012, 02:31:45 PM »
You can read about the SendMessage function here

You can read about the paint messages here

There is a library of all the messages you can send to a window here

Keep in mind that some may not work as expected in a VBA environment.

If you want to suppress the print notification dialog, it can be done relatively easily. (I suspect you mean the plot window for AutoCAD). Look into scripting. First you build a script with all of the plotting parameters set, then call that script by your application.
I used a very similar method some time ago to batch plot an entire folder of drawings. The user selects the folder, the scripts are written and then called. When scripting the plot command, the window does not display.

For a progressbar, this is easier yet ...
On your form, drop a progressbar where you want it to appear. Set it's visible property to false. When the user clicks the plot button in your application (assuming you have a plot button), make the progressbar visible, set the maximum value of the progressbar to the number of plots you will be doing, then as you loop through the plots, increment the progressbar value by one. Make sure you don't set the progressbar to a higher value than the maximum value or an error will occur.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

bty

  • Guest
Re: Bricscad application window handle
« Reply #11 on: June 14, 2012, 02:45:11 PM »
Thanks,
No I don't mean mean the print dialog box - I'm speaking of the small pop-up box that appears each time AutoCAD (Bricscad) is in the middle of sending a drawing to the printer- just creates irritating screen flicker during a long batch.
Great info- I'll explore the connections you provided.  I also like your idea of using the scripts - could be a possibility.  In my app the plot list is a text file or an excel spreadsheet, that way I don't have to move files around.