 |
|
|
|
| Author |
Message |
knopper
Joined: 15 Aug 2007 Posts: 28
|
Posted: Fri Feb 22, 2008 10:57 am Post subject: load icon in dll file not work ?! |
|
|
we have to write a module with icon and system tray on pocket pc (WM6). Whan
i start the module as exe file. All icon can loaded, but when i compile the
module as dll file and loaded in main exe app, the icons will not appear.
I have tried to pass the hInstance from main process to loadIcon function
but no result. My question it is possible to load icon in dll file generally ?
Archived from group: microsoft>public>pocketpc>developer |
|
| Back to top |
|
 |
Scott Seligman
Joined: 15 Aug 2007 Posts: 111
|
Posted: Fri Feb 22, 2008 2:15 pm Post subject: Re: load icon in dll file not work ?! |
|
|
=?Utf-8?B?a25vcHBlcg==?= wrote:
>
>we have to write a module with icon and system tray on pocket pc (WM6). Whan
>i start the module as exe file. All icon can loaded, but when i compile the
>module as dll file and loaded in main exe app, the icons will not appear.
>I have tried to pass the hInstance from main process to loadIcon function
>but no result. My question it is possible to load icon in dll file generally ?
Yes, it's possible to load an icon from a DLL.
If you'd like some more help, post code that's failing.
--
--------- Scott Seligman and michelle dot net> ---------
Anger is the most useless emotion, .. destructive to the mind and
hurtful of the heart.
-- Henchick in Dark Tower, Song of Susannah by Stephen King |
|
| Back to top |
|
 |
knopper
Joined: 15 Aug 2007 Posts: 28
|
Posted: Mon Feb 25, 2008 7:34 am Post subject: Re: load icon in dll file not work ?! |
|
|
Ok here are my code
//************ trayicon.Dll module***************//
#define TRAY_NOTIFYICON WM_USER + 2001
#define ID_TRAY 5000
#define ID_NOTIFY 6000
static const GUID guidPPCAlertsApp = { 0xca777af7, 0x3cde, 0x4c15, { 0xa7,
0xcd, 0x81, 0xf6, 0x29, 0xab, 0xa6, 0xb6 } };
//static const GUID guidPPCAlertsApp = { 0x33765136, 0x8cb9, 0x449a, { 0xb0,
0x20, 0x43, 0xed, 0x40, 0xa, 0xb8, 0xfc } };
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
HICON hTitleBarIcon;
BOOL APIENTRY DllMain (HANDLE hModule, DWORD reason, LPVOID reserved)
{
return TRUE;
}
DWORD WINAPI main_thread (LPVOID param)
{
WinMain(NULL, NULL, _T(""), 0);
return 0;
}
extern "C" __declspec(dllexport) int startmod (void *param) {
if (CreateThread(NULL, 0, main_thread, param, 0, NULL) == NULL) {
return -1;
}
return 0;
}
// Tray Icons and Notification
BOOL TrayMessage(
HWND hwnd,
DWORD dwMessage,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
BOOL res = FALSE;
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = hwnd;
tnd.uID = uID;
tnd.uFlags = NIF_MESSAGE|NIF_ICON;
tnd.uCallbackMessage = TRAY_NOTIFYICON;
tnd.hIcon = hIcon;
tnd.szTip[0] = '\0';
res = Shell_NotifyIcon(dwMessage, &tnd);
return res;
}
void TrayIconDelete(
HWND hwnd,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
TrayMessage(hwnd, NIM_DELETE, uID, hIcon, NULL);
}
void TrayIconModify(
HWND hwnd,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
//animate icons
TrayMessage(hwnd, NIM_MODIFY, uID, hIcon, NULL);
}
void TrayIconAdd(
HWND hwnd,
UINT uID,
HICON hIcon,
PTSTR pszTip
)
{
TrayMessage(hwnd, NIM_ADD, uID, hIcon, NULL);
}
void AddNotificationIcon(HWND hWnd,UINT uID,TCHAR *wndTittle, HICON hIcon)
{
SHNOTIFICATIONDATA Notification;
Notification.cbStruct = sizeof(SHNOTIFICATIONDATA);
Notification.dwID = uID;
Notification.npPriority = SHNP_INFORM;
Notification.csDuration = 1; // in second
Notification.hicon = hIcon;
Notification.clsid = guidPPCAlertsApp;
Notification.grfFlags = 0;
Notification.pszTitle = (LPCTSTR) wndTittle;
Notification.pszHTML = _T("module is ready"); // i can
see this popup but no icon ?!
Notification.hwndSink = hWnd;
Notification.rgskn[0].pszTitle = (LPCTSTR) wndTittle;
Notification.rgskn[0].skc.wpCmd = 1003;
Notification.rgskn[0].skc.grfFlags = NOTIF_SOFTKEY_FLAGS_HIDE;
SHNotificationAdd(&Notification);
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
#ifndef WIN32_PLATFORM_WFSP
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TRAYICON));
#endif // !WIN32_PLATFORM_WFSP
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
#ifndef WIN32_PLATFORM_WFSP
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
#endif // !WIN32_PLATFORM_WFSP
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
//TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; //hInstance; // Store instance handle in our global
variable
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// SHInitExtraControls should be called once during your application's
initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
LoadString(g_hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(g_hInst, IDC_TRAYICON, szWindowClass, MAX_LOADSTRING);
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the
foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
showdebug(L"Application alredy loaded");
return 0;
}
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
//set focus to foremost child window
//The "| 0x00000001" is used to bring any owned windows to the
foreground and
//activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
showdebug(L"Application alredy loaded");
return 0;
}
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
if (!MyRegisterClass(g_hInst, szWindowClass))
{
showdebug(L"could not register class");
return FALSE;
}
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
NULL, hInstance, NULL);
// hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
// 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
showdebug(L"could not create windows");
return FALSE;
}
#ifdef WIN32_PLATFORM_PSPC
// When the main window is created using CW_USEDEFAULT the height of the
menubar (if one
// is created is not taken into account). So we resize the window after
creating it
// if a menubar is present
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left,
rc.bottom-rc.top, FALSE);
}
#endif // WIN32_PLATFORM_PSPC
hTitleBarIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON1));
AddNotificationIcon(hParent,ID_NOTIFY,szTitle,hTitleBarIcon);
showdebug(L"AddNotificationIcon done"); // but no icon appear !
HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2));
TrayIconAdd(hParent, ID_TRAY,hIcon, NULL); // but no icon appear !
//ShowWindow(hWnd, SW_HIDE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//************in Main proccess exe file***************//
if( (hmodule= LoadLibrary(_T("trayicon.dll"))) == NULL)
{
showdebug(L"module not started.");
}
else
{
startmod = (module_icon)GetProcAddressA(hmodule, "startmod");
}
if (startmod) {
showdebug(L"module started."); // ok
startmod(NULL, 0);
}
I have tried to pass HWND and hInstance from main proccess to trayicon.dll,
but no success. what have i doing wrong ?
"Scott Seligman" wrote:
> =?Utf-8?B?a25vcHBlcg==?= wrote:
> >
> >we have to write a module with icon and system tray on pocket pc (WM6). Whan
> >i start the module as exe file. All icon can loaded, but when i compile the
> >module as dll file and loaded in main exe app, the icons will not appear.
> >I have tried to pass the hInstance from main process to loadIcon function
> >but no result. My question it is possible to load icon in dll file generally ?
>
> Yes, it's possible to load an icon from a DLL.
>
> If you'd like some more help, post code that's failing.
>
> --
> --------- Scott Seligman and michelle dot net> ---------
> Anger is the most useless emotion, .. destructive to the mind and
> hurtful of the heart.
> -- Henchick in Dark Tower, Song of Susannah by Stephen King
> |
|
| Back to top |
|
 |
knopper
Joined: 15 Aug 2007 Posts: 28
|
Posted: Mon Feb 25, 2008 10:05 am Post subject: Re: load icon in dll file not work ?! |
|
|
O i got it. I have to pass the resource icon from main process
"knopper" wrote:
> Ok here are my code
>
> //************ trayicon.Dll module***************//
>
> #define TRAY_NOTIFYICON WM_USER + 2001
> #define ID_TRAY 5000
> #define ID_NOTIFY 6000
> static const GUID guidPPCAlertsApp = { 0xca777af7, 0x3cde, 0x4c15, { 0xa7,
> 0xcd, 0x81, 0xf6, 0x29, 0xab, 0xa6, 0xb6 } };
>
> //static const GUID guidPPCAlertsApp = { 0x33765136, 0x8cb9, 0x449a, { 0xb0,
> 0x20, 0x43, 0xed, 0x40, 0xa, 0xb8, 0xfc } };
>
> // Global Variables:
> HINSTANCE g_hInst; // current instance
> HWND g_hWndMenuBar; // menu bar handle
> TCHAR szTitle[MAX_LOADSTRING]; // title bar text
>
> HICON hTitleBarIcon;
>
>
> BOOL APIENTRY DllMain (HANDLE hModule, DWORD reason, LPVOID reserved)
> {
> return TRUE;
> }
>
> DWORD WINAPI main_thread (LPVOID param)
> {
> WinMain(NULL, NULL, _T(""), 0);
> return 0;
> }
>
> extern "C" __declspec(dllexport) int startmod (void *param) {
> if (CreateThread(NULL, 0, main_thread, param, 0, NULL) == NULL) {
> return -1;
> }
> return 0;
> }
>
>
>
>
> // Tray Icons and Notification
>
> BOOL TrayMessage(
> HWND hwnd,
> DWORD dwMessage,
> UINT uID,
> HICON hIcon,
> PTSTR pszTip
> )
> {
> BOOL res = FALSE;
> NOTIFYICONDATA tnd;
>
> tnd.cbSize = sizeof(NOTIFYICONDATA);
> tnd.hWnd = hwnd;
> tnd.uID = uID;
> tnd.uFlags = NIF_MESSAGE|NIF_ICON;
> tnd.uCallbackMessage = TRAY_NOTIFYICON;
> tnd.hIcon = hIcon;
> tnd.szTip[0] = '\0';
>
> res = Shell_NotifyIcon(dwMessage, &tnd);
> return res;
> }
>
> void TrayIconDelete(
> HWND hwnd,
> UINT uID,
> HICON hIcon,
> PTSTR pszTip
> )
> {
> TrayMessage(hwnd, NIM_DELETE, uID, hIcon, NULL);
> }
>
> void TrayIconModify(
> HWND hwnd,
> UINT uID,
> HICON hIcon,
> PTSTR pszTip
> )
> {
> //animate icons
> TrayMessage(hwnd, NIM_MODIFY, uID, hIcon, NULL);
> }
>
> void TrayIconAdd(
> HWND hwnd,
> UINT uID,
> HICON hIcon,
> PTSTR pszTip
> )
> {
> TrayMessage(hwnd, NIM_ADD, uID, hIcon, NULL);
> }
>
>
> void AddNotificationIcon(HWND hWnd,UINT uID,TCHAR *wndTittle, HICON hIcon)
> {
> SHNOTIFICATIONDATA Notification;
>
> Notification.cbStruct = sizeof(SHNOTIFICATIONDATA);
> Notification.dwID = uID;
> Notification.npPriority = SHNP_INFORM;
> Notification.csDuration = 1; // in second
> Notification.hicon = hIcon;
> Notification.clsid = guidPPCAlertsApp;
> Notification.grfFlags = 0;
> Notification.pszTitle = (LPCTSTR) wndTittle;
> Notification.pszHTML = _T("module is ready"); // i can
> see this popup but no icon ?!
> Notification.hwndSink = hWnd;
> Notification.rgskn[0].pszTitle = (LPCTSTR) wndTittle;
> Notification.rgskn[0].skc.wpCmd = 1003;
> Notification.rgskn[0].skc.grfFlags = NOTIF_SOFTKEY_FLAGS_HIDE;
> SHNotificationAdd(&Notification);
>
> }
>
> int WINAPI WinMain(HINSTANCE hInstance,
> HINSTANCE hPrevInstance,
> LPTSTR lpCmdLine,
> int nCmdShow)
> {
> MSG msg;
>
> // Perform application initialization:
> if (!InitInstance(hInstance, nCmdShow))
> {
> return FALSE;
> }
>
> #ifndef WIN32_PLATFORM_WFSP
> HACCEL hAccelTable;
> hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TRAYICON));
> #endif // !WIN32_PLATFORM_WFSP
>
>
> // Main message loop:
> while (GetMessage(&msg, NULL, 0, 0))
> {
> #ifndef WIN32_PLATFORM_WFSP
> if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
> #endif // !WIN32_PLATFORM_WFSP
> {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
> }
>
> return (int) msg.wParam;
> }
>
>
> BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
> {
> HWND hWnd;
> //TCHAR szTitle[MAX_LOADSTRING]; // title bar text
> TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
>
> g_hInst = hInstance; //hInstance; // Store instance handle in our global
> variable
>
> #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
> // SHInitExtraControls should be called once during your application's
> initialization to initialize any
> // of the device specific controls such as CAPEDIT and SIPPREF.
> SHInitExtraControls();
> #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
>
> LoadString(g_hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
> LoadString(g_hInst, IDC_TRAYICON, szWindowClass, MAX_LOADSTRING);
>
> #if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
> //If it is already running, then focus on the window, and exit
> hWnd = FindWindow(szWindowClass, szTitle);
> if (hWnd)
> {
> // set focus to foremost child window
> // The "| 0x00000001" is used to bring any owned windows to the
> foreground and
> // activate them.
> SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
>
> showdebug(L"Application alredy loaded");
> return 0;
> }
>
>
> hWnd = FindWindow(szWindowClass, szTitle);
> if (hWnd)
> {
> //set focus to foremost child window
> //The "| 0x00000001" is used to bring any owned windows to the
> foreground and
> //activate them.
> SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
>
> showdebug(L"Application alredy loaded");
> return 0;
> }
>
> #endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
>
> if (!MyRegisterClass(g_hInst, szWindowClass))
> {
> showdebug(L"could not register class");
> return FALSE;
> }
>
> hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
> CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
> NULL, hInstance, NULL);
>
> // hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
> // 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
>
> if (!hWnd)
> {
> showdebug(L"could not create windows");
>
> return FALSE;
> }
>
>
> #ifdef WIN32_PLATFORM_PSPC
> // When the main window is created using CW_USEDEFAULT the height of the
> menubar (if one
> // is created is not taken into account). So we resize the window after
> creating it
> // if a menubar is present
> if (g_hWndMenuBar)
> {
> RECT rc;
> RECT rcMenuBar;
>
> GetWindowRect(hWnd, &rc);
> GetWindowRect(g_hWndMenuBar, &rcMenuBar);
> rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
>
> MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left,
> rc.bottom-rc.top, FALSE);
> }
> #endif // WIN32_PLATFORM_PSPC
>
>
> hTitleBarIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON1));
>
> AddNotificationIcon(hParent,ID_NOTIFY,szTitle,hTitleBarIcon);
>
> showdebug(L"AddNotificationIcon done"); // but no icon appear !
>
> HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2));
>
> TrayIconAdd(hParent, ID_TRAY,hIcon, NULL); // but no icon appear !
>
>
> //ShowWindow(hWnd, SW_HIDE);
> ShowWindow(hWnd, nCmdShow);
> UpdateWindow(hWnd);
>
> return TRUE;
> }
>
>
>
>
> //************in Main proccess exe file***************//
>
>
> if( (hmodule= LoadLibrary(_T("trayicon.dll"))) == NULL)
> {
> showdebug(L"module not started.");
> }
> else
> {
> startmod = (module_icon)GetProcAddressA(hmodule, "startmod");
> }
>
> if (startmod) {
> showdebug(L"module started."); // ok
> startmod(NULL, 0);
> }
>
>
>
>
> I have tried to pass HWND and hInstance from main proccess to trayicon.dll,
> but no success. what have i doing wrong ?
>
>
> "Scott Seligman" wrote:
>
> > =?Utf-8?B?a25vcHBlcg==?= wrote:
> > >
> > >we have to write a module with icon and system tray on pocket pc (WM6). Whan
> > >i start the module as exe file. All icon can loaded, but when i compile the
> > >module as dll file and loaded in main exe app, the icons will not appear.
|
|
| Back to top |
|
 |
|
|
| Related Topics: | No icon when deploying cab-file Hi, I'm new to PocketPC development. I follow the walkthrough "Packaging a Smart Device Solution for Deployment" in the help system to create a shortcut to the deployed application. The cab installes fine, except for that there is no icon created in the S
Place a icon near keyboard icon I want to see an icon/image near keyboard icon in pocket PC. I am using Visual studio 2005. How i can do that? I also want to handle click event. Rakesh
Speeding Up XML Load Time I just finished my 1st Pocket PC application. It's not a large fancy app by any means. When I deployed it to some test Compaq IPaq's, the issue I ran into was the initail data load. This is a standalone application for the PocketPC using C#. There is 1
Unable to load MUX driver in WM6.0 Hi. I am trying to run WM6.0 by creating a BSP. i am able to succesfully run the same over an emulator. But when i try to load MUX driver (by changing the configuration files), it is not getting loaded. Moreover no entry of MUX is getting created in the s
Unable to load service dll Hello friends, I have created a dll called as MYS.dll using the sample code of I have deployed this dll through a .cab file which has registry settings under services for this Dll. After rebooting Pocket PC 2003 emulator MYS.dll is loaded, |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|