Konuyu görüntüle
IUCODERS FORUM > Programlama > C / C++ > VC++ - WINAPI - XP - VISTA
Yazar
huseyinkozan


avatar
Serik
Kayıt: 21.03.2007
26.02.2008-17:17 #38859
selam millet
şu kodu yazdım, vistada çalışıyor. xp de hata veriyor. fikri olan ?

uzantıyı exe yapın :
http://rapidshare.com/files/95094884/YukselBilgisayarClient.html

#include "client.h"
//#include <strsafe.h>

#define MYWM_NOTIFYICON 200
#define IDI_MY_ICON 201
#define ID_60_TIMER 202

LRESULT CALLBACK MainWndProc( HWND, UINT, WPARAM, LPARAM );
BOOL MyTaskBarAddIcon(HWND , UINT , HICON , LPSTR );
BOOL MyTaskBarDeleteIcon(HWND , UINT );
void On_MYWM_NOTIFYICON(HWND , WPARAM , LPARAM );
DWORD WINAPI MyThreadProc(LPVOID );
void CreateMyMainWindow();
LRESULT CALLBACK ChildWndProc( HWND , UINT , WPARAM ,LPARAM  );

HWND ghWnd;
HDC ghdc;
HINSTANCE ghInstance;
HWND desktopRequestHwnd = NULL;
bool timerActive = false;
bool hidden = false;
HDESK orgThread;
HDESK orgInput ;
HDESK newDesktop;

/********************************************************************
*                              hata                                 *
********************************************************************/
void hata(LPCWSTR str){
	MessageBox(ghWnd,str,L"hata",MB_OK);
}

/********************************************************************
*                              WinMain                               *
********************************************************************/
int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow )
{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;
   BOOL bRet;

   if( !hPrevInstance )
   {
      wc.lpszClassName = TEXT("YukselBilgisayar");
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = TEXT("YukselBilgisayar");
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   ghInstance = hInstance;

   hWnd = CreateWindowEx( /*WS_EX_TOPMOST |*/ WS_EX_LAYERED|WS_EX_TOOLWINDOW,TEXT("YukselBilgisayar"),
      TEXT("YukselBilgisayar"),
	  WS_CAPTION|WS_TILED| WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
      GetSystemMetrics(SM_CXFULLSCREEN)*0.9,
      GetSystemMetrics(SM_CYFULLSCREEN)*0.9,
	  GetSystemMetrics(SM_CXFULLSCREEN)*0.1,
      GetSystemMetrics(SM_CYFULLSCREEN)*0.1,
      NULL,
      NULL,
      hInstance,
      NULL
   );

   ShowWindow( hWnd, nCmdShow );
   ghWnd = hWnd;

	// Make this window 70% alpha
	SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);

 while(GetMessage(&msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

   return (int)msg.wParam;
}

/********************************************************************
*                           MainWndProc                              *
********************************************************************/
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   PAINTSTRUCT ps;
   HDC hDC;
   static UINT s_uTaskbarRestart;
   HANDLE hThread;

   switch( msg ) {
	    case WM_CREATE:
            s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
			MyTaskBarAddIcon(hWnd,IDI_MY_ICON,LoadIcon( NULL, IDI_APPLICATION ),":P");
			break;
		case MYWM_NOTIFYICON:
			On_MYWM_NOTIFYICON( hWnd, wParam,  lParam);
			break;
	   case WM_LBUTTONUP:
		   DestroyWindow(hWnd);
		   break;
	   case WM_RBUTTONUP:
			   if(timerActive){
				   KillTimer(hWnd,ID_60_TIMER);
				   timerActive = false;
			   }
			   else{
				   SetTimer(hWnd,ID_60_TIMER, 5 * 1000 , NULL);
				   timerActive = true;
			   }
		   break;
	   case WM_MBUTTONUP:
		   DWORD dummy;
		   hThread = CreateThread( NULL, 0, MyThreadProc, NULL, 0, &dummy);
		   break;
	   case WM_TIMER:
		   switch(wParam){
				case ID_60_TIMER:
					hata(L"timer");
		   }
		   break;
      case WM_PAINT:
         hDC = BeginPaint( hWnd, &ps );
         TextOut( hDC, 10, 10, TEXT("Kapatmak icin"), 15 );
		 TextOut( hDC, 10, 25, TEXT("     tiklayin"), 15 );
         EndPaint( hWnd, &ps );
         break;

      case WM_DESTROY:
		 MyTaskBarDeleteIcon(hWnd, IDI_MY_ICON);
         PostQuitMessage( 0 );
         break;

      default:
		  if(msg == s_uTaskbarRestart)
			  MyTaskBarAddIcon(hWnd,IDI_MY_ICON,LoadIcon( NULL, IDI_APPLICATION ),":P");
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

// MyTaskBarAddIcon - adds an icon to the taskbar status area. 
// Returns TRUE if successful, or FALSE otherwise. 
// hwnd - handle to the window to receive callback messages. 
// uID - identifier of the icon. 
// hicon - handle to the icon to add. 
// lpszTip - ToolTip text. 
/********************************************************************
*                           MyTaskBarAddIcon                        *
********************************************************************/
BOOL MyTaskBarAddIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip) 
{
    BOOL res; 
    NOTIFYICONDATA tnid; 
 
    tnid.cbSize = sizeof(NOTIFYICONDATA); 
    tnid.hWnd = hwnd; 
    tnid.uID = uID; 
    tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 
	tnid.uCallbackMessage = MYWM_NOTIFYICON; 
    tnid.hIcon = hicon; 
    if (lpszTip) tnid.szTip[0] = (TCHAR)'�'; 
        /*hr = *//*StringCbCopyN(tnid.szTip, sizeof(tnid.szTip), (LPCTSTR) lpszTip, sizeof(tnid.szTip));*/
        // TODO: Add error handling for the HRESULT.
    else 
        tnid.szTip[0] = (TCHAR)'�'; 
 
    res = Shell_NotifyIcon(NIM_ADD, &tnid); 
 
    if (hicon) 
        DestroyIcon(hicon); 
 
    return res; 
}

// MyTaskBarDeleteIcon - deletes an icon from the taskbar status area. 
// Returns TRUE if successful, or FALSE otherwise. 
// hwnd - handle to the window that added the icon. 
// uID - identifier of the icon to delete. 
/********************************************************************
*                           MyTaskBarDeleteIcon                     *
********************************************************************/
BOOL MyTaskBarDeleteIcon(HWND hwnd, UINT uID) 
{ 
    BOOL res; 
    NOTIFYICONDATA tnid; 
 
    tnid.cbSize = sizeof(NOTIFYICONDATA); 
    tnid.hWnd = hwnd; 
    tnid.uID = uID; 
         
    res = Shell_NotifyIcon(NIM_DELETE, &tnid); 
    return res; 
}

// On_MYWM_NOTIFYICON - processes callback messages for taskbar icons. 
// wParam - first message parameter of the callback message. 
// lParam - second message parameter of the callback message. 
/********************************************************************
*                           On_MYWM_NOTIFYICON                      *
********************************************************************/
void On_MYWM_NOTIFYICON(HWND hwnd, WPARAM wParam, LPARAM lParam)
{ 
    UINT uID; 
    UINT uMouseMsg; 
 
    uID = (UINT) wParam; 
    uMouseMsg = (UINT) lParam; 
 
    if (uMouseMsg == WM_LBUTTONDOWN) 
    { 
        switch (uID) 
        { 
            case IDI_MY_ICON: 
				if(hidden){
					ShowWindow(ghWnd,SW_SHOWDEFAULT);
					BringWindowToTop(ghWnd);
					hidden = false;
			   }
			   else{
				   ShowWindow(ghWnd,SW_HIDE);
				   hidden = true;
			   }
                break; 
            default: 
                break; 
        } 
     }
     return; 
 }

/********************************************************************
*                           MyThreadProc                            *
********************************************************************/
DWORD WINAPI MyThreadProc(LPVOID lpv)
{
    // Save handle to original desktop.
    orgThread = GetThreadDesktop(GetCurrentThreadId());
	orgInput = OpenInputDesktop(0,FALSE,DESKTOP_SWITCHDESKTOP);
    // Start working with private desktop.
    newDesktop = CreateDesktop(TEXT("MyDesktop"), NULL, NULL, 0,GENERIC_ALL, NULL);
    if (SetThreadDesktop(newDesktop))
    {
		SwitchDesktop(newDesktop);
        CreateMyMainWindow();
        MSG msg;
        while (GetMessage(&msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    SwitchDesktop(orgInput);
    SetThreadDesktop(orgThread);
    CloseDesktop(newDesktop);
    return 0;
}

/********************************************************************
*                           CreateMyMainWindow                      *
********************************************************************/
void CreateMyMainWindow(){
	WNDCLASS wc;
   MSG msg;
   HWND hWnd;
   BOOL bRet;

      wc.lpszClassName = TEXT("desktopRequest");
      wc.lpfnWndProc = ChildWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
	  wc.hInstance = GetModuleHandle(NULL);
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = TEXT("desktopRequest");
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );

   hWnd = CreateWindow( TEXT("desktopRequest"),
      TEXT("desktopRequest"),
	  WS_CAPTION|WS_TILED| WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
      GetSystemMetrics(SM_CXFULLSCREEN)*0.3,
      GetSystemMetrics(SM_CYFULLSCREEN)*0.4,
	  GetSystemMetrics(SM_CXFULLSCREEN)*0.4,
      GetSystemMetrics(SM_CYFULLSCREEN)*0.2,
      NULL,
      NULL,
      GetModuleHandle(NULL),
      NULL
   );

   if(hWnd==NULL) 
	   hata(L"createdesktopRequestWindow");

   ShowWindow( hWnd, SW_SHOW );
}

/********************************************************************
*                           CreateMyMainWindow                      *
********************************************************************/
LRESULT CALLBACK ChildWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
   PAINTSTRUCT ps;
   HDC hDC;

   HANDLE hThread;

   switch( msg ) {
	   case WM_LBUTTONUP:
		   DestroyWindow(hWnd);
		   break;
      case WM_PAINT:
         hDC = BeginPaint( hWnd, &ps );
         TextOut( hDC, 10, 10, TEXT("Kapatmak icin tiklayin"), 15 );
         EndPaint( hWnd, &ps );
         break;
      case WM_DESTROY:
		  SwitchDesktop(orgInput);
		  SetThreadDesktop(orgThread);
		  CloseDesktop(newDesktop);
		  DestroyWindow(0);
         break;
      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }
   return 0;
}


düzenleme_1 : bi arkadaşımın gösterdiği şekilde exe yi editör ile açtığımda şöle bişey ile karşılaştım;

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
....

exe yi vs 2008 ile yapmıştım, .net framwork 3.5 olmayan pc lerde çalışmıyor sanırım.

düzenleme_2 : kendi soruma kendim cevap yazim bari
vs 2003 ile derlediğimde exe içinde assambly kodu yoktu, vs 2008 de native code derlemek için şu girdiye bi bakın derim. belli mi olur bi gün lazım olur :P
http://www.neowin.net/forum/index.php?showtopic=615265&st=0






Yazar
orhan


avatar
istanbul
admin
Kayıt: 17.11.2005
26.02.2008-17:36 #38860
xp ve vista iki farklı api kullanıyordur.
kodu incelemedim fakat taskbasa bişeyler eklemeye çalışıyor trayicon gibi bişey olabilir.
xp ve vista iki farklı pencere yoneticisi kullandığı için birinde çalışan diğerinde çalışmayabilir.





N/A
Yazar
huseyinkozan


avatar
Serik
Kayıt: 21.03.2007
26.02.2008-17:39 #38861
taskbar için fonksiyona bakmıştım, eski versiyonlarıda destekliyodu, ama yine bi kontrol ediyim. tşk ler






Yazar
huseyinkozan


avatar
Serik
Kayıt: 21.03.2007
26.02.2008-17:41 #38862
xp yüklü olup da debug edebilecek birileri varsa çok güzel olurdu...






Del.icio.us
Digg
Facebook
Furl
Google
Blink
Simpy
Spurl
Y! MyWeb