Link to home
Start Free TrialLog in
Avatar of hjaycox
hjaycox

asked on

KILL a command BUTTON

in vb5, after the" program.exe" is run for the FIRST time, I want to kill and TOTALLY ELIMINATE a command button.
This will be in an EXE form, so the coding must be internal. It will be necessary for this command button to NEVER REAPPEAR again.
ASKER CERTIFIED SOLUTION
Avatar of fujicast
fujicast

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yowkee
yowkee

There's a way:

---
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

' Eliminate button "command2"
Private Sub Command1_Click()
    Dim lRtn As Long
    ' If succeed, lRtn <> 0
    lRtn = DestroyWindow(Command2.hwnd)
End Sub


you meen like have it appear the 1st time it is run, and never appear again?
Avatar of hjaycox

ASKER

yowkee
There is only ONE button on the form. Changing your code to IRtn = destroywindow(command1.hwnd) generates
runtime error 453... can't find dll entry point....
Now what?


kewl
yep that is exactly what I want ... Got any Ideas ???
hjaycox,

  Do you declare Destroywindow at the right place? You could use your API viewer to cut and paste the declaration at the place you want it be.

Or, try this

' Put private in front if you declare it in a Form module
Private Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Long) As Long
Avatar of hjaycox

ASKER

Sorry yowkee I still get the same Error. I put the privat declare into the module and the rest of the coding into the command1-click.   Where do I go from here ??????? Yor answer will have to be very explect thanks.
hjaycox,

  I may have forgotten some things. :) What version of VB do you use(16 or 32 bits)? Which platform you are developing your app?
Avatar of hjaycox

ASKER

I am using vb5 32bit enterprise BETA edition in the standard exe platform, for this project..
 I also have vb4,  16 and 32 bit that I can use.
hope this helps
thanks

hjaycox,

  It is strange. However, I am not sure is there any restriction for using VB5 enterprise beta. It should have no problem to call an API. The error "Dll entry not found!" means that VB could not find the function DestroyWindow in user32.dll. But it was a standard API and exist in user32.dll. If you have dumpbin.exe, do a "dumpbin /exports user32.dll" will show all export functions in this dll and you will see the function there.

  Or you may try using VB4 32bits version. And try specify the full name of user32.dll instead of "user32" (of course, this file is in your windows system directory).

  If it still not working, you could mail your test project to me if you wish. I could reach at yowkee@yahoo.com.

  Regards.
hjaycox,

   Why you accept the answer without comment? Did you really accept the proposed answer? Didn't mine one work? It really make one frustrated after spending time to deal with it.
Avatar of hjaycox

ASKER

I emailed you the program and paid you in advance
Avatar of hjaycox

ASKER

yowkee... Thank yopu for your response.  There is one little problem. I guess my original guestion was on the vague side.
This Command button needs to be destroyed,  in an Exe. program.

The second time the Exe. program is run , this Command Button MUST NOT be there. Or any time thereafter.

If more points are needed , I'll gladly pay. Thanks in advance
Hi hjaycox,

  My previous answer for question is specified for *destroy and release* memory used by button. That's why we use API destroywindow.

  In the case you want the button don't appear any more, you must have some flag which stored some place for checking. For example you save a flag "NoButton" in registry and at each time your program start, you could check the flag to determine whether you want to show the button or not. Yes, I mean you must hide or set command1.Visible = False. You could still use DestroyWindow to destory command button but you must set its visible property to false first. Then it won't show out before it's being showed.

   The other way to do this is create another similiar form just didn't have that button. At your app startup module, check which form you need to load according to one flag.

   There is simple function to save and get information to registry. Use SaveSetting and GetSetting in VB5.

   Please let me if you need further info. :)

   Regards.

 
Avatar of hjaycox

ASKER

This is really STUPID... What is the apps 'STARTUP MODULE'.

Is that the module.bas in the program?

I have checked out the SaveSetting and GetSetting and I think I understand them.

thanks
hjaycox,

  What I mean 'Startup module' is where you start your app. Either 'Sub Main' in a BAS module or Form_Load event in a main form. If the form you want to implement the button destroying is the main form. Then probably you place your checking code in its Form_Load or change your app start in Sub Main and place checking  in Sub Main before loading form.

  Regards.
Avatar of hjaycox

ASKER

Thank you Very much..... thanks