Question Set the position of an API Color Chooser (1 Viewer)

G37Sam

Registered User.
Local time
Today, 13:03
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
 

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
You linked me to a thread of someone with a similar issue but no solution.. not sure how that helps :p
 

NickHa

CITP
Local time
Today, 10:03
Joined
Jan 29, 2012
Messages
203
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.
 

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
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.
 

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
Any help would be appreciated
 

MarkK

bit cruncher
Local time
Today, 02:03
Joined
Mar 17, 2004
Messages
8,188
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
 

NigelShaw

Registered User.
Local time
Today, 10:03
Joined
Jan 11, 2008
Messages
1,573
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
 

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
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.
 

NigelShaw

Registered User.
Local time
Today, 10:03
Joined
Jan 11, 2008
Messages
1,573
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

  • NSFontDialog.mdb
    352 KB · Views: 270

NigelShaw

Registered User.
Local time
Today, 10:03
Joined
Jan 11, 2008
Messages
1,573
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
 

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
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
 

NigelShaw

Registered User.
Local time
Today, 10:03
Joined
Jan 11, 2008
Messages
1,573
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
 

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
Haha thanks, that would save me a few hours of stress and a few beers :p
 

NigelShaw

Registered User.
Local time
Today, 10:03
Joined
Jan 11, 2008
Messages
1,573
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

  • NSFontDialog.mdb
    352 KB · Views: 129

G37Sam

Registered User.
Local time
Today, 13:03
Joined
Apr 23, 2008
Messages
454
I don't see any changes to be honest, did you re-upload the same file :p
 

NigelShaw

Registered User.
Local time
Today, 10:03
Joined
Jan 11, 2008
Messages
1,573
Hi Sam,

my bad. here it is lol :)
 

Attachments

  • NSFontColorDialog.mdb
    352 KB · Views: 178

Users who are viewing this thread

Top Bottom