#include #include #include static char g_szClassName[] = "MyWindowClass"; static HINSTANCE g_hInst = NULL; HMENU hMenu, hSubMenu; HWND ListView; unsigned char dsp_mem[0x20000]; #define IDC_EDIT_1 1001 #define CM_FILE_OPEN 9001 #define CM_FILE_SAVE 9002 #define CM_FILE_EXIT 9003 #define CM_STUFF_REFRESH 9011 #define CM_STUFF_GO2 9012 #define IDC_BTN_1 102 #define IDC_STATIC_1 201 #define IDC_LIST_1 301 #define IDC_LIST_2 302 #define BUFFER_SIZE 256 #define NO_OF_COLS 17 //#define MAX_PATH 512 clear_dsp_mem(char *dsp_mem) { int i; for(i=0;i<0x20000;i++) { dsp_mem[i] = 0; } } BOOL LoadFile(HWND hwnd, LPSTR pszFileName) { HANDLE hFile; BOOL bSuccess = FALSE; hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwFileSize; dwFileSize = GetFileSize(hFile, NULL); if(dwFileSize != 0xFFFFFFFF) { DWORD dwRead; if(dwFileSize >0x20000) dwFileSize = 0x20000; if(ReadFile(hFile, dsp_mem, dwFileSize, &dwRead, NULL)) { //MessageBox(hwnd, "read dsp_mem ok", "read mem", MB_OK); bSuccess = TRUE; // It worked! } } CloseHandle(hFile); } return bSuccess; } LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { char szText[BUFFER_SIZE]; LV_COLUMN lvc; LVITEM LvItem; int i,j; OPENFILENAME ofn; char szFileName[MAX_PATH]; switch(Message) { case WM_CREATE: ListView = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, "listview1", LVS_REPORT|LVS_EDITLABELS|WS_BORDER|WS_TABSTOP|LVS_SINGLESEL| WS_CHILD|WS_VISIBLE, 0, 0, 600, 180, hwnd, (HMENU) IDC_LIST_2, g_hInst, NULL); SendMessage(ListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT); memset(&lvc, 0, sizeof(LV_COLUMN) ); lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT; lvc.fmt = LVCFMT_RIGHT; // first column lvc.iSubItem = 0; lvc.cx = 60; lvc.cchTextMax = 10; lvc.pszText = "Nr."; SendMessage(ListView, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc); for(i=0;i<16;i++) { // second column lvc.fmt = LVCFMT_CENTER; lvc.iSubItem = i; lvc.cx = 30; lvc.cchTextMax = 2; sprintf(szText, "%X", i); lvc.pszText = szText; SendMessage(ListView, LVM_INSERTCOLUMN, i+2, (LPARAM)&lvc); } memset(&LvItem,0,sizeof(LvItem)); // Zero struct's Members // Setting properties Of members: LvItem.mask=LVIF_TEXT; LvItem.cchTextMax = 256; for(i=0;i<8;i++) { LvItem.iItem=i; LvItem.iSubItem=0; sprintf(szText, "%08X", i*0x10); LvItem.pszText= szText; SendMessage(ListView,LVM_INSERTITEM,0,(LPARAM)&LvItem); for(j=0;j<16;j++) { LvItem.iSubItem= j+1; LvItem.iItem=i; sprintf(szText, "%02X", j); LvItem.pszText=szText; SendMessage(ListView,LVM_SETITEM,0,(LPARAM)&LvItem); } } //CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", // WS_CHILD|WS_VISIBLE|WS_OVERLAPPED| // ES_WANTRETURN, 10, 10, 100, // 20, hwnd, (HMENU) IDC_EDIT_1, g_hInst, NULL); //CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "list1", // LBS_NOTIFY|WS_CHILD|WS_VISIBLE|WS_OVERLAPPED| // ES_WANTRETURN, 150, 10, 100, // 100, hwnd, (HMENU) IDC_LIST_1, g_hInst, NULL); //CreateWindowEx(0, "BUTTON", "View", // BS_DEFPUSHBUTTON|BS_CENTER|WS_CHILD| // WS_VISIBLE|WS_TABSTOP, 30, 150, 100, // 30, hwnd, (HMENU) IDC_BTN_1, g_hInst, NULL); //CreateWindowEx(0, "STATIC", "static", // SS_SIMPLE|SS_NOPREFIX|WS_CHILD|WS_VISIBLE|WS_TABSTOP, 30, 200, 100, // 30, hwnd, (HMENU) IDC_STATIC_1, g_hInst, NULL); hMenu = CreateMenu(); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, CM_FILE_OPEN, "&Open"); AppendMenu(hSubMenu, MF_STRING, CM_FILE_SAVE, "&Save"); AppendMenu(hSubMenu, MF_STRING, CM_FILE_EXIT, "E&xit"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File"); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, CM_STUFF_REFRESH, "&Refresh"); AppendMenu(hSubMenu, MF_STRING, CM_STUFF_GO2, "&Go2"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff"); SetMenu(hwnd, hMenu); break; case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_BTN_1: GetDlgItemText(hwnd, IDC_EDIT_1, szText, BUFFER_SIZE); SetDlgItemText(hwnd, IDC_STATIC_1, szText); return TRUE; case CM_STUFF_REFRESH: //MessageBox(hwnd, "refresh disp", "refresh", MB_OK); memset(&LvItem,0,sizeof(LvItem)); // Zero struct's Members // Setting properties Of members: LvItem.mask=LVIF_TEXT; LvItem.cchTextMax = 256; for(i=0;i<8;i++) { LvItem.iItem=i; LvItem.iSubItem=0; sprintf(szText, "%08X", i*0x10); LvItem.pszText= szText; SendMessage(ListView,LVM_SETITEM,0,(LPARAM)&LvItem); for(j=0;j<16;j++) { LvItem.iSubItem= j+1; LvItem.iItem=i; sprintf(szText, "%02X", dsp_mem[i*0x10+j]&0xff); LvItem.pszText=szText; SendMessage(ListView,LVM_SETITEM,0,(LPARAM)&LvItem); } } return TRUE; case CM_STUFF_GO2: GetDlgItemText(hwnd, IDC_EDIT_1, szText, BUFFER_SIZE); SetDlgItemText(hwnd, IDC_STATIC_1, szText); return TRUE; case CM_FILE_SAVE: ZeroMemory(&ofn, sizeof(ofn)); szFileName[0]=0; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Fls files (*.fls)\0*.fls\0All files (*.*)\0*.*\0\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; ofn.lpstrDefExt = "fls"; if(GetOpenFileName(&ofn)) { MessageBox(hwnd, szFileName, "You chose to save...", MB_OK); } return TRUE; case CM_FILE_OPEN: ZeroMemory(&ofn, sizeof(ofn)); szFileName[0]=0; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Fls files (*.fls)\0*.fls\0All files (*.*)\0*.*\0\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY; ofn.lpstrDefExt = "fls"; if(GetOpenFileName(&ofn)) { //MessageBox(hwnd, szFileName, "You chose to open...", MB_OK); LoadFile(hwnd, szFileName); } return TRUE; case CM_FILE_EXIT: DestroyWindow(hwnd); return TRUE; } break; case WM_SIZE: //if(wParam != SIZE_MINIMIZED) //MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 10, 10, 100, // 50, TRUE); break; case WM_LBUTTONDOWN: MessageBox(hwnd, "left click","message", MB_OK|MB_ICONINFORMATION); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, Message, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX WndClass; HWND hwnd; MSG Msg; INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwICC = ICC_LISTVIEW_CLASSES; InitCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX); BOOL bRet = InitCommonControlsEx(&InitCtrls); g_hInst = hInstance; clear_dsp_mem(dsp_mem); WndClass.cbSize = sizeof(WNDCLASSEX); WndClass.style = NULL; WndClass.lpfnWndProc = WndProc; WndClass.cbClsExtra = 0; WndClass.cbWndExtra = 0; WndClass.hInstance = g_hInst; WndClass.hIcon = 0; WndClass.hCursor = 0; WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); WndClass.lpszMenuName = NULL; WndClass.lpszClassName = g_szClassName; WndClass.hIconSm = 0; if(!RegisterClassEx(&WndClass)) { MessageBox(0, "Window reg failed", "error", MB_ICONEXCLAMATION|MB_OK|MB_SYSTEMMODAL); return 0; } hwnd = CreateWindowEx( WS_EX_WINDOWEDGE, g_szClassName, "title of window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 620, 400, NULL, NULL, g_hInst, NULL); if(hwnd == NULL) { MessageBox(0, "window creation failed", "error", MB_ICONEXCLAMATION|MB_OK|MB_SYSTEMMODAL); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }