当前位置:首页 > 嵌入式 > 嵌入式软件
[导读]需要先添加对话框,并且修改确定按钮的ID值.h文件struct DecodeUint{ UINT meesage; LONG (*fun)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); };#defi

需要先添加对话框,并且修改确定按钮的ID值

.h文件

struct DecodeUint{
 UINT meesage;
 LONG (*fun)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
};

#define dim(x) (sizeof(x)/sizeof(x[0]))

LONG OnInit(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LONG OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LONG OnClose(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LONG OnBtnClick(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

BOOL CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

 

.c文件

#include
#include
#include "Border.h"
#include "resource.h"
#include

struct DecodeUint DlgMessage[] = {
 WM_INITDIALOG,OnInit,
 WM_COMMAND,OnCommand,
};

struct DecodeUint DlgCommand[] = {
 IDBTN,OnBtnClick,
 IDCANCEL,OnClose,
};

HINSTANCE g_hInst;
HWND hStatic;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int WinMain(HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPTSTR    lpCmdLine,
   int       nCmdShow)
{
 g_hInst = hInstance;
 DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,About);
 return 1;
}

BOOL CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    for (int i = 0;i < dim(DlgMessage);i ++)
    {
  if (DlgMessage[i].meesage == message)
  {
   (*DlgMessage[i].fun)(hDlg,message,wParam,lParam);
  }
    }
 return FALSE;
}

LONG OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
 for (int i = 0;i < dim(DlgCommand);i ++)
 {
  if (DlgCommand[i].meesage == LOWORD(wParam))
  {
   (*DlgCommand[i].fun)(hDlg,message,wParam,lParam);
  }
 }

 return TRUE;
}

LONG OnInit(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
 hStatic = CreateWindow(TEXT("static"),TEXT("static text"),WS_CHILD | WS_VISIBLE | WS_BORDER | SS_CENTER | SS_CENTERIMAGE,
  10,10,200,200,hDlg,(HMENU)101,g_hInst,NULL);
 return TRUE;
}

LONG OnClose(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
 EndDialog(hDlg,0);
 return TRUE;
}

LONG OnBtnClick(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
 //1 获取文本内容 修改对话框标题
 //TCHAR * pc;
 //int count = Static_GetTextLength(hStatic);
 //pc = new TCHAR[count+1];
 //Static_GetText(hStatic,pc,count+1);
 //SetWindowText(hDlg,pc);
 //delete pc;
 
 //2 设置按钮不可用
 Button_Enable(GetDlgItem(hDlg,IDCANCEL),FALSE);
 return 0;
}

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭