I'm trying to write what should be a very simple program - a system tray based menu to allow me to quickly access files in a folder (for me a bunch of disc images). Unfotunately i'm stumped near completion.
Basically the following code fails to compile with this error:
I can see the problem is with me calling GetCurrentPosit ionEx but i can't see what i've done wrong.
Any help resolving this would be greatly appreciated.
The Code:
Basically the following code fails to compile with this error:
Code:
build/Debug/Cygwin-Windows/ImgMag.o: In function `_Z7WndProcP6HWND__jjl': /cygdrive/c/***CENSORED***/ImgMag/ImgMag.cpp:87: undefined reference to `_GetCurrentPositionEx@8' collect2: ld returned 1 exit status
Any help resolving this would be greatly appreciated.
The Code:
Code:
#define _WINVER 0x505 #define _WIN32_WINNT 0x505 #ifdef NOGDI #undef NOGDI #endif #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <wingdi.h> #include <map> #define ICON_MSG WM_USER+0 #define IDM_MENU0 1000 //Globals using namespace std; namespace globe { char trayClass[]="ImgMagCls"; HWND tray; HICON tIcon; HMENU popup=CreatePopupMenu(); HMENU* ptr; map<int,char*> menu; UINT count=0; UINT mx,my; } //Custom Functions int scanDir(char* Path){ char wPath[strlen(Path)+1]; strcpy(wPath,Path);strcat(wPath,"*"); printf("%s\r\n",wPath); WIN32_FIND_DATA fd; HANDLE file = FindFirstFile(wPath,&fd); if(file==INVALID_HANDLE_VALUE){ printf("ERR!!\r\n"); return -1; } do{ if((fd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ENCRYPTED)) || strlen(fd.cFileName)<3) continue; if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){ HMENU newMenu=CreateMenu(); HMENU* tmp=globe::ptr; globe::ptr = &newMenu; char newPath[strlen(Path)+strlen(fd.cFileName)]; strcpy(newPath,Path); strcat(newPath,fd.cFileName); strcat(newPath,"\\"); scanDir(newPath); globe::ptr=tmp; AppendMenu(*(globe::ptr),MF_ENABLED|MF_POPUP|MF_STRING,(UINT)newMenu,fd.cFileName); }else if(~FILE_ATTRIBUTE_HIDDEN & ~ FILE_ATTRIBUTE_SYSTEM){ AppendMenu(*(globe::ptr),MF_ENABLED|MF_STRING,IDM_MENU0+globe::count,fd.cFileName); globe::menu[IDM_MENU0+globe::count]=(char*)&fd.cFileName; printf("%u: %s\r\n",IDM_MENU0+globe::count,fd.cFileName); globe::count++; } }while(FindNextFile(file,&fd)); } //API Functions LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){ switch(msg){ case WM_CREATE:{ //Load Image globe::tIcon=(HICON) LoadImage(NULL,"ImgMag.ico",IMAGE_ICON,SM_CXSMICON,SM_CYSMICON,LR_LOADFROMFILE); NOTIFYICONDATA nid; nid.cbSize=sizeof(nid); nid.hIcon=globe::tIcon; nid.hWnd=hwnd; strcpy(nid.szTip,"Disc Image Magazine"); nid.uCallbackMessage=ICON_MSG; nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP; nid.uID=0; globe::ptr=&(globe::popup); scanDir("I:\\"); Shell_NotifyIcon(NIM_ADD,&nid); printf("let's go...\r\n"); }break; case ICON_MSG:{ //printf("ICON_MSG:{%u,%u}\r\n",wParam,lParam); switch(lParam){ case WM_CONTEXTMENU: case WM_LBUTTONUP: case WM_RBUTTONUP:{ //ShowWindow(globe::tray,SW_SHOW); POINT mp; HDC hdc=GetDC(NULL); GetCurrentPositionEx(hdc,(LPPOINT)&mp); SetForegroundWindow(hwnd); TrackPopupMenu(globe::popup,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON,(int)mp.x,(int)mp.y,0,globe::tray,NULL); }break; } }break; case WM_DESTROY: PostQuitMessage(0); break; default: //printf("MSG:%u\r\n",msg); return DefWindowProc(hwnd,msg,wParam,lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; MSG Msg; //<editor-fold defaultstate="collapsed" desc="Window Class Definition"> wc.cbSize = sizeof (WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = globe::trayClass; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if (!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 1; } //</editor-fold> globe::tray = CreateWindowEx(WS_EX_CLIENTEDGE, globe::trayClass, "Disc Image Magazine", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (globe::tray == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 2; } while (GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return (EXIT_SUCCESS); }
Comment