Solved

Creating a form.

Posted on 2001-08-03
15
197 Views
Last Modified: 2010-08-05
Hi all
This problem has been bugging me for a couple of days.

I have the folloing code

------------------------------
Form:

VERSION 5.00
Begin VB.Form frmOwnMenu
  Caption         =   "Owner Drawn Menu Example"
  ClientHeight    =   3375
  ClientLeft      =   165
  ClientTop       =   450
  ClientWidth     =   4185
  Icon            =   "frmOwnMenu.frx":0000
  LinkTopic       =   "Form1"
  MaxButton       =   0   'False
  ScaleHeight     =   225
  ScaleMode       =   3  'Pixel
  ScaleWidth      =   279
  StartUpPosition =   2  'CenterScreen
  Begin VB.PictureBox pctEntry4
     AutoRedraw      =   -1  'True
     AutoSize        =   -1  'True
     Height          =   540
     Left            =   0
     Picture         =   "frmOwnMenu.frx":000C
     ScaleHeight     =   32
     ScaleMode       =   3  'Pixel
     ScaleWidth      =   32
     TabIndex        =   3
     Top             =   1920
     Visible         =   0   'False
     Width           =   540
  End
  Begin VB.PictureBox pctEntry2
     AutoRedraw      =   -1  'True
     AutoSize        =   -1  'True
     Height          =   540
     Left            =   0
     Picture         =   "frmOwnMenu.frx":08D6
     ScaleHeight     =   32
     ScaleMode       =   3  'Pixel
     ScaleWidth      =   32
     TabIndex        =   2
     Top             =   720
     Visible         =   0   'False
     Width           =   540
  End
  Begin VB.PictureBox pctEntry3
     AutoRedraw      =   -1  'True
     AutoSize        =   -1  'True
     Height          =   540
     Left            =   0
     Picture         =   "frmOwnMenu.frx":11A0
     ScaleHeight     =   32
     ScaleMode       =   3  'Pixel
     ScaleWidth      =   32
     TabIndex        =   1
     Top             =   1320
     Visible         =   0   'False
     Width           =   540
  End
  Begin VB.PictureBox pctEntry1
     AutoRedraw      =   -1  'True
     AutoSize        =   -1  'True
     Height          =   540
     Left            =   0
     Picture         =   "frmOwnMenu.frx":15E2
     ScaleHeight     =   32
     ScaleMode       =   3  'Pixel
     ScaleWidth      =   32
     TabIndex        =   0
     Top             =   120
     Visible         =   0   'False
     Width           =   540
  End
  Begin VB.Label lblKFiles
     AutoSize        =   -1  'True
     BackStyle       =   0  'Transparent
     Caption         =   "The 'K' Files"
     BeginProperty Font
        Name            =   "MS Sans Serif"
        Size            =   8.25
        Charset         =   0
        Weight          =   400
        Underline       =   -1  'True
        Italic          =   0   'False
        Strikethrough   =   0   'False
     EndProperty
     ForeColor       =   &H00FF0000&
     Height          =   195
     Left            =   3240
     MouseIcon       =   "frmOwnMenu.frx":1EAC
     MousePointer    =   99  'Custom
     TabIndex        =   6
     Top             =   3120
     Width           =   855
  End
  Begin VB.Label lblPlug
     AutoSize        =   -1  'True
     BackStyle       =   0  'Transparent
     Caption         =   "For programming tutorials and products visit:"
     Height          =   195
     Left            =   120
     TabIndex        =   5
     Top             =   3120
     Width           =   3090
  End
  Begin VB.Label lblKalInfo
     BackStyle       =   0  'Transparent
     Height          =   2895
     Left            =   120
     TabIndex        =   4
     Top             =   120
     Width           =   3855
  End
  Begin VB.Menu mnuOwn
     Caption         =   "Owner Drawn Menus"
     Begin VB.Menu mnuEntry1
        Caption         =   "Entry #1"
     End
     Begin VB.Menu mnuEntry2
        Caption         =   "Entry #2"
     End
     Begin VB.Menu mnuEntry3
        Caption         =   "Entry #3"
     End
     Begin VB.Menu mnuEntry4
        Caption         =   "Entry #4"
     End
  End
  Begin VB.Menu mnuReg
     Caption         =   "Regular Menus"
     Begin VB.Menu mnuReg1
        Caption         =   "Entry #1"
     End
     Begin VB.Menu mnuReg2
        Caption         =   "Entry #2"
     End
     Begin VB.Menu mnuReg3
        Caption         =   "Entry #3"
     End
     Begin VB.Menu mnuReg4
        Caption         =   "Entry #4"
     End
  End
End
Attribute VB_Name = "frmOwnMenu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'/////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////
'////                                                                         ////
'//// frmOwnMenu - There isn't much to say here. Luckily the majority of      ////
'////              the work is taken care of by the OMenu_h code module,      ////
'////              which serves as an object manager and message handler,     ////
'////              and COwnMenu, which processes the actual commands and      ////
'////              draws each menu item to the screen. The only real work     ////
'////              that is done in this form module is in the InitMenus       ////
'////              procedure, which registers each menu entry with OMenu_h,   ////
'////              and in Form_Load, which initiates the subclass and calls   ////
'////              the InitMenus member function of this form. It is also     ////
'////              important to note that in Form_QueryUnload a procedure     ////
'////              in OMenu_h named "FreeMenus" is called. This procedure     ////
'////              frees the memory that is dynamically allocated by          ////
'////              OMenu_h in its registration process.                       ////
'////                                                                         ////
'//// ----------------------------------------------------------------------- ////
'////                                                                         ////
'//// If you've read this far at least it means you are making some           ////
'//// attempt to learn the code provided (Good luck to you!). If you have     ////
'//// any questions or comments please email them to KalaniCA@aol.com         ////
'//// If this example has been of use to you, you may want to visit           ////
'//// my website, at http://www.calcoast.com/kalani/                         ////
'////                                                                         ////
'//// ----------------------------------------------------------------------- ////
'////                                                                         ////
'//// This program was created by Kalani Thielen on 04/14/98                  ////
'//// You may use the provided code module and object module if this text     ////
'//// appears within it.                                                      ////
'////                                                                         ////
'//// NOTE: If this code is used within a commercial (for profit) application ////
'////       please send US $20.00 in a self-addressed stamped envelope to:    ////
'////               Kalani Thielen                                            ////
'////               430 Quintana Road PMB 122                                 ////
'////               Morro Bay, CA 93442                                       ////
'////                                                                         ////
'//// For more programming information visit my website,                      ////
'//// the website is: http://www.calcoast.com/kalani/                        ////
'////                                                                         ////
'/////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////

'// Function used to go to my web site
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal
lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
ByVal nShowCmd As Long) As Long
Private Const SW_MAXIMIZE = 3

'/////////////////////////////////////////////////////////
'////
'//// InitMenus - Initializes our owner drawn menus
'////             this procedure simply registers each
'////             menu item with an appropriate
'////             COwnMenu object
'////
'/////////////////////////////////////////////////////////
Private Sub InitMenus()
'// Get top level menu handle
Dim hMainMenu As Long, hSubMenu As Long
hMainMenu = GetMenu(Me.hwnd)
hSubMenu = GetSubMenu(hMainMenu, 0)

'// Register each of our menus
RegisterMenu hSubMenu, 0, Me.hwnd, "Owner Drawn Entry #1", pctEntry1
RegisterMenu hSubMenu, 1, Me.hwnd, "Owner Drawn Entry #2", pctEntry2
RegisterMenu hSubMenu, 2, Me.hwnd, "Owner Drawn Entry #3", pctEntry3
RegisterMenu hSubMenu, 3, Me.hwnd, "Owner Drawn Entry #4", pctEntry4
End Sub
Private Sub ShowInfo()
Dim sMsg As String

sMsg = "Owner Drawn Menu Example by Kalani Thielen" & vbCrLf & vbCrLf
sMsg = sMsg & "This program demonstrates the process of subclassing your window"
sMsg = sMsg & " in order to catch commands which are passed by the Windows OS"
sMsg = sMsg & " to the windows which have created owner drawn menus." & vbCrLf & vbCrLf
sMsg = sMsg & "The COwnMenu object encapsulates the process of drawing each menu"
sMsg = sMsg & " entry and the OMenu_h code module manages a list of COwnMenu"
sMsg = sMsg & " objects which represent each menu entry that has been registered"
sMsg = sMsg & " as an owner drawn menu."

lblKalInfo.Caption = sMsg
End Sub

Private Sub Form_Load()
'// Initialize our menu objects
InitMenus

'// Set a subclass on this window so that we can process
'// requests to draw our owner drawn menus
SetSubclass Me

'// Show information about this program
ShowInfo
End Sub


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'// Free the memory allocated by creating our owner drawn menus
FreeMenus
End Sub



Private Sub lblKFiles_Click()
'// Log on to the K Files web page at "http://members.aol.com/KalaniCOM"
ShellExecute 0, "open", "http://www.calcoast.com/kalani/", vbNullString, vbNullString, SW_MAXIMIZE
End Sub


Private Sub lblKFiles_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
lblKFiles.ForeColor = RGB(255, 0, 0)
End Sub


Private Sub lblKFiles_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
lblKFiles.ForeColor = RGB(0, 0, 255)
End Sub


---------------------------------------

which I want to paste into notepad and save a a form and import into vbproject as a form.  However when I in port it , it is displayed as a module.  I do as follows.

copy code to notepad.
Clik on file/saveas..... type in frmOwnMenu.frm in the name field and select all files in the type field.  I go to my project and click on add form.  I specify my frmownmenu.frm form (which appears as a form file and its proprties stae it is so).  When I add it it is put as  a module.

It probably sees it still as a text file as I was told by another expert.  So How do I change it to a vb form for definite.

PLease help

regards
Botch



0
Comment
Question by:Botch
  • 5
  • 4
  • 2
  • +4
15 Comments
 
LVL 1

Expert Comment

by:mcbeth
Comment Utility
this won't work cause you need a second file : frmOwnMenu.frx where icons are placed.

you can paste this code into notepad and save it as form2.frm
then you can load it into your vb project but you'll get an error because you don't have the frmOwnMenu.frx file
0
 

Expert Comment

by:evelyne
Comment Utility
I try on my computer, I Save the texte with notepad as frmownmenu.frm.
I open a project and add then file
It's work. He ask for frmownmenu.frx (graphics and icons), but the form is loaded.

Be sure the name of your file is not frmOwnMenu.frm.txt Hope you find.
0
 

Author Comment

by:Botch
Comment Utility
Hi all
How do I see if there is a .txt for my file.  I looked at the properties and it states it is

frmOwnMenu
type: visual basic form file

Vb must still think it is a txt file.  Is there a way of opem=ning the file or any file as a vb form

regards
botch
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
You may have to rename the file since Notepad, by default, will add a .txt extension.  If your system is set to hide extensions, you may not see it.

When you do your save in notepad, enclose the name in double-quotes.
0
 
LVL 8

Expert Comment

by:glass_cookie
Comment Utility
Hi!

The worst you can do is to load a new form file, paste the codes, save it.  Then, replace whatever there is in the txt file into the new form file in terms of the controls or whatever.

On the other hand, regarding the ranaming part of your .txt file, make sure that your windows explaorer DOES NOT hide file extentions for known file types or else you can add all the .frm you want to th file and it's still a text file.

That's it!

glass cookie : )
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Correct about the hidden extensions, glass_cookies.  I was going to mention it but wanted to also mention how, so here it is:

* Open Windows Explorer (right-click [Start] and pick Explore)
* Select menu Tools | Folder Options...
* Click the View tab
* Uncheck the entry for "Hide file extensions for known file types"

While you're there, you may want to review some of the other options, like "Display the full path in the title bar"

* Click [OK]

Now all files should show with the actual extension.  You may find a file such as

   myform.frm.txt

This should be renamed by:

* right-click the file
* select Rename
* remove the .txt from the end
* press enter

You now have a properly named VB form (rather than a textfile containing VB form information.)
0
 

Author Comment

by:Botch
Comment Utility

Hi all
I still could not get the form to create using notepad an dI have spent enought time on it already.  I then just created a form from scratch in the vb environment and dragged the controls manually onto the form and set their properites.  I have it working now,,, ie changin gthe font of the menu.

I did try to save the notepad file sing the double quotse but to no avail.  The file was also deffinitely not being saved as .frm.txt.  It is being displayed as a .frm file.  

I am going to have a go at tit tonight on my home computer to see if it is a bug on my vb program.  I finish the question tomorrow.

REgards
Botch
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 22

Accepted Solution

by:
rspahitz earned 50 total points
Comment Utility
As with evelyne, I copied and pasted into notepad, and saved as "test1.frm"

i started a new project and did a Project|Add Form, and it loaded fine except for the error message pointing to a log file (test1.log) which indicates that the various pictures/icons are missing.

--
Sometimes I see form-loading problems that are related to the .vbp

Why not try the above to see if the problem is in the form.  If not, it's likely to be in the project, in which case you probably want to create a new project, throw away the default form, then add all the pieces back, including all forms, modules, classes, user controls and non-default components (tool objects) and references.  You may also need to update the project properties.

0
 
LVL 3

Expert Comment

by:modder
Comment Utility
Botch

Please finalise this question, even if nobody gave you a satisfactory answer - in that case just let me know and I will be happy to refund your points to you.

If someone did give you a satisfactory answer, please accept the comment as the answer. If you are having problems doing that let me know.

Please do *not* ignore this request. To the other participants in the thread - if no response is forthcoming alert me and I will take action.

Regards

modder
Community Support Admin
0
 

Author Comment

by:Botch
Comment Utility
Nothing I have tried has worked wheather I am doing something wrong or my vb6 software is acting up a bit.  I am going to scrap the idea and do it a different way.  None of the comments kave worked for me even though some of the comments are similar and have worked for others.  The points don't really matter to me so someone can delete the question.  Sorry it has been there so long.  I was hopeing a new comment may be added.  Thanks for the advice Modder
regards Botch
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi Botch,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

Botch, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Author Comment

by:Botch
Comment Utility
Hi all
Forgat all about this problem.  I do remember though that it just wouldn't work for me.  I have no problem giving the points to the choice of any of the experts.   I actually think it might have sometghing to do with the version I had on my computer at the time.  Currently working on project so have no time to look into it further.
regards
Botch
p.s--sorry if I have annoyed any1 with the long delay.
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Botch,
If you want to award points, select one of the above comments as an answer (DO NOT AWARD A C GRADE).  Thanks.
-- Dan
0
 

Author Comment

by:Botch
Comment Utility
Thanks for the help every1.  I think rspahitz suggestioin is probably the best coarse of action for me to take.  Thanks again for all the help
regards
Botch
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Thanks for the "A".
I hope the info is useful in the future if you run into a similar problem.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now