Recent

Author Topic: WinCE Api Window creation problem  (Read 7508 times)

shadowmas

  • Newbie
  • Posts: 3
WinCE Api Window creation problem
« on: February 06, 2007, 09:34:21 pm »
Hello,

I tried creating a window using CreateWindow API with the lazurus wince binary download by CCRDude but for some reason it doesnt work. What actually seems to be happenning is that the window gets created and the window title gets displayed in next to the start button (testing on the Windows mobile 5 emulator) however rest of the screen doesnt seem to be painting the window.

I'm guessing this is a problem with my code because a normal form application seems to work and show the form.

Could someone check the following code and tell me if there is a problem.

Code: [Select]

program project1;

{$mode objfpc}{$H+}

uses
   windows;


function MyWndProc(hWnd:HWND; uMsg: UINT; lParam : LPARAM; wParam : WPARAM ):LONGINT;
begin
     MyWndProc:=DefWindowProc(hWnd, uMsg, wParam, lParam);
end;

procedure registerwindowclass();
var
   wndclass : TWndClass;
begin
     wndclass.style := CS_HREDRAW or CS_VREDRAW;
     wndclass.lpfnWndProc := @MyWndProc; // window procedure: mandatory
     wndclass.cbClsExtra := 0;
     wndclass.cbWndExtra := 0;
     wndclass.hInstance := HINSTANCE;         // owner of the class: mandatory
     wndclass.hIcon := 0;
     wndclass.hCursor := 0;
     wndclass.hbrBackground := HBRUSH(COLOR_WINDOW+1);
     wndclass.lpszMenuName := nil;
     wndclass.lpszClassName := 'MAS_TEST_FORM'; // mandatory
     if RegisterClass(@wndclass)=0 then
        MessageBox(0,'Window Resgistration Failed','Error',0);
end;

var
  handle:HWND;
  msg:tagMSG;
begin
     RegisterWindowClass();

     handle:=CreateWindow('MAS_TEST_FORM', 'test', WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HInstance, nil);
     if handle=0 then
     begin
        MessageBox(0,'Window Creation failed','Error',0);
     end;

     while GetMessage (@msg, 0, 0, 0) do
           DispatchMessage (@msg);
end.


P.S. i translated this from a working C++ code so i can't figure out what is wrong.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2584
RE: WinCE Api Window creation problem
« Reply #1 on: February 07, 2007, 11:58:40 am »
Don't know if this is the problem, but as a general rule of thumb, when using callbacks from external libs, use stdcall or cdecl
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

shadowmas

  • Newbie
  • Posts: 3
RE: WinCE Api Window creation problem
« Reply #2 on: February 07, 2007, 12:14:38 pm »
Tried both for one it doesn't compile and for the other there is no change.

shadowmas

  • Newbie
  • Posts: 3
RE: WinCE Api Window creation problem
« Reply #3 on: February 07, 2007, 02:56:20 pm »
Ok found the problem. Silly me i have swapped the lparam and wparam when calling the DefWindowProc :

Code: [Select]

function MyWndProc(hWnd:HWND; uMsg: UINT; lParam : LPARAM; wParam : WPARAM ):LONGINT;
begin
     MyWndProc:=DefWindowProc(hWnd, uMsg, wParam, lParam);
end;

 

TinyPortal © 2005-2018