Hi,
I have a problem with reading a textfile.
this textfile looks like that:
1
"Test1"
"\My Flash Disk\test.exe"
.
.
.
8
"Test2"
"\My Flash Disk\test.exe"
The first entry is the button-number,
the second has to be the button-text
and the third entry has to be the command, which starts the application shown there.
I tried a lot, but neither the button-Text is shown mor the link will executed...
This is the code:
#include <windows.h>
#include <windowsx.h>
#include "main.h"
#include <string.h>
#include <stddef.h>
#define LINELEN_MAX 200 // Maximale Anzahl der Zeichen einer Zeile.
#define N 8 // Anzahl der Button.
static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
static HANDLE ghInstance;
typedef struct button Button;
struct button
{
int nr;
wchar_t text[LINELEN_MAX+1];
wchar_t link[LINELEN_MAX+1];
};
void view_button_array ( Button* b, unsigned n )
{
unsigned i = 0;
while ( i < n )
printf ( "%d\n" "%s\n" "%s\n\n", b[i].nr, b[i].text, b[i].link ), i++;
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
hwnd = FindWindow(L"Addins_Menu.class", NULL); // Nachschauen, ob der Prozess schon läuft
if (hwnd) // wenn der Prozess läuft
{ //
SetForegroundWindow((HWND)((ULONG)hwnd|0x00000001)); // Fenster in den Vordergrund bringen
return 0;
}
ghInstance = hInstance; //
if (!GetClassInfo(NULL, L"Dialog", &wc))
return 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wc.lpszClassName = L"Addins_Menu.class";
if (!RegisterClass(&wc))
return 0;
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}
static INT_PTR CALLBACK MainDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int n = 3, // Anzahl der zu einem Datensatz zugehörigen Zeilen.
i = 0; // Index und Zähler fürs Strukturarray.
char* fname = "My Flash disk\\navigation\\skin480x272\\Addins\\Addins.txt",
*fmt = "%d %200[^\n]\n %200[^\n]\n"; // Angepasst an LINELEN_MAX.
FILE* fp = fopen ( fname, "r" );
Button buttons[N] = {0}; // Strukturarray für die Daten der Buttons.
if ( fp == NULL )
{
MessageBox(NULL, L"Addins.TXT fehlt!", L"Addins-Menü", MB_SETFOREGROUND);
return (0);
}
while ( !feof(fp) )
{
if ( i == N )
{
MessageBox(NULL, L"Addins.TXT beschädigt! ", L"Addins-Menü", MB_SETFOREGROUND);
return (0);
break;
}
if ( n != fscanf ( fp, fmt, &buttons[i].nr, buttons[i].text, buttons[i].link ))
{
MessageBox(NULL, L"Addins.TXT nicht vollständig! ", L"Addins-Menü", MB_SETFOREGROUND);
return (0);
break;
}
i++;
}
printf ( "Es wurden %d Datensaetze eingelesen.\n\n", i );
view_button_array ( buttons, i );
fclose ( fp );
HWND button1 = CreateWindow(_T("BUTTON"),_T(" "), WS_VISIBLE|WS_TABSTOP|WS_CHILD, 0, 80,72, 40, hwndDlg, (HMENU) Button1, NULL, NULL);
PostMessage(button1,WM_SETTEXT, 0, (LPARAM)buttons[0].text);
/* and so on until button8
.
.
. */
switch (uMsg)
{
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case Button1:
CreateProcess(buttons[1].link,NULL,0,0,FALSE,0, 0, 0, NULL, NULL);
PostQuitMessage(0);
EndDialog;
return (0);
/* and so on until button8
.
.
.*/
If I use SendMessage, the script lags...
Please help me for fixing my problem with this script...