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: - 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
I can see the problem is with me calling GetCurrentPositionEx but i can't see what i've done wrong.
Any help resolving this would be greatly appreciated.
The 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);
-
}
5 2513
I'd like to help but this code uses non-ANS C++ features like this: -
char wPath[strlen(Path)+1];
-
I don't have time to fix it.
Also, Windows code should be using the TCHAR mappings and not refer to char or char* directly.
Maybe you could compile using the -pedantic switch and re-post incase no one else come forward.
Thanks for the note on TCHAR (i am quite new to C programming) Have replaced all instances of Char with TCHAR and both variable-length arrays now have array length MAX_PATH;
Changes:
27: TCHAR wPath[MAX_PATH];
43: TCHAR newPath[MAX_PATH];
However, the original problem still stands.
There are a lot of problems with the code posted above. Are you receiving any others errors or just that one error? What compiler are you using? Verify that you have access to "wingdi.h". I used VS2005 and had no problems with the code you provided in finding GetCurrentPositionEX. There were other problems with variable types and non constant sizes of arrays, but i commented those areas out and I was able to compile.
There are a lot of problems with the code posted above. Are you receiving any others errors or just that one error? What compiler are you using? Verify that you have access to "wingdi.h". I used VS2005 and had no problems with the code you provided in finding GetCurrentPositionEX. There were other problems with variable types and non constant sizes of arrays, but i commented those areas out and I was able to compile.
I'm using netbeans 6.1 (i'm java at heart) with cygwin. it seems to have wingdi access. i'll have a go at compiling in MVSE.
Thanks for that it just seems that cygwin has let me down again (it just stopped working last time i gave C a go and MingW wouldn't read the NetBeans-generated make file)
M$ Visual Studio Express seems to have done the trick (darn discombobulating compilerators never working for me :'( )
[This thread can now be closed - i don't know how to though :(]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: runes |
last post by:
Hi,
I'm trying to set the title of the console window (CMD.EXE) in Windows.
I want it set to the basename of the current directory and it should
stay after the script has finished.
Now, the...
|
by: ZhangZQ |
last post by:
Is it possible to dynamicaly to local and call a function in Win32 dll(not a
..net assembly dll) in C# at run time, for example, a C# program popup a
dialogbox to let use input which Win32 dll to...
|
by: Avery Fong |
last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug
This program is developed...
|
by: vittorio |
last post by:
While I can compile the program below under freebsd via a simple:
gcc prog1.c -o prog1
and it runs smoothly, I'm experiencing annoying problems with lcc-win32
under windows xp pro. In fact, under...
|
by: =?Utf-8?B?Q29saXZpZXI=?= |
last post by:
If anyone can help me with this I would really appreciate it:
I have an assembly into which I have linked a manifest file as a Win32
resource. This is necessary since I want to use a class in this...
|
by: R.Kaiser |
last post by:
I know that I can call Win32 API functions in a Windows forms
application by specifying each function header individually like in
using namespace System;
using namespace...
|
by: Kevin |
last post by:
Hi guys,
I am a beginner for QT, and I installed the free qt 2.3 under windows
(XP), as well as the MS's free VC expression edition (for their
compilers, linkers, etc), and the SDK tool.
My...
|
by: Nimmi Srivastav |
last post by:
Apologies if my cross posting has offended anyone....
For a pure hobbyist C/C++ programmer, who wants to develop
applications to run on Windows, what would be a better choice to
install: Visual...
|
by: The Lord of the Strings |
last post by:
I used to write in Turbo C++ 3 for DOS waaaay back, then moved to
writing C in 32 bit windows using the standard windows api. I took a
many years off to pursue my musical career and now I'm...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |