Question Set the position of an API Color Chooser

G37Sam

Registered User.
Local time
Today, 14:38
Joined
Apr 23, 2008
Messages
454
Hello fella's,

Is there a way to set/alter the position (center screen?) of an API Color Chooser dialog upon its creation?

It keeps popping up on the upper left corner of my screen which I can't stand.

Below is the code in the module

Code:
Option Compare Database
'This code was originally written by Terry Kreft,
'and modified by Stephen Lebans
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
' Contact [EMAIL="Stephen@lebans.com"]Stephen@lebans.com[/EMAIL]
'
Private Type COLORSTRUC
  lStructSize As Long
  hwnd As Long
  hInstance As Long
  rgbResult As Long
  lpCustColors As String
  Flags As Long
  lCustData As Long
  lpfnHook As Long
  lpTemplateName As String
End Type
Private Const CC_SOLIDCOLOR = &H80
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As COLORSTRUC) As Long
 
Public Function DialogColor() As Long
Dim x As Long, CS As COLORSTRUC, CustColor(16) As Long
CS.lStructSize = Len(CS)
CS.hwnd = Application.hWndAccessApp
CS.Flags = CC_SOLIDCOLORw
CS.lpCustColors = String$(16 * 4, 0)
x = ChooseColor(CS)
DialogColor = CS.rgbResult
End Function

Then I just call DialogColor from a form.. any help would be greatly appreciated

Cheers,
Sam
 
You linked me to a thread of someone with a similar issue but no solution.. not sure how that helps :p
 
The answer you need is in the thread - the response from spikepl on 02-19-2012, 11:20 AM says to "google windows api position dialog", which will return the following link (amongst others) http://msdn.microsoft.com/en-us/library/windows/desktop/ms632595(v=vs.85).aspx. The answer is in there, but you need to find it.:)
The approach is to find your dialog box by iterating all open windows (EnumWindows), then use its handle to position the window to where you need it (SetWindowPos). Maybe a bit more complex than that; I haven't actually tried this.
 
I know, and I saw that

Thing is, when the dialog box loads, codes will stop executing because its waiting on a response. So you can't really execute any code to get that dialogs handle.
 
Here's an alternative you can try.
There is an ActiveX control called Microsoft Common Dialog Control. If you open a form in design view and select the ActiveX controls tool from the toolbar/ribbon, find this item and drop it on your form. It is an invisible control.
This code example shows how to open the ShowColor dialog assuming the name of the CommonDialog control is as follows...
Code:
Private Sub Command1_Click()
   Me.CommonDialog0.ShowColor
End Sub
This shows the dialog pretty close to center screen on my machine/version. Adding the control to a form automatically references the ComDlg library, so you can explore the properties and methods exposed by this control in your Object Browser.
Hope this helps,
Mark
 
Dude

I'll post my code tonight. I have a position example too from a different forum but it's quite hard to decipher even for me lol

my code works just fine


Tonight dude :)


Nidge
 
Thank you

I'm not interested in using ActiveX controls as I plan on distributing my database to very non IT-savvy people, last thing I want to deal with is missing controls or installation files.
 
Hi Sam,

try this little app i put together for you. Check out the routine (CenterWindow) which is responsible for centring the dialog.

Cheers
 

Attachments

Hi Sam,

Did any of the suggestions / examples work? it would be good order to let people here know so they can forget about the thread...



cheers

Nidge
 
I am very impressed!

There's a lot to learn from the file you posted, I've never worked with class modules before so this should get interesting.

And yes, it worked like a charm :) Just need to apply that to a color chooser now
 
I am very impressed!

There's a lot to learn from the file you posted, I've never worked with class modules before so this should get interesting.

And yes, it worked like a charm :) Just need to apply that to a color chooser now

LOL i actually meant to do a color dialog....... sorry. I'll do another one today with a colour dialog only :)


Cheers

nidge
 
Haha thanks, that would save me a few hours of stress and a few beers :p
 
Hi Sam,

not sure which type of colour dialog you are looking for but this is a pretty ok & simple one. Centres in the screen too ;)
 

Attachments

I don't see any changes to be honest, did you re-upload the same file :p
 

Users who are viewing this thread

Back
Top Bottom