#include <windows.h>
#define CM_FILE_SAVEAS 9072
#define CM_FILE_EXIT 9071
#define CM_FILE_OPEN 9070
#define CM_ABOUT 9069
#define CM_START 9068
#define CM_STOP 9067
#define CM_PORT 9065
#define IDD_DLG_MAIN 1000
#define IDC_BTN_TEST 1001
#define IDC_EDT1 1002
#define IDC_BTN_CANCEL 1003
#define IDC_LSTBOX1 1004
#define IDC_CMBOX1 1005
#define ID_TIMER 100
#define TIMERSTART_MSG 101
#define TIMERSTOP_MSG 102
++dlg.rc+++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "Main.h"
IDD_DLG_MAIN DIALOGEX 10,10,315,192
CAPTION "IDD_DLG"
FONT 8,"MS Sans Serif",0,0
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
BEGIN
CONTROL "OK",IDC_BTN_TEST,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,198,132,54,15
CONTROL "CANCEL",IDC_BTN_CANCEL,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,198,152,54,15
// CONTROL "",IDC_EDT1,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|ES_MULTILINE,12,6,249,23,WS_EX_CLIENTEDGE
// CONTROL "",IDC_LSTBOX1,"ListBox",WS_CHILDWINDOW|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|ES_MULTILINE,12,30,249,23,WS_EX_CLIENTEDGE
CONTROL "",IDC_CMBOX1,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|ES_MULTILINE,12,60,249,53,WS_EX_CLIENTEDGE
END
+++++++++++Menu.rc+++++++++
#include "Main.h"
MAINMENU MENU
{
POPUP "&Setting"
{
MENUITEM "&Setting...", CM_FILE_OPEN
MENUITEM "Save &As...", CM_FILE_SAVEAS
MENUITEM SEPARATOR
MENUITEM "E&xit", CM_FILE_EXIT
}
POPUP "&Service"
{
MENUITEM "&Start", CM_START
MENUITEM "&Stop", CM_STOP
MENUITEM "&Port", CM_PORT
}
POPUP "&Help"
{
MENUITEM "&About", CM_ABOUT
}
}
++++++++++++++++++++++++++++++++++++++++
#include "Main.h"
#include <stdio.h>
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
static int g_isModaling = TRUE;
static HWND ghEdit = NULL;
static int g_nModalCode = 0;
static HANDLE gThreadhandle = NULL;
static HANDLE ghEvent=NULL;
static UINT gTimerId;
static SOCKET gsClient;
static DWORD gMainThreadId;
static FILE* gLogFile = NULL;
#define IDC_MAIN_TEXT 1001
BOOL CALLBACK DlgWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
void UpdateInfo(HWND hwnd, LPSTR msg);
void Log(LPSTR msg);
void Initialization()
{
Log("System Initialization...");
gMainThreadId = GetCurrentThreadId();
}
void Exit()
{
Log("System Exit...");
}
void Log(LPSTR rawmsg)
{
DWORD msglen = sizeof(rawmsg) + 20;
char msg[msglen];
memset(msg, 0, msglen);
SYSTEMTIME p;
GetLocalTime(&p);
sprintf(msg, "%d-%d-%d %d:%d:%d:%d@%s\r\n", p.wYear, p.wMonth, p.wDay, p.wHour, p.wMinute, p.wSecond, p.wMilliseconds, rawmsg);
gLogFile = fopen("log.txt", "a+");
fputs(msg, gLogFile);
fclose(gLogFile);
}
void CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
SYSTEMTIME st;
GetLocalTime(&st);
UpdateInfo(ghEdit, "Start to close socket...") ;
Log("Timer invoked, close socket session by force...");
closesocket(gsClient);
}
BOOL LoadFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, 0, 0);
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; // Null terminator
if(SetWindowText(hEdit, pszFileText))
bSuccess = TRUE; // It worked!
}
GlobalFree(pszFileText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
void UpdateInfo(HWND hEdit, LPSTR rawmsg)
{
BOOL bSuccess = FALSE;
DWORD msglen = 50;
char msg[msglen];
memset(msg, 0, msglen);
SYSTEMTIME p;
GetLocalTime(&p);
sprintf(msg, "%d-%d-%d %d:%d:%d @ %s\r\n", p.wYear, p.wMonth, p.wDay, p.wHour, p.wMinute, p.wSecond, rawmsg);
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if (dwTextLength > 0)
{
char szFileName[dwTextLength+msglen + 3];
memset(szFileName, 0, dwTextLength+msglen +3);
char oldmsg[dwTextLength];
memset(oldmsg, 0, dwTextLength);
GetWindowText(hEdit, oldmsg, dwTextLength);
memcpy(szFileName, oldmsg, dwTextLength);
memcpy(szFileName+dwTextLength-1, "\r\n", 2);
memcpy(szFileName + dwTextLength + 1, msg, msglen);
memcpy(szFileName + dwTextLength + msglen + 1, "\r", 1);
if(SetWindowText(hEdit,szFileName))
bSuccess = TRUE; // It worked!
}
else
{
char szFileName[msglen + 1];
memset(szFileName, 0, msglen +1);
memcpy(szFileName, msg, msglen);
memcpy(szFileName+msglen, "\r", 1);
if(SetWindowText(hEdit,szFileName))
bSuccess = TRUE; // It worked!
// szFileName[5] = 0;
}
// memcpy(szFileName+dwTextLength, "start service...\r\n", dwMsgLength);
}
DWORD WINAPI ThreadProc1(void *arg)
{
HANDLE hEvent = (HANDLE)arg;
ResetEvent(hEvent); // 设置hEvent为非激发状态
SOCKET socket1;
WSADATA wsaData;
int ErrorCode;
if(WSAStartup(MAKEWORD(2,1),&wsaData))// windows socket dll;
{
UpdateInfo(ghEdit, "WSAStartup error!");
WSACleanup();
return -1;
}
else
{
UpdateInfo(ghEdit, "Socket Initialized Successfully!");
}
const char* ip="127.0.0.1";
struct sockaddr_in server;
int len = sizeof(server);
server.sin_family = AF_INET;
server.sin_port = htons(6999); //the port need listened
server.sin_addr.s_addr = inet_addr(ip);
SOCKET slisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(slisten == INVALID_SOCKET)
{
UpdateInfo(ghEdit, "Socket error!");
WSACleanup();
return -1;
}
else
{
UpdateInfo(ghEdit, "Socket Created Successfully!");
}
if(bind(slisten, (LPSOCKADDR)&server, sizeof(server)) == SOCKET_ERROR)
{
UpdateInfo(ghEdit, "Bind error !");
return -1;
}
else
{
UpdateInfo(ghEdit, "Socket Bind Successfully!");
}
//开始监听
if(listen(slisten, 5) == SOCKET_ERROR)
{
UpdateInfo(ghEdit, "listen error !");
return -1;
}
else
{
UpdateInfo(ghEdit, "Socket Listen Successfully!");
}
struct sockaddr_in remoteAddr;
int nAddrlen = sizeof(remoteAddr);
char revData[255];
while (1)
{
UpdateInfo(ghEdit, "Waitting for connection...");
//Log("Waitting for connecion...");
gsClient = accept(slisten, (SOCKADDR *)&remoteAddr, &nAddrlen);
if(gsClient == INVALID_SOCKET)
{
UpdateInfo(ghEdit, "Accept error !");
continue;
}
memset(revData, 0, 255);
sprintf(revData, "接受到一个连接:%s", inet_ntoa(remoteAddr.sin_addr));
UpdateInfo(ghEdit, revData);
Log(revData);
PostThreadMessage(gMainThreadId, TIMERSTART_MSG, 0, 0);
//接收数据
memset(revData, 0, 255);
int ret = recv(gsClient, revData, 255, 0);
if(ret > 0)
{
revData[ret] = 0x00;
UpdateInfo(ghEdit, revData);
Log(revData);
}
//发送数据
char * sendData = "你好,TCP客户端!\n";
send(gsClient, sendData, strlen(sendData), 0);
PostThreadMessage(gMainThreadId, TIMERSTOP_MSG, 0, 0);
closesocket(gsClient);
/* DWORD waitRet = WaitForSingleObject(hEvent, 1000); // 等待hEvent变为激发状态,超时1s
if (WAIT_OBJECT_0 == waitRet) {
sprintf(msg, "%d-%d-%d %d:%d:%d @ Exit thread...!\r\n", p.wYear, p.wMonth, p.wDay, p.wHour, p.wMinute, p.wSecond);
UpdateInfo(ghEdit, msg, 50);
break;
}
*/
}
closesocket(slisten);
WSACleanup();
return 0;
}
BOOL StopBoxService(HWND hwnd)
{
BOOL bSuccess = FALSE;
KillTimer(NULL, gTimerId);
if (gThreadhandle != NULL)
{
/* SetEvent(ghEvent); // 设置hEvent为激发状态
DWORD waitRet = WaitForSingleObject(gThreadhandle, 5);
switch (waitRet)
{
// case WAIT_TIMEOUT: printf("%#p处于非激发状态, 超时\n", gThreadhandle); break;
// case WAIT_ABANDONED: printf("%#p是一个未释放的Mutex对象\n", gThreadhandle); break;
// case WAIT_OBJECT_0: printf("%#p处于激发状态\n", gThreadhandle); break;
}*/
TerminateThread( gThreadhandle, 12345);
WSACleanup();
CloseHandle(gThreadhandle);
UpdateInfo(ghEdit, "Stop Socket Services...");
gThreadhandle=NULL;
//CloseHandle(ghEvent);
}
return bSuccess;
}
BOOL StartBoxService(HWND hwnd)
{
BOOL bSuccess = FALSE;
HWND hEdit = GetDlgItem(hwnd, IDC_MAIN_TEXT);
ghEdit = hEdit;
SYSTEMTIME p;
GetLocalTime(&p);
//
// char msg[50];
// memset(msg, 0, 50);
//sprintf(msg, "%d-%d-%d %d:%d:%d @ Prepare to Start WinSocket...!\r\n", p.wYear, p.wMonth, p.wDay, p.wHour, p.wMinute, p.wSecond);
UpdateInfo(hEdit, "Prepare to Start WinSocket...!");
// memset(msg, 0, 50);
// ghEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // 创建一个手动控制、初始为非激发状态、未命名的Event对象
if (gThreadhandle == NULL)
gThreadhandle=CreateThread(NULL,0,ThreadProc1,NULL,0,NULL);
/*
SOCKET socket1;
WSADATA wsaData;
int ErrorCode;
if(WSAStartup(MAKEWORD(2,1),&wsaData))// windows socket dll;
{
sprintf(msg, "%d-%d-%d %d:%d:%d @ WSAStartup error!\r\n", p.wYear, p.wMonth, p.wDay, p.wHour, p.wMinute, p.wSecond);
UpdateInfo(hEdit, msg, 50);
WSACleanup();
return FALSE;
}
const char* ip="127.0.0.1";
struct sockaddr_in server;
int len = sizeof(server);
server.sin_family = AF_INET;
server.sin_port = htons(6999); //the port need listened
server.sin_addr.s_addr = inet_addr(ip);
socket1 = socket(AF_INET,SOCK_DGRAM,0);
while (1)
{
char buffer[1024] = "/0";
printf("input message/n");
scanf("%s",buffer);
//printf("%s",buffer);
if(strcmp(buffer,"bye")==0)
{
printf("exit,bye!!/n");
Sleep(100);
closesocket(socket1);
break;
}
if(sendto(socket1,buffer,sizeof(buffer),0,(struct sockaddr*)&server,len)!=SOCKET_ERROR)
{
printf("sending...");
Sleep(100);
if(recvfrom(socket1,buffer,sizeof(buffer),0,(struct sockaddr*)&server,&len) != SOCKET_ERROR)
printf("recevie from server: %s/n",buffer);
}
}
closesocket(socket1);
system("pause");
return FALSE;
// SendDlgItemMessage(hEdit,IDC_MAIN_TEXT,LB_ADDSTRING,0,(LPARAM)"startservice");
/*
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
char szFileName[dwTextLength+7];
memset(szFileName, 0, dwTextLength+7);
if (dwTextLength > 0)
{
char oldmsg[dwTextLength];
memset(oldmsg, 0, dwTextLength);
GetWindowText(hEdit, oldmsg, dwTextLength);
memcpy(szFileName, oldmsg, dwTextLength);
// memcpy(szFileName + dwTextLength, "\r\n", 2);
memcpy(szFileName+dwTextLength-1, "\r\n123\r", 7);
// szFileName[dwTextLength+5] = 0;
szFileName[dwTextLength+5] = 0;
}
else
{
memcpy(szFileName, "123\r", 5);
// szFileName[5] = 0;
}
// memcpy(szFileName+dwTextLength, "start service...\r\n", dwMsgLength);
if(SetWindowText(hEdit,szFileName))
bSuccess = TRUE; // It worked!
*/
return bSuccess;
}
BOOL SaveFile(HWND hEdit, LPSTR pszFileName)
{
HANDLE hFile;
BOOL bSuccess = FALSE;
hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile != INVALID_HANDLE_VALUE)
{
DWORD dwTextLength;
dwTextLength = GetWindowTextLength(hEdit);
if(dwTextLength > 0)// No need to bother if there's no text.
{
LPSTR pszText;
pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1);
if(pszText != NULL)
{
if(GetWindowText(hEdit, pszText, dwTextLength + 1))
{
DWORD dwWritten;
if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
bSuccess = TRUE;
}
GlobalFree(pszText);
}
}
CloseHandle(hFile);
}
return bSuccess;
}
BOOL DoFileOpenSave(HWND hwnd, BOOL bSave)
{
// HINSTANCE g_hFlashWnd = CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_DLG_MAIN), hwnd, (DLGPROC)DlgWndProc );
// ShowWindow( g_hFlashWnd, SW_SHOW );
// MessageBox(hwnd, "", "Notify", MB_OK);
/* HWND hNewWnd = CreateWindow("Dialog", "", WS_POPUP | WS_THICKFRAME, 100, 100, 100, 100, hwnd, NULL, g_hInst, NULL);
int nCode = DoModal(hNewWnd);
TCHAR buffer[MAX_PATH];
MessageBox(hwnd, "", "Notify", MB_OK);
DestroyWindow(hNewWnd);
*/
OPENFILENAME ofn;
char szFileName[MAX_PATH];
ZeroMemory(&ofn, sizeof(ofn));
szFileName[0] = 0;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "txt";
if(bSave)
{
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT;
if(GetSaveFileName(&ofn))
{
if(!SaveFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName))
{
MessageBox(hwnd, "Save file failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
}
else
{
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if(GetOpenFileName(&ofn))
{
if(!LoadFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName))
{
MessageBox(hwnd, "Load of file failed.", "Error",
MB_OK | MB_ICONEXCLAMATION);
return FALSE;
}
}
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
CreateWindow("EDIT", "",
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE |
ES_WANTRETURN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwnd, (HMENU)IDC_MAIN_TEXT, g_hInst, NULL);
SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,
(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
break;
case WM_SIZE:
if(wParam != SIZE_MINIMIZED)
MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, 0, LOWORD(lParam),
HIWORD(lParam), TRUE);
break;
case WM_SETFOCUS:
SetFocus(GetDlgItem(hwnd, IDC_MAIN_TEXT));
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CM_FILE_OPEN:
DoFileOpenSave(hwnd, FALSE);
break;
case CM_FILE_SAVEAS:
DoFileOpenSave(hwnd, TRUE);
break;
case CM_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case CM_START:
StartBoxService(hwnd);
break;
case CM_STOP:
StopBoxService(hwnd);
break;
case CM_ABOUT:
MessageBox (NULL, "File Editor for Windows !\n Using the Win32 API" , "About...", 0);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
Exit();
break;
case WM_DESTROY:
PostQuitMessage(0);
Exit();
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;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = "MAINMENU";
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"File Editor Example Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
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);
Initialization();
while(GetMessage(&Msg, NULL, 0, 0))
{
switch(Msg.message)
{
case TIMERSTART_MSG:
{
UpdateInfo(ghEdit, "SetTimer...");
Log("Start Timer, Waitting for session close...");
gTimerId = SetTimer(NULL, ID_TIMER, 2000, (TIMERPROC)TimerProc);
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
break;
case TIMERSTOP_MSG:
{
UpdateInfo(ghEdit, "KillTimer...");
Log("Stop Timer, Session Close Successfully...");
KillTimer(NULL, gTimerId);
TranslateMessage(&Msg);
DispatchMessage(&Msg);}
break;
default:
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return Msg.wParam;
}
int DoModal(HWND hWnd)
{
//标识处于模态状态中
g_isModaling = TRUE;
//显示自己
ShowWindow(hWnd, SW_SHOW);
BringWindowToTop(hWnd);
//disable掉父窗口
HWND hParentWnd = GetParent(hWnd);
while(hParentWnd != NULL)
{
EnableWindow(hParentWnd, FALSE);
hParentWnd = GetParent(hParentWnd);
}
//接管消息循环
while(g_isModaling)
{
MSG msg;
if (!GetMessage(&msg, NULL, 0, 0))
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//模态已经退出
//恢复父窗口的enable状态
hParentWnd = GetParent(hWnd);
while (hParentWnd != NULL)
{
EnableWindow(hParentWnd, TRUE);
hParentWnd = GetParent(hParentWnd);
}
//将自己隐藏
ShowWindow(hWnd, SW_HIDE);
return g_nModalCode;
}
void EndModal(int nCode)
{
g_nModalCode = nCode;
g_isModaling = FALSE;
PostMessage(NULL, WM_NULL, 0, 0);
}
BOOL CALLBACK DlgWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch ( msg )
{
case WM_INITDIALOG:
/*
* TODO: Add code to initialize the dialog.
*/
{
HWND hComboWnd = GetDlgItem(hWnd, IDC_CMBOX1);
SendMessage(hComboWnd,CB_ADDSTRING,0,(LPARAM)"test1");
SendMessage(hComboWnd,CB_ADDSTRING,0,(LPARAM)"test2");
SendMessage(hComboWnd,CB_ADDSTRING,0,(LPARAM)"test3");
}
break;
case WM_CLOSE:
EndDialog(hWnd, 0);
return TRUE;
case WM_PAINT:
break;
case WM_LBUTTONDOWN:
DestroyWindow( hWnd );
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
/*
* TODO: Add more control ID's, when needed.
*/
/*case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;*/
case IDC_BTN_TEST:
// BtnTest(hwndDlg);
//MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
{
HWND hComboWnd1 = GetDlgItem(hWnd, IDC_CMBOX1);
int idex = SendMessage(hComboWnd1,CB_GETCURSEL,0,0);
// MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
//DestroyWindow( hWnd );
}
return TRUE;
case IDC_BTN_CANCEL:
// BtnTest(hwndDlg);
//MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
DestroyWindow( hWnd );
return TRUE;
}
break;
default:
return FALSE; // 没处理过的消息
}
return TRUE; // 处理过的
}