有点乱...嘿嘿
第一次用c编写Windows的窗口程序。
SubTitleCombination.cpp关于窗口界面的,足足花了我一个星期,在上班的时候自己偷偷写的。
StrCombination.cpp,处理字幕整合。花了我一天的时间,主要是malloc的问题。
写好之后,很不满意,如果有时间的话,再把代码好好整理整理。
ps:
用vs编译代码之前,要先将unicode 改成 multicode。
在项目属性里面。
程序运行效果见:
http://blog.youkuaiyun.com/zhanjh/archive/2008/11/09/3261000.aspx
下载地址(在csdn上下东西还真够麻烦的,可惜找不到其他的地方):
http://d.download.youkuaiyun.com/down/762283/zhanjh
StrCombination.cpp
StrCombination.h
SubTitleCombination.cpp
第一次用c编写Windows的窗口程序。
SubTitleCombination.cpp关于窗口界面的,足足花了我一个星期,在上班的时候自己偷偷写的。
StrCombination.cpp,处理字幕整合。花了我一天的时间,主要是malloc的问题。
写好之后,很不满意,如果有时间的话,再把代码好好整理整理。
ps:
用vs编译代码之前,要先将unicode 改成 multicode。
在项目属性里面。
程序运行效果见:
http://blog.youkuaiyun.com/zhanjh/archive/2008/11/09/3261000.aspx
下载地址(在csdn上下东西还真够麻烦的,可惜找不到其他的地方):
http://d.download.youkuaiyun.com/down/762283/zhanjh
StrCombination.cpp
- #include "StrCombination.h"
- #include <stdlib.h>
- #define ST_SIZE 50
- #define ST_TIME_SIZE 29
- #define ST_NUM_SIZE 10
- #define ST_CONTENT_SIZE 250
- #define ST_MALLOC_SIZE 50
- typedef struct tagSubTitle {
- unsigned long index;
- unsigned long time;
- unsigned int csize;
- char strTime[ST_TIME_SIZE];
- char *content;
- tagSubTitle *next;
- }SubTitle, *PSubtitile;
- typedef struct tagSTNode {
- PSubtitile item;
- tagSTNode *next;
- }STNode, *PSTNode;
- unsigned int stm_index = 0;
- unsigned int stm_size = 0;
- PSubtitile head = NULL;
- int error;
- int delay;
- char *allchars;
- unsigned long allcIndex = 0;
- unsigned long mergedSize = 0;
- unsigned long subtIndex = 0;
- PSTNode pstNodeHead = NULL;
- PSTNode pstNode = NULL;
- bool getSubTitle(PSubtitile pst, char *subT, unsigned long &index);
- void extendPChar(PSubtitile pst,int oldSize, int newSize);
- void st_free(PSubtitile pst);
- PSubtitile mergeSubTitle(PSubtitile pst1, PSubtitile pst2);
- PSubtitile newPst()
- {
- if(stm_index == 0 || stm_index >= ST_MALLOC_SIZE)
- {
- if(pstNodeHead == NULL)
- {
- pstNodeHead = (PSTNode)malloc(sizeof(tagSTNode));
- pstNodeHead->item = NULL;
- pstNodeHead->next = NULL;
- pstNode =pstNodeHead;
- }
- stm_size += ST_MALLOC_SIZE;
- PSTNode pstnode = (PSTNode)malloc(sizeof(tagSTNode));
- pstnode->item = (PSubtitile)malloc(ST_MALLOC_SIZE * sizeof(tagSubTitle));
- pstnode->next = NULL;
- pstNode->next = pstnode;
- pstNode = pstnode;
- stm_index = 0;
- }
- PSubtitile pst = pstNode->item + stm_index;
- pst->content = NULL;
- pst->next = NULL;
- stm_index++;
- return pst;
- }
- int tenExp(unsigned int i)
- {
- if(i==0)
- return 0;
- int result = 10;
- while(i>0)
- {
- result *= 10;
- i --;
- }
- }
- char *getMergedChars()
- {
- unsigned long tempSBTIndex = subtIndex;
- int tempDigitSize = 0;
- while(tempSBTIndex != 0)
- {
- tempSBTIndex /= 10;
- tempDigitSize ++;
- }
- unsigned long numberSize = 0;
- for(int i = 1; i<tempDigitSize; i++)
- {
- numberSize += i * (tenExp(i) - tenExp(i-1));
- }
- numberSize += tempDigitSize * (subtIndex - tenExp(tempDigitSize-1));
- mergedSize += numberSize;
- char *result = (char *)malloc(mergedSize * sizeof(char));
- unsigned long stIndex = 1;
- unsigned long index = 0;
- while(head->next != NULL)
- {
- head = head->next;
- int digitSize = 0;
- int tempIndex = stIndex;
- while(tempIndex != 0)
- {
- for(int i= 0; i < digitSize; i++)
- {
- result[index - i] = result[index -i - 1];
- }
- result[index - digitSize] = tempIndex % 10 + 48;
- tempIndex /= 10;
- index ++;
- digitSize ++;
- }
- stIndex ++;
- result[index++] = 13;
- result[index++] = 10;
- for(int i = 0; i < ST_TIME_SIZE; i++)
- {
- result[index++] = head->strTime[i];
- }
- result[index++] = 13;
- result[index++] = 10;
- for(int i = 0; i < head->csize; i++)
- {
- result[index++] = head->content[i];
- }
- result[index++] = 13;
- result[index++] = 10;
- result[index++] = 13;
- result[index++] = 10;
- }
- result[index] = 0;
- mergedSize = index + 1;
- return result;
- }
- char *newPChar()
- {
- char *result = allchars + allcIndex;
- return result;
- }
- void addToAllChars(char c)
- {
- allchars[allcIndex] = c;
- allcIndex ++;
- }
- char* ST_Merge(char subT1[], char subT2[],unsigned long &mgSize, int stcSize,int parameterDelay, int parameterError)
- {
- allchars = (char *)malloc(2 * stcSize * sizeof(char));
- delay = parameterDelay;
- error = parameterError;
- unsigned long index1 = 0;
- unsigned long index2 = 0;
- unsigned long time1 = 0;
- unsigned long time2 = 0;
- unsigned long index = 1;
- PSubtitile pst1;
- PSubtitile pst2;
- PSubtitile list;
- head = newPst();
- pst1 = newPst();
- pst2 = newPst();
- list = head;
- while(!(subT1[index1] == 0 && subT2[index2] == 0))
- {
- if(time1 <= time2 && subT1[index1] != 0)
- {
- pst1 = newPst();
- getSubTitle(pst1, subT1, index1);
- time1 = pst1->time;
- list = mergeSubTitle(list, pst1);
- }
- else
- {
- pst2 = newPst();
- getSubTitle(pst2, subT2, index2);
- time2 = pst2->time;
- list = mergeSubTitle(list, pst2);
- }
- }
- char *result = getMergedChars();
- mgSize = mergedSize;
- ST_Clearup();
- return result;
- }
- PSubtitile mergeSubTitle(PSubtitile pst1, PSubtitile pst2)
- {
- if(pst1->content == NULL)
- {
- if(pst2->content != NULL)
- {
- pst1->next = pst2;
- pst2->index = 1;
- mergedSize += pst2->csize + ST_TIME_SIZE + 2;
- subtIndex = pst2->index;
- return pst2;
- }
- else
- return pst1;
- }
- if((pst2->time <= pst1->time + error) && (pst2->time + error >= pst1->time)){
- unsigned int csize = pst1->csize + pst2->csize + 2;
- mergedSize +=pst2->csize + 2 + ST_TIME_SIZE + 2;
- char *c = newPChar();
- int cindex = 0;
- for(int i = 0; i < pst1->csize; i++)
- {
- addToAllChars(pst1->content[i]);
- cindex ++;
- }
- addToAllChars(13);
- addToAllChars(10);
- for(int i = 0; i < pst2->csize; i++)
- {
- addToAllChars(pst2->content[i]);
- cindex ++;
- }
- pst1->content = c;
- pst1->csize = csize;
- return pst1;
- }
- else
- {
- pst1->next = pst2;
- pst2->index = pst1->index + 1;
- mergedSize += pst2->csize + ST_TIME_SIZE + 2;
- subtIndex = pst2->index;
- return pst2;
- }
- }
- void st_free(PSubtitile pst)
- {
- free(pst->content);
- if(pst->next != NULL)
- st_free(pst->next);
- free(pst);
- }
- bool isSTEnd(char *subT, unsigned long &index)
- {
- if(subT[index] == 0)
- return true;
- if(subT[index+3] == 0)
- {
- index += 3;
- return true;
- }
- if(subT[index] == 13 && subT[index+1] == 10 && subT[index+2] == 13 && subT[index+3] == 10)
- {
- int tempIndex = index + 4;
- int digit = 0;
- int nextIndex = 0;
- while(subT[tempIndex] == 32 ||
- (subT[tempIndex] == 13 && subT[tempIndex+1] == 10) ||
- (subT[tempIndex-1] == 13 && subT[tempIndex] == 10))
- {
- tempIndex ++;
- }
- nextIndex = tempIndex;
- while(subT[tempIndex] >= 48 && subT[tempIndex] <= 57)
- {
- digit ++;
- tempIndex ++;
- }
- if(digit = 0)
- return false;
- while(subT[tempIndex] == 32)
- tempIndex ++;
- if(subT[tempIndex] == 13 && subT[tempIndex+1] == 10)
- {
- index = nextIndex;
- return true;
- }
- }
- return false;
- }
- bool getSubTitle(PSubtitile pst, char *subT, unsigned long &index)
- {
- if(pst == NULL)
- return false;
- if(subT[index] <= 0)
- return false;
- while(!(subT[index] == 13 && subT[index+1] == 10))
- index ++;
- while(subT[index] == 32 ||
- (subT[index] == 13 && subT[index+1] == 10) ||
- (subT[index-1] == 13 && subT[index] == 10))
- {
- index ++;
- }
- pst->time = ((unsigned long)(((subT[index]-48) * 10 + (subT[index+1] -48)) * 60 * 60 +
- ((subT[index+3]-48) * 10 + (subT[index+4] -48)) * 60 +
- ((subT[index+6]-48) * 10 + (subT[index+7] -48)))) * 1000 +
- (subT[index+9]-48) * 100 + (subT[index+10]-48) * 10 + (subT[index+11]-48);
- int tstIndex = 0;
- while(!(subT[index] == 13 &&subT[index+1] == 10))
- {
- if(subT[index] != 32 || (subT[index] == 32 && subT[index+1] != 32))
- {
- pst->strTime[tstIndex] = subT[index];
- tstIndex ++;
- }
- index ++;
- }
- index += 2;
- /*for(int i = 0; i< ST_TIME_SIZE; i++)
- {
- pst->strTime[i] = subT[index+i];
- }
- index += 31;*/
- int contentSize = 0;
- int cindex = 0;
- pst->content = newPChar();
- while(!isSTEnd(subT, index))
- {
- addToAllChars(subT[index]);
- cindex ++;
- index ++;
- }
- pst->csize = cindex;
- return true;
- }
- void extendPChar(PSubtitile pst,int oldSize, int newSize)
- {
- char *b = (char *)malloc(newSize * sizeof(char));
- pst->content = newPChar();
- if(oldSize > 0)
- {
- for(int i = 0; i < oldSize; i++)
- {
- b[i] = pst->content[i];
- }
- }
- pst->content = b;
- }
- void ST_Clearup()
- {
- PSTNode pnode;
- do{
- pnode = pstNodeHead;
- pstNodeHead = pstNodeHead->next;
- free(pnode->item);
- free(pnode);
- }while(pstNodeHead != NULL);
- free(allchars);
- stm_index = 0;
- stm_size = 0;
- head = NULL;
- error;
- delay;
- allcIndex = 0;
- mergedSize = 0;
- subtIndex = 0;
- pstNodeHead = NULL;
- pstNode = NULL;
- }
- #if !defined STR_COMBINATION_H
- #define STR_COMBINATION_H
- void ST_Initialize();
- char* ST_Merge(char subT1[], char subT2[],unsigned long &mgSize, int stcSize,int parameterDelay, int parameterError);
- void ST_Clearup();
- #endif
- #include <windows.h>
- #include "StrCombination.h"
- #define IDC_TITLE_LEFT 101
- #define IDC_BTN_OPEN_LEFT 102
- #define IDC_TITLE_RIGHT 103
- #define IDC_BTN_OPEN_RIGHT 104
- #define IDC_BTN_SAVE_LEFT 105
- #define IDC_BTN_SAVE_RIGHT 106
- #define IDC_TEXT_LEFT 201
- #define IDC_TEXT_RIGHT 202
- #define IDC_NUMBER_DELAY 301
- #define IDC_NUMBER_EORROR 302
- #define IDC_BTN_MERGE_LEFT 303
- #define IDC_BTN_MERGE_RIGHT 304
- #define IDC_LABEL_DELAY 305
- #define IDC_LABEL_ERROR 306
- const char g_szClassName[] = "dowClass";
- LPSTR pszSubtitleDest;
- LPSTR pszSubtitleSrc;
- BOOL getFileName(HWND hwnd,char pszFileName[], bool isForSave)
- {
- OPENFILENAME ofn;
- ZeroMemory(&ofn, sizeof(ofn));
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hwnd;
- ofn.lpstrFilter = "Srt Files (*.srt)/0*.srt/0All Files (*.*)/0*.*/0";
- ofn.lpstrFile = pszFileName;
- ofn.nMaxFile = MAX_PATH;
- if(isForSave)
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
- else
- ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
- ofn.lpstrDefExt = "srt";
- return GetOpenFileName(&ofn);
- }
- LPSTR getWinText(HWND hEdit, DWORD &dwBuffSize)
- {
- DWORD dwSize = GetWindowTextLength(hEdit);
- dwBuffSize = dwSize + 1;
- LPSTR result = (LPSTR)GlobalAlloc(GPTR,dwBuffSize); //(LPSTR)GlobalAlloc(GPTR, dwBufferSize)
- GetWindowText(hEdit, result, dwBuffSize);
- return result;
- }
- void DoFileSave(HWND hwnd, LPSTR lps, DWORD buffsize, HWND hEdit)
- {
- char pszFileName[MAX_PATH] = "";
- if(!getFileName(hwnd, pszFileName, false))
- return;
- HANDLE hFile;
- hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, NULL,
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if(hFile != INVALID_HANDLE_VALUE)
- {
- DWORD dwWritten;
- WriteFile(hFile, lps, buffsize, &dwWritten, NULL);
- }
- SetWindowText(hEdit, lps);
- free(lps);
- CloseHandle(hFile);
- }
- void doFileMerge(HWND hwnd, DWORD destId, DWORD srcId)
- {
- DWORD bsizeDest = 0, bsizeSrc= 0, bsizeMg;
- pszSubtitleDest = getWinText(GetDlgItem(hwnd,destId), bsizeDest);
- pszSubtitleSrc = getWinText(GetDlgItem(hwnd, srcId), bsizeSrc);
- BOOL bSuccess = FALSE;
- int delay = GetDlgItemInt(hwnd,IDC_NUMBER_DELAY,&bSuccess, FALSE);
- if(!bSuccess)
- delay = 0;
- int error = GetDlgItemInt(hwnd, IDC_NUMBER_EORROR, &bSuccess, FALSE);
- if(!bSuccess)
- error = 0;
- LPSTR pszCombination = ST_Merge(pszSubtitleDest, pszSubtitleSrc, bsizeMg, bsizeDest+bsizeSrc, delay, error);
- DoFileSave(hwnd, pszCombination, bsizeMg, GetDlgItem(hwnd,destId));
- }
- BOOL loadSrtFileToEdit(HWND hEdit, LPCTSTR pszFileName)
- {
- HANDLE hFile;
- BOOL bSuccess = FALSE;
- hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
- OPEN_EXISTING, 0, NULL);
- if(hFile != INVALID_HANDLE_VALUE)
- {
- DWORD dwFileSize;
- dwFileSize = GetFileSize(hFile, NULL);
- if(dwFileSize != 0xFFFFFFFF)
- {
- LPSTR pszFileText;
- pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize + 1);
- if(pszFileText != NULL)
- {
- DWORD dwRead;
- if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL))
- {
- pszFileText[dwFileSize] = 0; // Add null terminator
- if(SetWindowText(hEdit, pszFileText))
- bSuccess = TRUE; // It worked!
- }
- GlobalFree(pszFileText);
- }
- }
- CloseHandle(hFile);
- }
- return bSuccess;
- }
- void doFileLoad(HWND hwnd, DWORD titleId, DWORD contentId)
- {
- HWND hTitle;
- HWND hEdit;
- char pszFileName[MAX_PATH] = "";
- if(!getFileName(hwnd, pszFileName, true))
- return;
- hTitle = GetDlgItem(hwnd, titleId);
- if(hTitle == NULL)
- {
- MessageBox(hwnd, "Cannot find hTitle", "Error", MB_OK | MB_ICONERROR);
- return;
- }
- if(!SetWindowText(hTitle, pszFileName))
- {
- GlobalFree(pszFileName);
- return;
- }
- hEdit = GetDlgItem(hwnd, contentId);
- if(hEdit == NULL)
- {
- MessageBox(hwnd, "Cannot find hEdit", "Error", MB_OK | MB_ICONERROR);
- return;
- }
- if(loadSrtFileToEdit(hEdit,pszFileName))
- {
- }
- }
- HWND addHEdit(HWND hWndParent,DWORD hWndId,DWORD dwStyle, int x, int y, int nWidth, int nHeight)
- {
- HFONT hfDefault;
- HWND hEdit;
- hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
- dwStyle,
- x, y, nWidth, nHeight, hWndParent, (HMENU)hWndId, GetModuleHandle(NULL), NULL);
- if(hEdit == NULL)
- MessageBox(hWndParent, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
- hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
- SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
- return hEdit;
- }
- void addText(HWND hwnd, PCSTR pszTxt,DWORD hwndId, int x, int y)
- {
- HWND htxt;
- HFONT hfDefault;
- hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
- htxt= CreateWindowEx(WS_EX_TRANSPARENT,
- "Static",pszTxt,WS_CHILD | WS_VISIBLE ,
- x, y, 50, 15, hwnd, (HMENU)hwndId, GetModuleHandle(NULL),NULL);
- LOGFONT stFont;
- memset(&stFont, 0, sizeof(LOGFONT));
- stFont.lfHeight = 14;
- stFont.lfWeight = FW_NORMAL;
- WPARAM wp = (WPARAM)CreateFontIndirect(&stFont);
- SendMessage(htxt, WM_SETFONT,wp,MAKELPARAM(FALSE,0));
- }
- HWND addContentEdit(HWND hWndParent,DWORD hWndId, int x, int y, int nWidth, int nHeight)
- {
- return addHEdit(hWndParent, hWndId,
- WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_READONLY ,
- x, y, nWidth, nHeight);
- }
- HWND addTitleEdit(HWND hWndParent,DWORD hWndId, int x, int y, int nWidth, int nHeight)
- {
- return addHEdit(hWndParent,hWndId,
- WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_READONLY ,
- x, y, nWidth, nHeight);
- }
- HWND addNumberEdit(HWND hWndParent,DWORD hWndId, int x, int y, int nWidth, int nHeight)
- {
- return addHEdit(hWndParent,hWndId,
- WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_NUMBER ,
- x, y, nWidth, nHeight);
- }
- HWND addButton(HWND hWndParent, DWORD hWndId,PCSTR pszName, int x, int y)
- {
- HWND hBtn;
- hBtn=CreateWindowEx(0,"BUTTON",pszName,WS_CHILD|WS_VISIBLE|BS_FLAT|WS_BORDER,
- x,y,40,20,hWndParent,(HMENU)hWndId,GetModuleHandle(NULL),NULL);
- return hBtn;
- }
- HWND addSButton(HWND hWndParent, DWORD hWndId,PCSTR pszName, int x, int y)
- {
- HWND hBtn;
- hBtn=CreateWindowEx(0,"BUTTON",pszName,WS_CHILD|WS_VISIBLE|BS_FLAT|WS_BORDER,
- x,y,25,20,hWndParent,(HMENU)hWndId,GetModuleHandle(NULL),NULL);
- return hBtn;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch(msg)
- {
- case WM_CREATE:
- {
- addTitleEdit(hwnd, IDC_TITLE_LEFT,5 ,5, 200, 20);
- addTitleEdit(hwnd, IDC_TITLE_RIGHT, 430, 5, 200, 20);
- addContentEdit(hwnd, IDC_TEXT_LEFT, 5, 30, 350, 530);
- addContentEdit(hwnd, IDC_TEXT_RIGHT, 430, 30, 350, 530);
- addButton(hwnd, IDC_BTN_OPEN_LEFT, "open", 210, 5);
- addButton(hwnd, IDC_BTN_OPEN_RIGHT, "open", 635, 5);
- addText(hwnd, "Delay/ms",IDC_LABEL_DELAY, 365, 85);
- addNumberEdit(hwnd,IDC_NUMBER_DELAY,365,100,50,20);
- addText(hwnd, "Eorror/ms",IDC_LABEL_ERROR, 365, 135);
- addNumberEdit(hwnd,IDC_NUMBER_EORROR,365,150,50,20);
- addSButton(hwnd, IDC_BTN_MERGE_LEFT, "<=", 362, 205);
- addSButton(hwnd, IDC_BTN_MERGE_RIGHT, "=>", 392, 205);
- }
- break;
- case WM_SIZE:
- {
- RECT rcClient;
- GetClientRect(hwnd, &rcClient);
- HWND teLeft = GetDlgItem(hwnd, IDC_TITLE_LEFT);
- HWND teRight = GetDlgItem(hwnd, IDC_TITLE_RIGHT);
- HWND boLeft = GetDlgItem(hwnd, IDC_BTN_OPEN_LEFT);
- HWND boRight = GetDlgItem(hwnd, IDC_BTN_OPEN_RIGHT);
- HWND ceLeft = GetDlgItem(hwnd, IDC_TEXT_LEFT);
- HWND ceRight = GetDlgItem(hwnd, IDC_TEXT_RIGHT);
- HWND nmDelay = GetDlgItem(hwnd, IDC_NUMBER_DELAY);
- HWND nmError = GetDlgItem(hwnd, IDC_NUMBER_EORROR);
- HWND lDelay = GetDlgItem(hwnd, IDC_LABEL_DELAY);
- HWND lError = GetDlgItem(hwnd, IDC_LABEL_ERROR);
- HWND bmLeft = GetDlgItem(hwnd, IDC_BTN_MERGE_LEFT);
- HWND bmRight = GetDlgItem(hwnd, IDC_BTN_MERGE_RIGHT);
- int xCenter = rcClient.right / 2;
- int lLeft = 430 * rcClient.right/800;
- int cHeight = 565 * rcClient.bottom / 600;
- int cWidth = 365 * rcClient.right / 800;
- SetWindowPos(teLeft, NULL,5,5, 200, 20, SWP_NOZORDER);
- SetWindowPos(teRight, NULL, lLeft, 5, 200, 20, SWP_NOZORDER);
- SetWindowPos(boLeft, NULL, 210, 5,40, 20, SWP_NOZORDER);
- SetWindowPos(boRight, NULL, lLeft + 205, 5,40, 20, SWP_NOZORDER);
- SetWindowPos(ceLeft, NULL, 5, 30, cWidth,cHeight, SWP_NOZORDER);
- SetWindowPos(ceRight, NULL, lLeft, 30, cWidth,cHeight, SWP_NOZORDER);
- SetWindowPos(nmDelay, NULL, xCenter - 25, 100, 50, 20 ,SWP_NOZORDER);
- SetWindowPos(nmError, NULL, xCenter - 25, 150, 50, 20, SWP_NOZORDER);
- SetWindowPos(lDelay, NULL, xCenter - 25, 85, 50, 15, SWP_NOZORDER);
- SetWindowPos(lError, NULL, xCenter - 25, 135, 50, 15, SWP_NOZORDER);
- SetWindowPos(bmLeft, NULL, xCenter - 26, 205, 25, 20, SWP_NOZORDER);
- SetWindowPos(bmRight, NULL, xCenter + 4, 205, 25, 20, SWP_NOZORDER);
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_BTN_OPEN_LEFT:
- {
- doFileLoad(hwnd, IDC_TITLE_LEFT, IDC_TEXT_LEFT);
- }
- break;
- case IDC_BTN_OPEN_RIGHT:
- {
- doFileLoad(hwnd, IDC_TITLE_RIGHT, IDC_TEXT_RIGHT);
- }
- break;
- case IDC_BTN_MERGE_LEFT:
- {
- doFileMerge(hwnd, IDC_TEXT_LEFT, IDC_TEXT_RIGHT);
- }
- break;
- case IDC_BTN_MERGE_RIGHT:
- {
- doFileMerge(hwnd, IDC_TEXT_RIGHT, IDC_TEXT_LEFT);
- }
- break;
- }
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- MSG Msg;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = g_szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- "字幕合并器",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 800, 600,
- NULL, NULL, hInstance, NULL);
- if(hwnd == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while(GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }