Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How:i can't use this API !!!

How:i can't use this API !!!

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelp
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    happycpp
    wrote on last edited by
    #1

    hi everyone.. I got really tired trying to use "SetLayeredWindowAttributes". I will describe what I did and then maybe you can help me figure out what's wrong: the MSDN says that I need to include "windows.h" so I did that..it also says that I need the linker to link to "user32.lib" so I did that also... now I can't use the api function (I don't know why) though I'm using GetWindowLong (which is from the same library)

    B G 2 Replies Last reply
    0
    • H happycpp

      hi everyone.. I got really tired trying to use "SetLayeredWindowAttributes". I will describe what I did and then maybe you can help me figure out what's wrong: the MSDN says that I need to include "windows.h" so I did that..it also says that I need the linker to link to "user32.lib" so I did that also... now I can't use the api function (I don't know why) though I'm using GetWindowLong (which is from the same library)

      B Offline
      B Offline
      BlackDice
      wrote on last edited by
      #2

      what's the error you're getting? I have a sample of what I did to use it, but I don't necessarily know if that will help if I don't know what the problem is. I think I had a problem also when I first tried to use that function. Check your stdafx.h file and see what WINVER is defined as. you don't need to include windows.h if you're using mfc. also check your _WIN_32_IE #define. When creating a project, the wizard puts these values too low to take advantage of some of the more advanced controls and api's. if WINVER is #defined as 0x0400, somebody told me to set it like this on CP, although I was told this wasn't a good idea: #ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. #define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. #endif //NEXT two lines added because some things aren't available if WINVER is #defined as 0x400 #undef WINVER #define WINVER 1000000 it isn't a good idea because there's no such version of Windows but a lot of structures have conditional compilation directives depending on whether or not your version of Windows is defined high enough. If your _WIN_32_IE is #defined as 0x400, you need to change that also (I put mine to 0x0600). Hope this helps. [insert witty comment here] bdiamond :zzz:

      H 1 Reply Last reply
      0
      • H happycpp

        hi everyone.. I got really tired trying to use "SetLayeredWindowAttributes". I will describe what I did and then maybe you can help me figure out what's wrong: the MSDN says that I need to include "windows.h" so I did that..it also says that I need the linker to link to "user32.lib" so I did that also... now I can't use the api function (I don't know why) though I'm using GetWindowLong (which is from the same library)

        G Offline
        G Offline
        gamitech
        wrote on last edited by
        #3

        you may also do this to call the function: #define WS_EX_LAYERED 0x00080000 #define LWA_COLORKEY 0x00000001 #define LWA_ALPHA 0x00000002 typedef VOID (CALLBACK* MySetWindowLayeredAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); typedef VOID (CALLBACK* UpdateLayeredWindow)( HWND hwnd, // handle to layered window HDC hdcDst, // handle to screen DC POINT *pptDst, // new screen position SIZE *psize, // new size of the layered window HDC hdcSrc, // handle to surface DC POINT *pptSrc, // layer position COLORREF crKey, // color key BLENDFUNCTION *pblend, // blend function DWORD dwFlags // options ); MySetWindowLayeredAttributes procedure; UpdateLayeredWindow procedure1; COLORREF color; color=RGB(50,100,150); HINSTANCE dllhinst; dllhinst= LoadLibrary("User32.dll"); if (dllhinst!=NULL) { procedure=(MySetWindowLayeredAttributes)GetProcAddress(dllhinst, "SetLayeredWindowAttributes"); if (!procedure) { MessageBox(GetDesktopWindow(),"The HOOK FUNCTION COULD NOT BE LOADED","GABBY",MB_ICONSTOP|MB_APPLMODAL); FreeLibrary(dllhinst); }; procedura1=(MyUpdateLayeredWindow)GetProcAddress(dllhinst, "UpdateLayeredWindow"); if (!procedure1) { MessageBox(GetDesktopWindow(),"The HOOK FUNCTION COULD NOT BE LOADED","GABBY",MB_ICONSTOP||MB_APPLMODAL); FreeLibrary(dllhinst); }; }else MessageBox(NULL,"Could not load DLL","Gabby",MB_OK||MB_APPLMODAL); //and now what you've been waitring for procedure(hdlg,color,1,LWA_ALPHA); :) hope you like it gabby

        H 1 Reply Last reply
        0
        • B BlackDice

          what's the error you're getting? I have a sample of what I did to use it, but I don't necessarily know if that will help if I don't know what the problem is. I think I had a problem also when I first tried to use that function. Check your stdafx.h file and see what WINVER is defined as. you don't need to include windows.h if you're using mfc. also check your _WIN_32_IE #define. When creating a project, the wizard puts these values too low to take advantage of some of the more advanced controls and api's. if WINVER is #defined as 0x0400, somebody told me to set it like this on CP, although I was told this wasn't a good idea: #ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later. #define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. #endif //NEXT two lines added because some things aren't available if WINVER is #defined as 0x400 #undef WINVER #define WINVER 1000000 it isn't a good idea because there's no such version of Windows but a lot of structures have conditional compilation directives depending on whether or not your version of Windows is defined high enough. If your _WIN_32_IE is #defined as 0x400, you need to change that also (I put mine to 0x0600). Hope this helps. [insert witty comment here] bdiamond :zzz:

          H Offline
          H Offline
          happycpp
          wrote on last edited by
          #4

          the solutions you (mr.euacela) mention is a little bit complicated I hope there's something better... to mr.bdiamond: the problem is undeclared identifiers: LWA_ALPHA SetLayeredWindowAttributes WS_EX_LAYERED also I want to note that I'm not using mfc.. and about the defintion things that you want me to check, where are they(which file or header..) or do I have to put my own header including these things..

          1 Reply Last reply
          0
          • G gamitech

            you may also do this to call the function: #define WS_EX_LAYERED 0x00080000 #define LWA_COLORKEY 0x00000001 #define LWA_ALPHA 0x00000002 typedef VOID (CALLBACK* MySetWindowLayeredAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); typedef VOID (CALLBACK* UpdateLayeredWindow)( HWND hwnd, // handle to layered window HDC hdcDst, // handle to screen DC POINT *pptDst, // new screen position SIZE *psize, // new size of the layered window HDC hdcSrc, // handle to surface DC POINT *pptSrc, // layer position COLORREF crKey, // color key BLENDFUNCTION *pblend, // blend function DWORD dwFlags // options ); MySetWindowLayeredAttributes procedure; UpdateLayeredWindow procedure1; COLORREF color; color=RGB(50,100,150); HINSTANCE dllhinst; dllhinst= LoadLibrary("User32.dll"); if (dllhinst!=NULL) { procedure=(MySetWindowLayeredAttributes)GetProcAddress(dllhinst, "SetLayeredWindowAttributes"); if (!procedure) { MessageBox(GetDesktopWindow(),"The HOOK FUNCTION COULD NOT BE LOADED","GABBY",MB_ICONSTOP|MB_APPLMODAL); FreeLibrary(dllhinst); }; procedura1=(MyUpdateLayeredWindow)GetProcAddress(dllhinst, "UpdateLayeredWindow"); if (!procedure1) { MessageBox(GetDesktopWindow(),"The HOOK FUNCTION COULD NOT BE LOADED","GABBY",MB_ICONSTOP||MB_APPLMODAL); FreeLibrary(dllhinst); }; }else MessageBox(NULL,"Could not load DLL","Gabby",MB_OK||MB_APPLMODAL); //and now what you've been waitring for procedure(hdlg,color,1,LWA_ALPHA); :) hope you like it gabby

            H Offline
            H Offline
            happycpp
            wrote on last edited by
            #5

            hi again.. ]I found the solution to the problem..I digged in the WinUser.h a little bit and I found that the API will not be declared unless "_WIN32_WINNT" is defined equal or greater than 0x0501 so I just defined it like that in my prog and it worked...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups