Changing Form's BorderStyle property at run time but before form is loaded

Hello,
          Is there any workaround to change the form's BorderStyle property 
before the form is loaded?
I need to change it from None to Fixed Single depending on user's 
preferences.
That form is not the main form of the project.
Your thoughts appreciated,
Claire 


0
Claire
5/6/2010 9:05:57 PM
vb.general.discussion 1016 articles. 0 followers. Follow

7 Replies
1270 Views

Similar Articles

[PageSpeed] 57

Claire wrote:
>           Is there any workaround to change the form's BorderStyle property 
> before the form is loaded?
> I need to change it from None to Fixed Single depending on user's 
> preferences.

Technically, not before it's loaded, but you can change it during the 
Form_Load event using the techniques demonstrated here:

  http://vb.mvps.org/samples/FormBdr

-- 
..NET: It's About Trust!
http://vfred.mvps.org


0
Karl
5/6/2010 9:40:43 PM
"Claire" <replyto@fra> wrote in message 
news:%23i%236t$V7KHA.3504@TK2MSFTNGP05.phx.gbl...

> Is there any workaround to change the form's BorderStyle
> property before the form is loaded? I need to change it from
> None to Fixed Single depending on user's preferences.
> That form is not the main form of the project.

Don't know if you actually do mean "before the form is loaded". You can 
change its BorderStyle after it loads, or as it loads:

  Dim oldStyle As Long
  oldStyle = GetWindowLong(Form2.hwnd, GWL_STYLE)
  SetWindowLong Form2.hwnd, GWL_STYLE, oldStyle _
        And Not WS_THICKFRAME
  SetWindowPos Form2.hwnd, 0, 0, 0, 0, 0, _
        SWP_FRAMECHANGED Or SWP_NOMOVE Or _
        SWP_NOZORDER Or SWP_NOSIZE
  Form2.Show

Mike



0
Mike
5/6/2010 9:51:14 PM
Thank you Karl and Mike.
It does work perfectly.
Claire

"Claire" <replyto@fra> wrote in message 
news:%23i%236t$V7KHA.3504@TK2MSFTNGP05.phx.gbl...
> Hello,
>          Is there any workaround to change the form's BorderStyle property 
> before the form is loaded?
> I need to change it from None to Fixed Single depending on user's 
> preferences.
> That form is not the main form of the project.
> Your thoughts appreciated,
> Claire
> 


0
Claire
5/6/2010 11:34:14 PM
Almost done but I need to disable (grayed) X
How to do that?
Thanks,
Claire

"Claire" <replyto@fra> wrote in message 
news:%23c8tkSX7KHA.3924@TK2MSFTNGP04.phx.gbl...
> Thank you Karl and Mike.
> It does work perfectly.
> Claire
>
> "Claire" <replyto@fra> wrote in message 
> news:%23i%236t$V7KHA.3504@TK2MSFTNGP05.phx.gbl...
>> Hello,
>>          Is there any workaround to change the form's BorderStyle 
>> property before the form is loaded?
>> I need to change it from None to Fixed Single depending on user's 
>> preferences.
>> That form is not the main form of the project.
>> Your thoughts appreciated,
>> Claire
>>
>
> 


0
Claire
5/6/2010 11:49:48 PM
Claire wrote :
> Almost done but I need to disable (grayed) X
> How to do that?

Not sure it's exactly what you're looking for, but what about that 
ControlBox property in the CFormBorder class I directed you to?


0
Karl
5/7/2010 12:00:16 AM
I have found the way.
using GWL_EXSTYLE with WS_EX_TOOLWINDOW does disable X but also it removes 
the icon.
I can live without the icon.
I wonder if in my case should I use first GWL_STYLE and then GWL_EXSTYLE 
like below:
===================
  oldStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
  SetWindowLong Me.hWnd, GWL_STYLE, oldStyle Or WS_CAPTION Or WS_SYSMENU
  oldStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
  SetWindowLong Me.hWnd, GWL_EXSTYLE, oldStyle Or WS_EX_TOOLWINDOW
===================
Is that correct?
Thanks,
Claire

"Claire" <replyto@fra> wrote in message 
news:%23c8tkSX7KHA.3924@TK2MSFTNGP04.phx.gbl...
> Thank you Karl and Mike.
> It does work perfectly.
> Claire
>
> "Claire" <replyto@fra> wrote in message 
> news:%23i%236t$V7KHA.3504@TK2MSFTNGP05.phx.gbl...
>> Hello,
>>          Is there any workaround to change the form's BorderStyle 
>> property before the form is loaded?
>> I need to change it from None to Fixed Single depending on user's 
>> preferences.
>> That form is not the main form of the project.
>> Your thoughts appreciated,
>> Claire
>>
>
> 


0
Claire
5/7/2010 12:04:57 AM
"Claire" <replyto@fra> wrote in message 
news:uAcqRbX7KHA.356@TK2MSFTNGP05.phx.gbl...
> Almost done but I need to disable (grayed) X

That one's not so easy, but is doable.

Using the below code
To disable,
m_fCloseEnabled = EnableCloseButton(hwnd, False)

To toggle,
m_fCloseEnabled = EnableCloseButton(hwnd, Not m_fCloseEnabled)

David


Watch for word wrap,

Private Const SC_CLOSE As Long = &HF060&
Private Const MIIM_STATE As Long = &H1&
Private Const MIIM_ID As Long = &H2&
Private Const MF_ENABLED As Long = &H0&
Private Const MF_GRAYED As Long = &H3&

Private Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As Long 'String
    cch As Long
End Type

'* Retreives the handle to the system menu for the specified window
Private Declare Function GetSystemMenu Lib "user32" ( _
        ByVal hwnd As Long, _
        ByVal bRevert As Long) As Long

'* Retreives inforamtion about a menu entry
Private Declare Function GetMenuItemInfo Lib "user32" _
        Alias "GetMenuItemInfoA" ( _
        ByVal hMenu As Long, _
        ByVal un As Long, _
        ByVal b As Boolean, _
        lpMenuItemInfo As MENUITEMINFO) As Long

'* Set the specified information for a menu entry
Private Declare Function SetMenuItemInfo Lib "user32" _
        Alias "SetMenuItemInfoA" ( _
        ByVal hMenu As Long, _
        ByVal un As Long, _
        ByVal bool As Boolean, _
        lpcMenuItemInfo As MENUITEMINFO) As Long

'* Enables/disables the specified menu item
Private Declare Function EnableMenuItem Lib "user32" ( _
        ByVal hMenu As Long, _
        ByVal wIDEnableItem As Long, _
        ByVal wEnable As Long) As Long

'* Redraws the menu for the specified window
Private Declare Function DrawMenuBar Lib "user32" ( _
        ByVal hwnd As Long) As Long

'* Form close button state
Private m_fCloseEnabled As Boolean

Public Function EnableCloseButton(ByVal hwnd As Long, ByVal Enable As 
Boolean) As Boolean

    '* Purpose  :  Enables/disables Close system menu item
    '* Accepts  :  hWnd - handle of the window
    '              Enable - True to enable, False to disable
    '* Returns  :  Boolean - enabled state
    '* Modified :  8/14/2006 dwy

    '* Note     :  Alt+F4 must be handled in the Query_Unload event
    '*          :  Errors are handled by the calling procedure

    Dim hMenu As Long
    Dim mii As MENUITEMINFO

    '* Default value
    EnableCloseButton = Enable

    '* Get a handle to the system menu
    hMenu = GetSystemMenu(hwnd, 0)
    If hMenu Then

        '* Fill in size parameter
        mii.cbSize = Len(mii)

        If Enable Then
            '* Get the menu item information for the close menu item
            '* Exit if it fails, item is most likely already enabled
            If GetMenuItemInfo(hMenu, -SC_CLOSE, False, mii) = 0 Then
                GoTo PROC_EXIT
            End If

            '* Switch the ID of the menu item so that VB can't reset it
            mii.wID = SC_CLOSE
            mii.fMask = MIIM_ID
            If SetMenuItemInfo(hMenu, -SC_CLOSE, False, mii) = 0 Then
                GoTo PROC_EXIT
            End If

            '* Set enabled state of the menu item
            EnableCloseButton = EnableMenuItem(hMenu, SC_CLOSE, MF_ENABLED)

        Else
            '* Get the menu item information for the close menu item
            '* Exit if it fails, item is most likely already 
disabled(grayed)
            If GetMenuItemInfo(hMenu, SC_CLOSE, False, mii) = 0 Then
                GoTo PROC_EXIT
            End If

            '* Switch the ID of the menu item so that VB can't reset it
            mii.wID = -SC_CLOSE
            mii.fMask = MIIM_ID
            If SetMenuItemInfo(hMenu, SC_CLOSE, False, mii) = 0 Then
                GoTo PROC_EXIT
            End If

            '* Set disabled state of the menu item
            EnableCloseButton = EnableMenuItem(hMenu, -SC_CLOSE, MF_GRAYED)

        End If

        '* Force a redraw of the menu
        Call DrawMenuBar(hwnd)

    End If

PROC_EXIT:
    Exit Function

End Function

Private Sub Form_Load()
    m_fCloseEnabled = True
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode = vbFormControlMenu Then
        Cancel = Not m_fCloseEnabled
    End If
End Sub


0
David
5/7/2010 12:47:02 AM
Reply:

Similar Artilces:

External data link change
Hi, I've a sheet linked to an external data on the net, and I would like that a cell in this sheet to indicate the last date and time it was updated, the simplest way the better but I can do some programming too. Thanks for your attention, -- Domingos Junqueira No need of help any more, I solved the question. Thanks again ...

how create sum function in form field
I'm trying to utilize the sum function in a field on an Outlook 2002 form. I want the form field to sum up the other form fields. Sum is not a function listed in the value tab. Please advise. ...

Why does the change change to a number?
Hi all, I've noticed something wierd and always wondered WHY it happens. When you type a date into a cell, and then change the Formatting of it to a 'general' cell, it turns into a number. How does it come up with that number? What is the significance? i.e. type today's date of "12/7/2007" - change it to a 'General' format, and it then says "39423". I'm a trainer of Excel and this question always comes up. I'm curious myself too. Thanks! Joe It's the number of days since January zero 1900 using Excel default for windows (M...

changing the way Excel displays selected cells
Is there a way to change the way Excel displays selected cells? I'm interested in viewing all the selected cells highlighted (with light blue for instance), but by default excel highlights all the cells but not the first one the same occurs when you define a range with no adyacents cells Your definition of the display is not quite correct. Excel highlights the current cell, Excel also highlights a selecte range. The currently selected cell is generally the first of a range, bu press enter and the current cell changes and becomes the second, the third etc in the range. You cannot...

Track Changes
How do i remove the track changes in outlook? When i press "Enter", a symbol that represents "Enter" will appears. Same for space etc. ...

DST changes for Exchange 5.5
I noticed the 2007 DST Calendar Update "Exchange tool" is available now: http://support.microsoft.com/kb/930879 This will seemingly take care of calendars for mailboxes still on Exchange 5.5 servers, as Exchange 5.5 is listed as "compatible" . However would this address the CDO issues such as BlackBerry users and OWA users still on Exchange 5.5 ? Thanks in advance, Itrcb4 On Mon, 12 Feb 2007 14:31:00 -0800, itrcb4 <itrcb4@discussions.microsoft.com> wrote: >I noticed the 2007 DST Calendar Update "Exchange tool" is available now: > >http://su...

more on VBA function name change
I thought I'd start a new thread since I haven't received any replies to my first one... To recap: I've declared a function in a module using mixed case: Function TMDE_Category (FormName As Form) I noticed recently that it appeared in the module as Function tmde_category(FormName As Form) I changed it back to the mixed case declaration, saved the module, exited the app, reopened it and looked. The function had changed back to the all lowercase declaration. Things I've tried since the original post: Using the databse documenter, I selected all ob...

Can't Publish changes with Deploy Manager
After a migration process, I can't publish the changes made on CRM. When I try do this in Deploy Manager I get the follow error: ---------------------------------------------------------------------------- ----- Publish done with errors. See the event log to get deitails NETRA-INOVACAO: ***Error*** Failed to download XSL template files from Web Server ---------------------------------------------------------------------------- ----- Can somebody help me? I don't know if the migration process have any relationship with the error. Thank you for pay attention. []'s Vin´┐Żcius Pitta...

How to change icon for my application
Hi, I am currently developing an application on visual studio 6.0, and i wish to change the MFC icon on my application header. Anyone can help? Thank you. Raed Sawalha wrote: > Hi, I am currently developing an application on visual studio 6.0, and i > wish to change the MFC icon on my application header. Anyone can help? Thank > you. > > Open the icon resource for editing by double clicking. Then notice the control just above the editing grid that lets you switch between editing the large icon and editing the small one. -- Scott McPhillips [VC++ MVP] thanx that work...

How to change newsgroup message font
Like many other ribbon based programs I sometimes struggle to find how to make a change. This time its how to change the font just for newsgroup messages? regards "nobody" wrote in message news:EWTao.39493$GF5.7129@hurricane... > Like many other ribbon based programs I sometimes struggle to find how to make a change. This time its how to change the font just for newsgroup messages? Newsgroup messages are usually plain text. The font used is that selected at [no name tab] > Options > Mail > Read > Fonts for the encoding specified for the messag...

Notify change of email address when changing ISP
How do I notify my entire address book of an email address when I change ISP's? Thanks By sending a mail to everyone ? If you do so, please use BCC for the adresses, this way you won't spread everybody's e-mail adres to everybody. Niels Bob Baker wrote: > How do I notify my entire address book of an email address when I change ISP's? > Thanks ...

Time calculations for Scheduled vs Actual Employee Time and Wages 11-28-09
I am THRYING and TRYING to make a simple schedule worksheet for a manger to use to calculate the time he schedules an employee to clock in and out and what it will cost him in regards to his allocated budget and then to be able to compare it after the job is completed. BUT time calculations have thrown me for loop and I am stuck for hours on trying to calculate time fields. PLEASE DEAR GOD can someone help me. Below is a simple example of my worksheet. A2 (Time IN) = 1:00 PM A3 (Time OUT) = 5:00 PM A4 (Time Worked) = 4:00 (h:mm format) ...

Pass Through query with criteria on a form
I have a Pass Through query that looks like this. select Location,City,State,Country,Pings from (select sd_term_name_loc as 'Location', sd_term_city as 'City', sd_term_st as 'State', sd_term_cntry as 'Country', count(sd_key)as 'Pings' from detail (nolock) where -- ***** The dates below refer to the date and time at which the transaction was loaded to PRM. -- ***** -- ***** The number of pings which have occurred BETWEEN those dates/times will be counted. -- ***** -- ***** Enter the date/time in the format '09/16/2007 14:00:00.000...

Change a formula to an acual number
I want to change the formula I have created to the number it has created Example: Cell A1 is the number 1. Cell A2 is the formula =a1+1 creatin the number 2. I want this to be a two not a formula. Any ideas? Laura, copy, then paste special, valves -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2000 & 97 ** remove news from my email address to reply by email ** "Laura" <anonymous@discussions.microsoft.com> wrote in message news...

Outlook 2003 MSKSrver.exe! RUNS ALL TIME HOGS MEMORY!
Outlook 2003 Too Slow! I used the MicroSoft task manager to find-out what all the action in the background is! MSKSrver.exe RUNS ALL the time at 85 to 95 CPU and the CPU total usage is near 100% ALL the time with nothing major running but MSKSrver.exe! Whenever I try to do anything else, the new application takes forever to get going as it must compete with MSKSrver.exe! Why is that database server working all the time? What is it doing? I do not use "Favorite Folders" or "Business Contact Manager" yet, though those are areas show in MAIL, empty. I don'...

Problem Changing an Investment Name
I am trying to change an investment name and Money 2006 tells me "The name or symbol 'TRP Spectrum Income' has already been used for a deleted investment. Please enter a different name." When I go to delete investments the name does not appear! Any ideas on how I get Money to accept the name change? This is the first time I have run into this situation and I have made numerous name changes in Money over the years. In microsoft.public.money, Ken wrote: >I am trying to change an investment name and Money 2006 tells me "The name >or symbol 'TRP Spec...

Running Excel 2000 & 2007 Bug
This is a multi-part message in MIME format. ------=_NextPart_000_000C_01CA53A0.C4136A80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am able to run 2000 and 2007 on the same machine ok except for the = following The File Type associations are messed up. I have a bunch of files that = were created in 2000 and they have the *.xls extension. I want these = files(when double clicked) to open in Excel 2000. However, Excel 2007 = is dominating this action. I have tried changing the association for the *.xls file type to version = 200...

Should I change this code?
Should I change 556 to 560???..............Thanks for your help..........Bob Private Sub Command560_Click() On Error GoTo Err_Command556_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "frmClientInfomation" DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Command556_Click: Exit Sub Err_Command556_Click: MsgBox Err.Description Resume Exit_Command556_Click End Sub On Sun, 15 Jul 2007 16:37:26 +1200, "Bob V" <rjvance@ihug.co.nz> wrote: > >Should I change 556 to 560???..............Thanks for your help.....

symbols won't work in form fields
I have Access 2002. We write a lot of letters in French and as I have a QWERTY keyboard, we have shortcuts for the french letters which are missing from the keyboard. For example Ctrl + e is e with an accute accent, Alt + e is e with a grave accent, and so on. It all works just fine in WORD. But in my forms in my ACCESS database, in my fill-in fields, the shortcuts simply don't work. And there is no "symbol" option available in the tool bar to insert a symbol or French character. Is there any way I can add this function in to the database ? thanks .. Roger ...

Prompted for password when running a report
Running CRm 3.0 on a single SBS 2003 box. Everything seems to work great except we get prompted for windows credentials when running a report. I verified the reports and reportserver website are using integrated authentication. The webserver is in the local intranet zone. Any ideas? Thanks Dave Dave, I'd first try adding the server as a 'trusted site' in IE, and under 'custom level' set User Authentication.Logon to "Automatic logon with current username and password". Hope that helps, Jeff Bennett CRM Practice Manager Solutions Consulting Group, Inc....

How to change default font in Outlook 2003
Can someone tell me how to change tthe default font in Outlook 2003 when composing a new email. It always comes up as Times New Roman. I remember somewhere that I specified that Outlook should use Word as the text editor and that seems to be the case. I have Arial as my default font in Word but this seems to make no difference when using Outlook. Hi, Please go to Tools > Setting > Mail Format > Stationery and Fonts > Fonts It's right there :) On 20 Nov 2005 06:28:45 -0800, amarsarit@gmail.com wrote: >Hi, >Please go to Tools > Setting > Mail Format > Statione...

icon changes with change of extension
when we change the extension of a file in windows, its icon also changes..... how does windows do tht. in my application i require a similar approach. i want the icon to be dependent on the file extension not on the attributes of the file. i have gone trough the registry but things are not very clear. Windows has listed all the file extensions avaliable there, but there is no general way to extract icons for those extension... kindly help icon changes with change of extension "Neelu" <nemesia31@gmail.com> wrote in message news:1161232739.720722.120950@b28g2000cwb.google...

Combo Box on Forms
Hi, I am using a combo box on a form that has several items w/ one being Other. If the user selects other I want them to be able to input what they want so that it will go into the table instead of just the "Other". I just am not really sure on how to do that. Can you help? Thanks, Jaime In design view click on VIEW - Properties and the the combo. Then change Limit To List to No. -- KARL DEWEY Build a little - Test a little "jseger22@yahoo.com" wrote: > Hi, > > I am using a combo box on a form that has several items w/ one being > Other. If the use...

Field Type Change
I am trying to change a free text field to a drop down menu in my current database, that already has data entered for this particular field, in order to avoid multiple versions of the same organization that are just typed in differently. I'm assuming that I'll need to recode the different versions of an entry to make them uniform but after that, I'm unsure how to proceed so I won't lose any data. Is this possible or will I need to delete the field, recreate it as a drop down and then re-enter the data? Thanks in advance! Mike Thanks everyone for all the input and advice s...

Tracking Changes
I am the author of a document and am making revisions to it. I want to chnage the redline color to denote new edits from the 1st version. Can anyone guide me through this process? I am sure it is easy but I cannot figure it out. THanks Peter On Wed, 10 Feb 2010 07:08:06 -0800, Peter SSI <Peter SSI@discussions.microsoft.com> wrote: >I am the author of a document and am making revisions to it. I want to >chnage the redline color to denote new edits from the 1st version. Can >anyone guide me through this process? I am sure it is easy but I cannot >figure i...