| Код | #include <windows.h> #include <iostream> #include "shlwapi.h" #include <fstream> #include <string.h> using namespace std;
/* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */ #define IDS_APP_TITLE 103 #define MAX_LOADSTRING 100 #define IDB_ACCEPT 106 #define IDB_EDIT 107 #define IDC_WINDOWBASIC 109
// Global Variables: HINSTANCE hInst; // current instance
char szClassName[ ] = "WindowsApp"; HWND hWnd_Global; HWND hWnd_Btn; HWND hWnd_Edit; HWND hWnd_Edit1; HWND hWnd_Edit2; HWND hWnd_Label; HWND hWnd_Label1; HWND hWnd_Label2; WNDPROC wpOrigEditProc;
bool RegSetStringValue(HKEY Root, LPCTSTR SubKey, LPCTSTR Key, char *sValue) { HKEY hKey = 0; RegCreateKey(Root,SubKey,&hKey); bool hr = RegSetValueEx(hKey, Key, 0, REG_SZ, (LPBYTE) sValue, (DWORD)strlen(sValue)+1 )==ERROR_SUCCESS; RegCloseKey(hKey); return hr; } LRESULT CALLBACK EditWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam); }
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{ //HWND hwnd; /* This is the handle for our window */ MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */
/* 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 (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); 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_BACKGROUND;
/* Register the window class, and if it fails quit the program */ if (!RegisterClassEx (&wincl)) return 0;
/* The class is registered, let's create the program*/ hWnd_Global = CreateWindow(szClassName, "cgpsmapper AUTOMAKE", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, NULL, NULL, hThisInstance, NULL); hWnd_Btn = CreateWindow("BUTTON", // predefined class "ACCEPT", // button text WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // styles // Size and position values are given explicitly, because // the CW_USEDEFAULT constant gives zero values for buttons. 100,150,120,25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // No menu (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed SetWindowLong(hWnd_Btn,GWL_ID,IDB_ACCEPT); hWnd_Edit = CreateWindow("EDIT", // predefined class "GlobalMapDefault", // no window title WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 150, 15, 250, 25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // edit control ID (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed hWnd_Label = CreateWindow("STATIC", // predefined class "Íàçâàíèå êàðòû", // no window title WS_CHILD | WS_VISIBLE | ES_LEFT, 10, 15, 120, 25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // edit control ID (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed hWnd_Edit1 = CreateWindow("EDIT", // predefined class "0", // no window title WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 150, 55, 250, 25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // edit control ID (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed hWnd_Label1 = CreateWindow("STATIC", // predefined class "Product Code", // no window title WS_CHILD | WS_VISIBLE | ES_LEFT, 15, 55, 120, 25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // edit control ID (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed hWnd_Edit2 = CreateWindow("EDIT", // predefined class "Default.img", // no window title WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 150, 95, 250, 25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // edit control ID (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed hWnd_Label2 = CreateWindow("STATIC", // predefined class "File Name", // no window title WS_CHILD | WS_VISIBLE | ES_LEFT, 15, 95, 120, 25, // set size in WM_SIZE message hWnd_Global, // parent window NULL, // edit control ID (HINSTANCE) GetWindowLong(hWnd_Global, GWL_HINSTANCE), NULL); // pointer not needed SetWindowLong(hWnd_Edit,GWL_ID,IDB_EDIT); wpOrigEditProc = (WNDPROC) SetWindowLong(hWnd_Edit,GWL_WNDPROC, (LONG) EditWndProc); /* Make the window visible on the screen */ ShowWindow (hWnd_Global, 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); }
/* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; }
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: if ((wmId==IDB_ACCEPT)&&(wmEvent == BN_CLICKED)) { char CardName[250]; char ProductCode[250]; char FileName[250]; char OutputFile[3000]=""; char RegFile[3000]=""; GetWindowText(hWnd_Edit,CardName,250); GetWindowText(hWnd_Edit1,ProductCode,250); GetWindowText(hWnd_Edit2,FileName,250); FILE * fo; fo = fopen("pv.txt","wt"); fprintf(fo, "[Map]\nFileName="); fprintf(fo, CardName); fprintf(fo, "\nMapVersion=100\nProductCode="); fprintf(fo, ProductCode); fprintf(fo, "\nLevels=2\nLevel0=15\nLevel1=13\nZoom0=7\nZoom1=8\nMapsourceName="); fprintf(fo, CardName); fprintf(fo, "\nMapSetName="); fprintf(fo, CardName); fprintf(fo, "\nCDSetName="); fprintf(fo, CardName); fprintf(fo, "\nCopy1=Garmin\nCopy2=Garmin\n[End-Map]\n\n[Files]\nimg="); fprintf(fo, FileName); fprintf(fo,"\n[END-Files]"); fclose(fo); cout << WinExec("cgpsmapper.exe pv pv.txt",SW_SHOW) << endl; char *pdest; char m_AppPath[MAX_PATH]; GetModuleFileName(NULL,m_AppPath,MAX_PATH); pdest = strrchr(m_AppPath, '\\'); *pdest = '\0'; char szPath[_MAX_PATH+1]; strcpy(szPath, CardName); char szExtension[_MAX_PATH+1]; strcpy(szExtension, "reg"); if (PathAddExtension(szPath, szExtension)) { FILE * fo; fo = fopen(szPath,"wt+"); fprintf(fo, "REGEDIT4\n"); fprintf(fo, "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GARMIN\\MapSource\\Products\\"); fprintf(fo, ProductCode); fprintf(fo, "]\n"); fprintf(fo, "\"Bmap\"="); fprintf(fo, "\"", pdest); fprintf(fo, CardName); fprintf(fo, ".img"); fprintf(fo, "\"\n"); fprintf(fo, "\"Tdb\"="); fprintf(fo, "\"", pdest); fprintf(fo, CardName); fprintf(fo, ".tdb"); fprintf(fo, "\"\n"); fprintf(fo, "\"Loc\"="); fprintf(fo, "\"", pdest); fprintf(fo, "\""); fclose(fo); } } case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;
}
|
На этапе Link выдаётся ошибка: [Linker error] undefined reference to `_imp__PathAddExtensionA@8' ld returned 1 exit status C:\Mapsoft\Makefile.win [Build Error] [windows.exe] Error 1
Что делать? |