Recent

Author Topic: A few questions about Windows Mobile  (Read 14389 times)

mikaelo

  • New Member
  • *
  • Posts: 18
A few questions about Windows Mobile
« on: September 21, 2007, 11:44:10 pm »
A few thing I haven't been able to figure out:

1 . OK i have my environment set up and can build small sample apps however as I mentioned in the last thread, the resulting executables are in serious need of stripping, but I cant seem to find anyway to do this.

2.  Hitting [X] hides the window/app but clicking on the application again, makes it start a second instance. Can we use code like in Win32 (semaphore) to to avoid multiple instances? if we have changed the [X] behavior, maybe we need to add in the single instance code into the framework as well?

3. softbuttons /sip . Once I start an application i get the bottom toolbar with the SIP button in the middle, but does anyone know how to add the soft buttons on either side?

4. one the [X] have been hit and if I switch to the application using a task manager supplied with my phone (HTC) the SIP doesn't show either.

EDIT: I found that by creating a main menu with 2 items I got the soft buttons working and once the menu was there, the SIP behavior fixed it self too ;). So item 3 and 4 is taken care of.
Rather than deleting them I leave them here for the next person running into this.


In case anyone wonders, this is running on Window Mobile 6


Thanks in advance
Mikael

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: A few questions about Windows Mobile
« Reply #1 on: September 22, 2007, 12:54:13 am »
Quote from: "mikaelo"
2.  Hitting [X] hides the window/app but clicking on the application again, makes it start a second instance. Can we use code like in Win32 (semaphore) to to avoid multiple instances? if we have changed the [X] behavior, maybe we need to add in the single instance code into the framework as well?


This is the correct behavior for the X button under wince, as determined by microsoft guidelines.

About single instance, that's a common task. I'm sure there is something on the free pascal libraries that implements this cross-platform, but I've never used it so I wouldn't know.

I would try searching this forum. If you don't find anything and noone else answers this on the near future then I would try asking on the Free Pascal mailling list. People there will certainly have an answer.

In the worse can you can just use the Windows API =) I remember vaguely using WaitForMultipleObject or similar to do this.

Legolas

  • Full Member
  • ***
  • Posts: 117
    • http://itaprogaming.free.fr
RE: Re: A few questions about Windows Mobile
« Reply #2 on: September 22, 2007, 01:30:19 am »
In fact in windows CE [X] button minimizes the application. The [ok] button should close the application, like stated here:
http://msdn2.microsoft.com/en-us/library/bxz0e21k.aspx

bobix

  • Jr. Member
  • **
  • Posts: 71
    • http://rechnik-bg.com
Re: A few questions about Windows Mobile
« Reply #3 on: September 22, 2007, 02:40:00 pm »
Quote
1 . OK i have my environment set up and can build small sample apps however as I mentioned in the last thread, the resulting executables are in serious need of stripping, but I cant seem to find anyway to do this.


download UPX from here:
http://upx.sourceforge.net/
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64

mikaelo

  • New Member
  • *
  • Posts: 18
Re: A few questions about Windows Mobile
« Reply #4 on: September 23, 2007, 11:34:04 pm »
1. I never objected to the minimize of the app on [X], simply brought it up to lead to my question about single instancing.

I did find a sample on a blog posting:

var hExisting: THandle;
begin // main loop
   hExisting := FindWindow('sApplicationClass,nil);
   if hExisting<>0 then begin
      SetForegroundWindow(hExisting);
      Halt(1);
   end;
     
but as the application class for lazarus apps always seem to be 'Window' you need to combine this with the main form title like:

var hExisting: THandle;
begin // main loop
   hExisting := FindWindow('Window', 'Form1');
   if hExisting<>0 then begin
      SetForegroundWindow(hExisting);
      Halt(1);
   end;
     
this assumes the form title stays fixed.

is there otherwise a way to change the application class name?

2.
Quote from: "bobix"


download UPX from here:
http://upx.sourceforge.net/


Using upx in a memory limited environment like WM, seem to me to be of negative values as it forces you to load the entire executable into memory including all resources which in a regular executable would be loaded on demand.

btw I did find the included strip command, bringing down the file seize to 1.2mb  from close to 11

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: Re: A few questions about Windows Mobile
« Reply #5 on: September 24, 2007, 12:06:48 am »
I did a quick search and there is a component for unique instance here:

http://sourceforge.net/project/showfiles.php?group_id=92177&package_id=215290

The wiki seams temporarely offline, but as soon as it's back there are docs here:

http://wiki.lazarus.freepascal.org/UniqueInstance

This probably wasn't tested on wince yet, so it may or may not work out of the box.

Zaher

  • Hero Member
  • *****
  • Posts: 679
    • parmaja.org
RE: Re: A few questions about Windows Mobile
« Reply #6 on: September 24, 2007, 12:45:47 am »
I use one instance like as in my project unit, worked good, but be sure the main form have the same caption (I used mine 'MPOS'), but for test at Win32 make the caption of main form same at run time, and at design time change it to any caption else.

Code: [Select]

procedure Run;
var
  hWnd:THandle;
begin
   hWnd := FindWindow('Window', 'MPOS');
   if hWnd <> 0 then
   begin
     SetForegroundWindow(hWnd);
   end
   else
   begin
     Application.Initialize;
     Application.Title := 'Mobile POS';
     Application.CreateForm(TMainForm, MainForm);
     Application.Run;
   end;
end;

begin
  Run;
end.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2582
Re: RE: Re: A few questions about Windows Mobile
« Reply #7 on: September 24, 2007, 11:33:43 am »
Quote from: "Legolas"
In fact in windows CE [X] button minimizes the application. The [ok] button should close the application, like stated here:
http://msdn2.microsoft.com/en-us/library/bxz0e21k.aspx


That page describes the smart minimize feature, but imo, it is still up to the programmer what happens. I've seen several games for pocket PC where the
  • closes the app. Something I think should be an option for lazarus apps too.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

roeug

  • Jr. Member
  • **
  • Posts: 67
    • http://roeug.50megs.com/
One instance
« Reply #8 on: November 07, 2007, 01:34:09 pm »
in lpr:

...
uses...
 you can add units after this }, Unit1, Unit2,
 windows; //!

const
  MemFileSize = 1024;
  MemFileName = 'one_inst_TST';
var
 MemHnd : HWND;
begin
 MemHnd := CreateFileMapping(HWND($FFFFFFFF),nil,
       PAGE_READWRITE, 0, MemFileSize, MemFileName);
 if GetLastError<>ERROR_ALREADY_EXISTS then begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
 end;
 CloseHandle(MemHnd);
end.

The only thing U have to (if U want)  is to show the previous instance ;)

roeug

  • Jr. Member
  • **
  • Posts: 67
    • http://roeug.50megs.com/
One instance + activate previous
« Reply #9 on: November 08, 2007, 10:57:38 am »
Try it (in .lpr) :
Some misbehavior with multiform apps



  { you can add units after this }, Unit1, Unit2,
  windows;

const
  MemFileSize = 1024;
  MemFileName = 'one_inst_TST';
var
 MemHnd, MainFormHnd : HWND; // DWord;
 FFileView: Pointer;
begin
 MemHnd := CreateFileMapping(HWND($FFFFFFFF),nil, PAGE_READWRITE, 0, MemFileSize, MemFileName);
 if GetLastError<>ERROR_ALREADY_EXISTS then begin
  FFileView:=nil;
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  MainFormHnd:= Form1.Handle;
// Write Handle of MainForm to the file
  FFileView := MapViewOfFile(MemHnd,FILE_MAP_ALL_ACCESS,0,0,0);
  if FFileView <> nil then begin
   CopyMemory( FFileView, @MainFormHnd, 4);
   UnmapViewOfFile(FFileView);
  end;
  Application.CreateForm(TForm2, Form2);
  Application.Run;
 end
 else begin
// Read Handle of MainForm from the file created by previous instance
  FFileView := MapViewOfFile(MemHnd,FILE_MAP_READ,0,0,0);
  CopyMemory( @MainFormHnd, FFileView, 4);
  SetForegroundWindow(MainFormHnd); // activate previous
 end;
 CloseHandle(MemHnd);
end.

 

TinyPortal © 2005-2018