?? win.c
字號:
#define WIN32
#include "lpc-h.h"
#include <commctrl.h>
#include "lpc.h"
static HWND Hwnd;
static HANDLE MsgThread;
static LONG ThreadID;
void Puts(char *Msg)
{ SendDlgItemMessage(Hwnd,IDC_LISTBOX1,LB_ADDSTRING,0,(LPARAM)Msg);
}
void delay(unsigned Time)
{ Sleep(Time);
}
void SetProgress(int Steps)
{ if (Steps)
SendDlgItemMessage(Hwnd,IDC_PROGRESSBAR1,PBM_SETRANGE,0,MAKELPARAM(0,Steps+1));
SendDlgItemMessage(Hwnd,IDC_PROGRESSBAR1,PBM_SETPOS,0,0);
}
void StepProgress(void)
{ SendDlgItemMessage(Hwnd,IDC_PROGRESSBAR1,PBM_DELTAPOS,(WPARAM)1,0);
}
void ReadLPC(HWND hwnd)
{ static char WritePath[MAX_PATH]={0};
OPENFILENAME DirBox;
ZeroMemory(&DirBox, sizeof(DirBox));
DirBox.lStructSize = sizeof(DirBox);
DirBox.hwndOwner = hwnd;
DirBox.lpstrFile = WritePath;
DirBox.nMaxFile = MAX_PATH;
DirBox.lpstrTitle = "Save LPC image as";
DirBox.Flags = OFN_EXPLORER | OFN_LONGNAMES | OFN_NOCHANGEDIR ;
if (GetSaveFileName(&DirBox))
{ ReadChip(WritePath);
}
}
void WriteVerifyLPC(HWND hwnd,int flag)
{ static char ReadPath[MAX_PATH]={0};
OPENFILENAME DirBox;
int offset;
ZeroMemory(&DirBox, sizeof(DirBox));
DirBox.lStructSize = sizeof(DirBox);
DirBox.hwndOwner = hwnd;
DirBox.lpstrFile = ReadPath;
DirBox.nMaxFile = MAX_PATH;
DirBox.lpstrTitle = "Read LPC image from";
DirBox.Flags = OFN_EXPLORER | OFN_LONGNAMES | OFN_NOCHANGEDIR ;
if(SendDlgItemMessage(hwnd,IDC_First,BM_GETSTATE,0,0)==BST_CHECKED)
offset=0;
else
offset=1;
if (GetOpenFileName(&DirBox))
{ switch(flag)
{ case 0:
VerifyChip(ReadPath,offset);
break;
case 1:
WriteChip(ReadPath,offset);
break;
case 2:
WriteChip(ReadPath,offset);
VerifyChip(ReadPath,offset);
break;
}
}
}
BOOL StartUpIoPorts(HWND hwnd)
{ HANDLE hUserPort;
hUserPort = CreateFile("\\\\.\\UserPort", GENERIC_READ, 0, NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hUserPort); // Activate the driver
Sleep(100); // We must make a process switch
}
// Win32 GUI code
void GUI_Init(HWND hwnd)
{ const char *CableTypes[] = {"LPC^2 Rev.1","LPC^2 Rev.2",NULL};
const char *IOAddr[] = {"378 (Hex) LPT1:","278 (Hex) LPT2:",NULL};
int i;
for(i=0;IOAddr[i];i++)
SendDlgItemMessage(hwnd,IDC_IOPort,CB_INSERTSTRING,i,(LPARAM)IOAddr[i]);
SendDlgItemMessage(hwnd,IDC_IOPort,CB_SETCURSEL,0,0);
for(i=0;CableTypes[i];i++)
SendDlgItemMessage(hwnd,IDC_CableType,CB_INSERTSTRING,i,(LPARAM)CableTypes[i]);
i=Rev2_Detect();
SendDlgItemMessage(hwnd,IDC_CableType,CB_SETCURSEL,i,0);
SendDlgItemMessage(hwnd,IDC_Last,BM_SETCHECK,BST_CHECKED,0);
SetDriver(i);
}
// LPC thread
DWORD WINAPI LPCTask( LPVOID Dummy )
{ int Exit, DelayConst, Result;
MSG msg;
BOOL Success;
Exit=FALSE;
do
{ WaitMessage(); // Wake up when messages arrive
if (Result=GetMessage(&msg,NULL,0,0))
{ if (Result==-1)
break;
if(msg.message==WM_COMMAND)
{ AbortLPC=0;
DelayConst=GetDlgItemInt(Hwnd,IDC_Delay,&Success,FALSE);
LPC_Delay=Success?DelayConst:0;
switch(LOWORD(msg.wParam))
{ case IDC_ChipID:
ReadFlashID();
break;
case IDC_Verify:
WriteVerifyLPC(Hwnd,0);
break;
case IDC_Write:
WriteVerifyLPC(Hwnd,1);
break;
case IDC_Program:
FlashErase();
WriteVerifyLPC(Hwnd,2);
break;
case IDC_Read:
ReadLPC(Hwnd);
break;
case IDC_Erase:
FlashErase();
/* Flow through */
case IDC_BlankCheck:
BlankCheck();
SetProgress(0);
break;
}
if (AbortLPC)
Puts("-- Operation Aborted --");
}
}
else
{ Exit=TRUE;
}
} while (!Exit);
}
BOOL CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ Hwnd = hwnd;
switch(msg)
{ case WM_INITDIALOG:
InitCommonControls();
StartUpIoPorts(hwnd);
// LPC_Init();
GUI_Init(hwnd);
MsgThread=CreateThread(NULL,0,LPCTask,NULL,0,&ThreadID);
if(MsgThread)
break;
/* Fall through if task creation failed */
case WM_CLOSE:
EndDialog(hwnd,0);
break;
case WM_COMMAND:
switch LOWORD(wParam)
{ case IDC_Abort:
AbortLPC=1;
break;
// LPC commands -> process them in LPCTask
case IDC_ChipID:
case IDC_Verify:
case IDC_Write:
case IDC_Program:
case IDC_Read:
case IDC_Erase:
case IDC_BlankCheck:
PostThreadMessage(ThreadID,WM_COMMAND,wParam,lParam);
break;
}
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{ return DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DialogProc);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -