Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_SYSCOMMAND works from WinControl but not ActiveX

Status
Not open for further replies.

MilesAhed

Programmer
Jul 16, 2008
14
US
I'm a bit baffled. I wrote a "single instance" TWinControl
in which the secondary instance of a program passes info to the first instance(such as command tail etc.) and also sends a message to restore the first program instance's main form.
The restore code is:

SendMessage(MainHandle, WM_SYSCOMMAND, SC_RESTORE, 0);
SetForegroundWindow(MainHandle);

The first program instance stores Application.Handle in a memory mapped file that the instance control uses to pass data. (In code prior to what I've shown, I copy the Handle value from the memory mapped file to the local variable "MainInstance".)Here's the part I can't figure out. If I use a component or TWinControl with the above 2 lines, they work perfectly. However, when I convert my TWinControl into an ActiveX Control(.ocx) using the Delphi 5 wizard, I get nadda! It's really strange!! The ActiveX Control method just reflects into the TWinControl code which works if it's not wrapped up in an ActiveX.

I can come up with a work-around but it would be much neater if the .ocx did it all "automatically" instead of through an event handler supplied by the application programmer.

 
Guess ocx is like dll. Application.Handle is 0. I tried messing around with IOleInPlaceSite and then said to hell with it!! I cheated and coded another method and just passed in the handle. If calling through the ActiveX you have to use the new method if you want the main form in the first instance restored. Way simpler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top