/* EasyPLX beta version, third version Licensed under GNU GPL Copyleft Olle Bergkvist 2007 www.olle.tk e-mail: olle dot bergvist at yahoo dot se */ #include #include #include "config.h" FILE* debugf; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK rutaproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // global variable indentifying the current focused control int focused=0; int appstarted=0; static HINSTANCE g_hInst = NULL; static int g_FunsterStil = 0; /* Make the class name into a global variable */ char szClassName[ ] = "EasyPLXWindowClass"; LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND button(int xp, int yp, int xs, int ys, int id, char* text){ HWND handle; handle = CreateWindow ( "BUTTON", text, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, xp, yp, xs, ys, hwnd, (HMENU) id, g_hInst, NULL ); SendDlgItemMessage(hwnd, id, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); return handle; } HFONT oneletterfont; oneletterfont= CreateFont( 24, // logical height of font 12, // logical average character width 0, // angle of escapement 0, // base-line orientation angle 1000, // font weight 0, // italic attribute flag 0, // underline attribute flag 0, // strikeout attribute flag DEFAULT_CHARSET, // character set identifier OUT_DEFAULT_PRECIS , // output precision CLIP_DEFAULT_PRECIS , // clipping precision DEFAULT_QUALITY , // output quality FF_DONTCARE , // pitch and family "Courier New" // pointer to typeface name string ); /* switch(message){ case WM_CREATE:fprintf(debugf,"WM_CREATE \n");break; case WM_COMMAND:fprintf(debugf,"WM_COMMAND \n");break; case WM_SIZE:fprintf(debugf,"WM_SIZE \n");break; case WM_SETFOCUS:fprintf(debugf,"WM_SETFOCUS \n");break; case WM_CLOSE:fprintf(debugf,"WM_CLOSE \n");break; case WM_DESTROY:fprintf(debugf,"WM_DESTROY \n");break; default:fprintf(debugf,"Message %d hex %x \n",message,message);break; } */ switch (message) /* handle the messages */ { case WM_CREATE: //editpic CreateWindow("EDIT", "Click on Browse to choose one or more JPEG pictures.", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE | ES_READONLY , 20, 20, 250, 150, hwnd, (HMENU)editpic, g_hInst, NULL ); SendDlgItemMessage(hwnd, editpic, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); //editm3u CreateWindow("EDIT", "Click on Browse to choose a M3U file.", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE | ES_READONLY , 20, 260, 250, 20, hwnd, (HMENU)editm3u, g_hInst, NULL ); SendDlgItemMessage(hwnd, editm3u, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); //editname CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE , rightcordx, 70, 200, 20, hwnd, (HMENU)editname, g_hInst, NULL ); SendDlgItemMessage(hwnd, editname, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); //statname CreateWindow("STATIC", "Enter a name for the playlist in the box below!", WS_CHILD | WS_VISIBLE | SS_LEFT, rightcordx,50,230,20, hwnd, (HMENU)statname, g_hInst, NULL ); SendDlgItemMessage(hwnd, statname, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); //editletter CreateWindow("EDIT", "", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | ES_UPPERCASE , rightcordx, 100, 25, 30, hwnd, (HMENU)editletter, g_hInst, NULL ); SendDlgItemMessage(hwnd, editletter, WM_SETFONT, (WPARAM)oneletterfont, MAKELPARAM(TRUE, 0)); //statletter CreateWindow("STATIC", "If incorrest, change the iriver's drive letter here.", WS_CHILD | WS_VISIBLE | SS_LEFT, 420,100,160,30, hwnd, (HMENU)statletter, g_hInst, NULL ); SendDlgItemMessage(hwnd, statletter, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); //BUTTONS CreateWindow ( "BUTTON", "Continue!", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 380, 280, 80, 30, hwnd, (HMENU) btnok, g_hInst, NULL ); /*SendDlgItemMessage(hwnd, btnok, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); */ button(500,280,btnsizex,btnsizey,btnhelp,"Help!"); button(500, 320, btnsizex, btnsizey,btnabout,"About"); button(590, 280, btnsizex, btnsizey,btnrestart,"Restart"); button(590, 320, btnsizex, btnsizey,btnesc,"Exit"); button(380, 200, 80, btnsizey,btnsettings,"Settings..."); button(midcordx, 20, btnsizex, btnsizey,btnpic,"Browse..."); button(midcordx, 260, btnsizex, btnsizey,btnm3u,"Browse..."); //checkboxes CreateWindow( "BUTTON", "Create picture files (JFU and JTH)", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX , rightcordx,150,200,20, hwnd, (HMENU)checkjfujth, g_hInst, 0 ); SendDlgItemMessage(hwnd, checkjfujth, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); CheckDlgButton(hwnd,checkjfujth,BST_CHECKED); //Groupboxes CreateWindow ( "BUTTON", "Pictures", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 10,0,340,200, hwnd, (HMENU)grppic, g_hInst, NULL ); CreateWindow ( "BUTTON", "M3U file", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 10,220,340,100, hwnd, (HMENU)grpm3u, g_hInst, NULL ); SetFocus(GetDlgItem(hwnd,editname)); break; case WM_SIZE: //MoveWindow(hwnd,0,0,650,400,1); SetFocus(GetDlgItem(hwnd,focused)); if (!appstarted){ appstarted=1; readini(hwnd); searchfordrive(hwnd); } break; case WM_SETFOCUS: SetFocus(GetDlgItem(hwnd,focused)); break; case WM_COMMAND: focused=LOWORD(wParam); switch(LOWORD(wParam)) { case btnok: maintask(hwnd); break; case btnesc: quit(hwnd); break; case btnrestart: restart(hwnd); quit(hwnd); break; case btnsettings: createpopup(hwnd); break; case btnabout: about(hwnd); break; case btnhelp: help(hwnd); break; case btnpic: getpicfilename(hwnd); break; case btnm3u: getm3ufilename(hwnd); break; } break; case WM_CLOSE: quit(hwnd); break; case WM_DESTROY: PostQuitMessage (0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } LRESULT CALLBACK popupproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HWND folderbutton(int xp, int yp, int xs, int ys, int id){ HWND handle; handle = CreateWindow ( "BUTTON", "Folder...", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, xp, yp, xs, ys, hwnd, (HMENU) id, g_hInst, NULL ); SendDlgItemMessage(hwnd, id, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); return handle; } HWND editbox(int xp, int yp, int xs, int ys, int id, char* str){ HWND handle; handle = CreateWindow ( "EDIT", str, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP | WS_VSCROLL | ES_MULTILINE , xp, yp, xs, ys, hwnd, (HMENU) id, g_hInst, NULL ); SendDlgItemMessage(hwnd, id, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); return handle; } HWND staticbox(int xp, int yp, int xs, int ys, int id, char* str){ HWND handle; handle = CreateWindow ( "STATIC", str, WS_CHILD | WS_VISIBLE | SS_LEFT , xp, yp, xs, ys, hwnd, (HMENU) id, g_hInst, NULL ); SendDlgItemMessage(hwnd, id, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); return handle; } switch(message){ case WM_CREATE: //editpath editbox(20, 40, 200, 20,editpath,""); //statpath staticbox(20,20,200,20,statpath,"The PLX output directory path:"); //editext editbox(170, 70, 50, 20,editext,""); //statext staticbox(20,70,150,20,statext,"The PLX file extension:"); //editjfujthpath editbox(20, 110, 200, 20,editjfujthpath,""); //statjfujthpath staticbox(20,90,200,20,statjfujthpath,"The JFU and JTH output directory:"); //editjfuext editbox(170, 140, 50, 20,editjfuext,""); //statjfuext staticbox(20,140,150,20,statjfuext,"The JFU file extension:"); //editjthext editbox(170, 170, 50, 20,editjthext,""); //statjthext staticbox(20,170,150,20,statjthext,"The JTH file extension:"); folderbutton(240,40,btnsizex,btnsizey,btnplxdir); folderbutton(240,110,btnsizex,btnsizey,btnjfujthdir); CreateWindow ( "BUTTON", "Save && use!", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 30, 250, 100, 30, hwnd, (HMENU) btnok, g_hInst, NULL ); /*SendDlgItemMessage(hwnd, btnok, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); */ CreateWindow ( "BUTTON", "Clear settings", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 150, 250, 80, btnsizey, hwnd, (HMENU) btnclear, g_hInst, NULL ); SendDlgItemMessage(hwnd, btnclear, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); CreateWindow ( "BUTTON", "Cancel", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP, 250, 250, btnsizex, btnsizey, hwnd, (HMENU) btnesc, g_hInst, NULL ); SendDlgItemMessage(hwnd, btnesc, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0)); showiniset(hwnd); break; case WM_SIZE: SetFocus(GetDlgItem(hwnd,focused)); break; case WM_SETFOCUS: SetFocus(GetDlgItem(hwnd,focused)); break; case WM_COMMAND: switch(LOWORD(wParam)){ case btnok: saveset(hwnd); DestroyWindow(hwnd); break; case btnesc: DestroyWindow(hwnd); break; case btnclear: deleteini(hwnd); restart(hwnd); PostQuitMessage(0); break; case btnplxdir: getroot(hwnd,editpath); break; case btnjfujthdir: getroot(hwnd,editjfujthpath); break; } break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; } int createpopup(HWND hwnd) { HWND popup; popup = CreateWindowEx ( WS_EX_CONTROLPARENT, "easyplxpopup", "Settings - EasyPLX", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME,//WS_DLGFRAME,//WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 350, 350, hwnd, NULL, g_hInst, NULL ); if (popup==0){ MessageBox(0,"Pop up window creation failed!","EasyPLX",MB_ICONERROR); return 0; } /* Make the window visible on the screen */ ShowWindow (popup, g_FunsterStil); return 0; } int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { //system("ERASE C:\\plxdebug.txt");debugf=fopen("C:\\plxdebug.txt","a"); HWND hwnd,popup; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl,popupcl; /* Data structure for the windowclass */ g_hInst = hThisInstance; g_FunsterStil = nFunsterStil; /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon (g_hInst, "MAINICON"); wincl.hIconSm = LoadIcon (g_hInst, "SMALLICON"); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ wincl.hbrBackground = (HBRUSH) COLOR_BTNSHADOW; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)){ MessageBox(0,"Window registration failed!","EasyPLX",MB_ICONERROR); return 0; } //The window class for the Settings popup. /* The Window structure */ popupcl.hInstance = hThisInstance; popupcl.lpszClassName = "easyplxpopup"; popupcl.lpfnWndProc = popupproc; // WindowProcedure; /* This function is called by windows */ popupcl.style = CS_DBLCLKS; /* Catch double-clicks */ popupcl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */ popupcl.hIcon = LoadIcon (g_hInst, "MAINICON"); popupcl.hIconSm = LoadIcon (g_hInst, "SMALLICON"); popupcl.hCursor = LoadCursor (NULL, IDC_ARROW); popupcl.lpszMenuName = NULL; /* No menu */ popupcl.cbClsExtra = 0; /* No extra bytes after the window class */ popupcl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default color as the background of the window */ popupcl.hbrBackground = (HBRUSH) COLOR_BTNSHADOW; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&popupcl)){ MessageBox(0,"Pop up window registration failed!","EasyPLX",MB_ICONERROR); return 0; } /* The class is registered, let's create the program*/ hwnd = CreateWindowEx ( WS_EX_CONTROLPARENT, /* Extended possibilites for variation */ szClassName, /* Classname */ "EasyPLX", /* Title Text */ WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_DLGFRAME|WS_MINIMIZEBOX, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 680, /* The programs width */ 400, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); if (hwnd==0){ MessageBox(0,"Window creation failed!","EasyPLX",MB_ICONERROR); return 0; } /* Make the window visible on the screen */ ShowWindow (hwnd, nFunsterStil); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage (&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } //fclose(debugf); /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }