⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plx_alwnd.c

📁 mtk wap和mms代码。。适应mtk 25。26平台
💻 C
字号:
/***************************************************************************
*
*                      Pollex Mobile Platform
*
*  Copyright (c) 2004 by Pollex Mobile Software Co., Ltd.
*                       All Rights Reserved
*
*  Module  : Pollex Adaption Layer
*
*  Purpose :
*  
\**************************************************************************/

#include "window.h"
#include "TimerEvents.h"
//#include "kal_non_specific_general_types.h"


extern void Trace(char *fmt,...);
/**************************************************************************/
/*                  Internal function prototypes & definition             */
/**************************************************************************/

static int inter_stricmp(const char* dst, const char* src)
{
    int f,l;
    
    do 
    {
        if (((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z'))
            f -= ('A' - 'a');
        
        if (((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z'))
            l -= ('A' - 'a');
    } while (f && (f == l));
    
    return (f - l);
}
/*********************************************************************
* Function	   
* Purpose      
* Params	   
* Return	 	   
* Remarks	   
**********************************************************************/
static char * inter_strcpy( char *strDest, const char *strSour )
{
    char *p = strDest;
    while ( *strSour != 0 )
        *p++ =  *strSour++;
    *p = 0;
    return strDest;
}
/**************************************************************************/
/*                  Window Object Management                              */
/**************************************************************************/

typedef struct tagWINOBJ
{
    WNDPROC     pfnWndProc;     // 窗口对应的窗口函数
} WINOBJ, *PWINOBJ;

#define MAX_WIN_OBJS 32
static  WINOBJ WinObjs[MAX_WIN_OBJS];

static PWINOBJ AllocWindowObj(void)
{
    int i;

    for (i = 0; i < MAX_WIN_OBJS; i++)
        if (WinObjs[i].pfnWndProc == NULL)
            return &WinObjs[i];

    return NULL;
}

static BOOL FreeWindowObj(PWINOBJ pWin)
{
    if ((pWin < &WinObjs[0]) || (pWin > &WinObjs[MAX_WIN_OBJS - 1]))
        return FALSE;
    
    pWin->pfnWndProc = NULL;
    return TRUE;
}

/**************************************************************************/
/*                  Class Register & Unregister API                       */
/**************************************************************************/
#define PLX_CLASSNAME_LEN    32
typedef struct tagCLSOBJ
{
    char pszClassName[PLX_CLASSNAME_LEN];
    WNDPROC pfnWndProc;
}CLSOBJ, *PCLSOBJ;

#define MAX_CLASS_OBJS 32
static CLSOBJ ClsObjs[MAX_CLASS_OBJS];

static PCLSOBJ AllocClassObj(const char *pszClassName)
{
    int i;
    int index = -1;
    
    for (i = 0; i < MAX_CLASS_OBJS; i++) {
        if ( ClsObjs[i].pfnWndProc != NULL ) {
            if(!inter_stricmp(ClsObjs[i].pszClassName, pszClassName))
                return NULL;
        }else {
            if ( index == -1 )
                index = i;
        }
    }
    if ( index == -1 )
        return NULL;
        
    return &ClsObjs[index];
}

static BOOL FreeClassObj(const char* pszClassName)
{
    int i;
    
    for (i = 0; i < MAX_CLASS_OBJS; i++)
    {
        if (!inter_stricmp(ClsObjs[i].pszClassName, pszClassName))
            break;
    }

    if (i == MAX_CLASS_OBJS)
        return FALSE;

    ClsObjs[i].pfnWndProc = NULL;

    return TRUE;
}

static PCLSOBJ GetClassObj(const char* pszClassName)
{
    int i;

    for (i = 0; i < MAX_CLASS_OBJS; i++)
    {
        if (!inter_stricmp(ClsObjs[i].pszClassName, pszClassName))
            return &ClsObjs[i];
    }

    return NULL;
}

/****************************************************************************
**  Function : RegisterClass
**  Purpose  : Registers a window class for subsequent use in calls
**             to the CreateWindow function. 
**  Params   :
**      pWndClass : Points to a WNDCLASS structure. It must be filled
**                  with the appropriate class attributes before 
**                  passed to the function. 
**  Return   :
**      If the function succeeds, the return value is TRUE. Otherwise, 
**      the return value is FALSE. To get extended error information, 
**      call GetLastError. 
*****************************************************************************/
BOOL PlxRegisterClass(const WNDCLASS* pWndClass)
{
    PCLSOBJ pClsObj;
    
    if (!pWndClass)
        return FALSE;
    
    if (!pWndClass->lpfnWndProc || !pWndClass->lpszClassName)
        return FALSE;

    pClsObj = AllocClassObj(pWndClass->lpszClassName);
    if (!pClsObj)
        return FALSE;

    pClsObj->pfnWndProc = pWndClass->lpfnWndProc;
    inter_strcpy(pClsObj->pszClassName, pWndClass->lpszClassName );
//    pClsObj->pszClassName = pWndClass->lpszClassName;
    
    return TRUE;
}

/*****************************************************************************
**  Function : UnregisterClass
**  Purpose  :
**      Removes a window class, freeing the memory required for the 
**      class.
**  Params   :
**      pszClassName : Specifies the window class name. This class 
**                     name must have been registered by a previous
**                     call to the RegisterClass function.
**  Return   :
**      If the function succeeds, the return value is TRUE. If the 
**      class could not be found or if a window still exists that 
**      was created with the class, the return value is FALSE. To 
**      get extended error information, call GetLastError.
***************************************************************************/
BOOL PlxUnregisterClass(PCSTR pszClassName, HINSTANCE hInst)
{
    if (!pszClassName)
        return FALSE;
    
    return FreeClassObj(pszClassName);
}

/**************************************************************************/
/*                  Window Create & Destroy API                           */
/**************************************************************************/



/****************************************************************************
**  Function : CreateWindowEx
**  Purpose  :
**      Creates an overlapped, pop-up, or child window with an extended 
**      style; otherwise, this function is identical to the CreateWindow 
**      function. 
*******************************************************************************/
HWND PlxCreateWindowEx(DWORD dwExStyle, PCSTR pszClassName, 
                           PCSTR pszWindowName, DWORD dwStyle, 
                           int x, int y, int nWidth, int nHeight, 
                           HWND hwndParent, HMENU hMenu, 
                           HINSTANCE hInstance, PVOID pParam)
{
    PWINOBJ pWin;
    PCLSOBJ pClsObj;
    CREATESTRUCT cs;

    if (!pszClassName)
        return NULL;

    pWin = AllocWindowObj();
    if (!pWin)
        return NULL;

    pClsObj = GetClassObj(pszClassName);
    if (!pClsObj)
        return NULL;

    pWin->pfnWndProc = pClsObj->pfnWndProc;

    cs.dwExStyle        = dwExStyle;
    cs.lpszClass        = pszClassName;
    cs.lpszName         = pszWindowName;
    cs.style            = dwStyle;
    cs.x                = x;
    cs.y                = y;
    cs.cx               = nWidth;
    cs.cy               = nHeight;
    cs.hwndParent       = hwndParent;
    cs.hMenu            = hMenu;
    cs.hInstance        = hInstance;
    cs.lpCreateParams   = pParam;

    pWin->pfnWndProc((HWND)pWin, WM_CREATE, 0, (LPARAM)&cs);

    return (HWND)pWin;
}
/***************************************************************************
**  Function : CreateWindow
**  Purpose  :
**      Creates an overlapped, pop-up, or child window. It specifies 
**      the window class, window title, window style, and (optionally) 
**      the initial position and size of the window. The function also 
**      specifies the window's parent or owner, if any, and the window's 
**      menu. 
**  Params   :
**
**  Return   :
**      If the function succeeds, the return value is the handle to the
**      new window. If the function fails, the return value is NULL. To 
**      get extended error information, call GetLastError.
************************************************************************/
HWND PlxCreateWindow(PCSTR pszClassName, PCSTR pszWindowName, 
                         DWORD dwStyle, int x, int y, int width, 
                         int height, HWND hwndParent, HMENU hMenu, 
                         HINSTANCE hInstance, PVOID pParam)
{
    return PlxCreateWindowEx(0, pszClassName, pszWindowName, dwStyle, x, y,
        width, height, hwndParent, hMenu, hInstance, pParam);
}
/****************************************************************************
**  Function : DestroyWindow
**  Purpose  :
**      Destroys the specified window. The function sends WM_DESTROY and 
**      WM_NCDESTROY messages to the window to deactivate it and remove 
**      the keyboard focus from it. The function also destroys the window's 
**      menu, destroys timers. 
**      If the specified window is a parent or owner window, DestroyWindow 
**      automatically destroys the associated child or owned windows when 
**      it destroys the parent or owner window. The function first destroys 
**      child or owned windows, and then it destroys the parent or owner 
**      window. 
**  Params   :
**      hWnd : Specifies the window to be destroyed.
**  Return   :
**      If the function succeeds, the return value is nonzero. 
**      If the function fails, the return value is zero. To get extended 
**      error information, call GetLastError. 
*****************************************************************************/
BOOL PlxDestroyWindow(HWND hWnd)
{
    PWINOBJ pWinObj;

    if ( hWnd == NULL )
        return FALSE;

    pWinObj = (PWINOBJ)hWnd;

    pWinObj->pfnWndProc(hWnd, WM_DESTROY, 0, 0);

    return FreeWindowObj((PWINOBJ)hWnd);
}

/*********************************************************************
* Function	   
* Purpose      
* Params	   
* Return	 	   
* Remarks	   
**********************************************************************/

BOOL PlxIsWindow( HWND hWnd )
{
    BOOL iswin = 0;
    if ( hWnd >= (HWND)&WinObjs[0] && hWnd <= (HWND)&WinObjs[MAX_WIN_OBJS-1] )
        iswin = TRUE;
    return iswin;
}
/*
**  Function : DefWindowProc
**  Purpose  :
**      Calls the default window procedure to provide default processing 
**      for any window messages that an application does not process. 
**      This function ensures that every message is processed. DefWindowProc 
**      is called with the same parameters received by the window procedure. 
**  Params   :
**      hWnd    : Identifies the window procedure that received the message. 
**      wMsgCmd : Specifies the message. 
**      wParam  : Specifies additional message information. The content of 
**                this parameter depends on the value of the Msg parameter. 
**      lParam  : Specifies additional message information. The content of 
**                this parameter depends on the value of the Msg parameter. 
**  Return   :
**      The return value is the result of the message processing and depends
**      on the message. 
*/
LRESULT PlxDefWindowProc(HWND hWnd, UINT wMsgCmd, WPARAM wParam, 
                             LPARAM lParam)
{
    return 0L;
}

/*********************************************************************\
* Function	   
* Purpose      
* Params	   
* Return	 	   
* Remarks	   
**********************************************************************/
LRESULT PlxSendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT result;
    WNDPROC pfnWndProc;

    if ( hWnd == NULL )
        return -1;

    pfnWndProc = ((PWINOBJ)hWnd)->pfnWndProc;
    result = (*pfnWndProc)(NULL, Msg, wParam,  lParam);
    return result;
}


/**************************************************************************/
/*                  Message Mechanism API                                 */
/**************************************************************************/

/*
**  Function : PostMessage
**  Purpose  :
**      Places (posts) a message in the message queue associated with the 
**      thread that created the specified window and then returns without 
**      waiting for the thread to process the message. Messages in a 
**      message queue are retrieved by calls to the GetMessage function. 
**  Params   :
**      hWnd    : Identifies the window whose window procedure is to 
**                receive the message.
**      wMsgCmd : Specifies the message to be posted.
**      wParam  : Specifies additional message-specific information. 
**      lParam  : Specifies additional message-specific information. 
**  Returns  :
**      If the function succeeds, the return value is TRUE.
**      If the function fails, the return value is FALSE. To get extended
**      error information, call GetLastError. 
*/    
/*
BOOL PostMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

    PPLXMSG pMsg;
    
    pMsg = mp_alloc(sizeof(MSG));
    if (pMsg == NULL)
        return FALSE;

    pMsg->hwnd = hWnd;
    pMsg->message = message;
    pMsg->wParam = wParam;
    pMsg->lParam = lParam;

    AMS_MBOX_medp_message_send(MP_POLLEX, pMsg);

    return TRUE;
}
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -