Win32SDK对话框模板
来源:互联网 发布:powershell安装软件 编辑:程序博客网 时间:2024/06/06 11:27
前言
vc6向导生成Win32SDK时,没有对话框模板。
整理了一个, 写测试程序用.
Win32SDK对话框模板
// hw.cpp : Defines the entry point for the application.//#include "stdafx.h"#include <windows.h>#include <tchar.h>#include <stdio.h>#pragma comment(lib, "user32.lib")#include <Shellapi.h>#pragma comment(lib, "Shell32.lib")#include "resource.h"#include "constDefine.h"#include "constDefine.h"HINSTANCE g_hInstance = NULL;HWND g_hMainWnd = NULL;LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);void fnCenterWindow(HWND hWnd);void fnSetWndText(HWND hWnd, const TCHAR* pcTip);void fnSetCtrlText(int iCtrlId, const TCHAR* pcTip);LRESULT OnInitDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnClose(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnCancel(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnOk(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);LRESULT OnDropFiles(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// 做一些测试任务, 发行时,里面的内容会被关掉void fnTest_On_WinMain();int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ g_hInstance = hInstance; fnTest_On_WinMain(); return DialogBox(hInstance, (LPCTSTR)IDD_MAIN_DLG, GetDesktopWindow(), (DLGPROC)MainDlgProc);}LRESULT CALLBACK MainDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ BOOL bRc = TRUE; WORD wCtrlId = LOWORD(wParam); WORD wNotifyCode = HIWORD(wParam); HWND hSubWnd = (HWND)lParam; switch (message) { case WM_INITDIALOG: { OnInitDialog(hWnd, message, wParam, lParam); } break; case WM_COMMAND: switch (wCtrlId) { case IDCANCEL: OnCancel(hWnd, message, wParam, lParam); break; case IDOK: OnOk(hWnd, message, wParam, lParam); break; default: break; } break; case WM_CLOSE: OnClose(hWnd, message, wParam, lParam); break; case WM_DROPFILES: OnDropFiles(hWnd, message, wParam, lParam); break; default: bRc = FALSE; break; } return bRc;}void fnCenterWindow(HWND hWnd){ HWND hwndOwner; RECT rc; RECT rcDlg; RECT rcOwner; hwndOwner = GetParent(hWnd); if (NULL == hwndOwner) { hwndOwner = GetDesktopWindow(); } GetWindowRect(hwndOwner, &rcOwner); GetWindowRect(hWnd, &rcDlg); CopyRect(&rc, &rcOwner); OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); OffsetRect(&rc, -rc.left, -rc.top); OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); SetWindowPos(hWnd, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE);}void fnSetCtrlText(int iCtrlId, const TCHAR* pcTip){ HWND hWnd = NULL; if (NULL != g_hMainWnd) { hWnd = GetDlgItem(g_hMainWnd, iCtrlId); fnSetWndText(hWnd, pcTip); }}void fnSetWndText(HWND hWnd, const TCHAR* pcTip){ if (NULL != hWnd) { SetWindowText(hWnd, (NULL != pcTip) ? pcTip : _T("")); }}LRESULT OnInitDialog(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ g_hMainWnd = hWnd; fnSetWndText(g_hMainWnd, G_STR_PROG_NAME); fnCenterWindow(hWnd); return S_OK;}LRESULT OnClose(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ ::MessageBox(g_hMainWnd, "关闭", "提示", MB_OK); EndDialog(hWnd, LOWORD(wParam)); return S_OK;}LRESULT OnCancel(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ ::MessageBox(g_hMainWnd, "取消", "提示", MB_OK); EndDialog(hWnd, LOWORD(wParam)); return S_OK;}LRESULT OnOk(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ ::MessageBox(g_hMainWnd, "确定", "提示", MB_OK); EndDialog(hWnd, LOWORD(wParam)); return S_OK;}LRESULT OnDropFiles(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ POINT pt; UINT uFilesCnt = 0; UINT uIndex = 0; HDROP hDropFile = (HDROP)wParam; char lpszFile[MAXBYTE] = {'\0'}; DragQueryPoint(hDropFile, &pt); uFilesCnt = DragQueryFile(hDropFile, -1, (LPSTR) NULL, 0); for(uIndex = 0; uIndex < uFilesCnt; uIndex++) { DragQueryFile(hDropFile, uIndex, lpszFile, sizeof(lpszFile)); fnSetCtrlText(IDC_EDIT, lpszFile); } DragFinish(hDropFile); return S_OK;}void fnTest_On_WinMain(){}
0 0
- Win32SDK对话框模板
- win32sdk学习-创建一个对话框窗口
- 对话框模板
- 一个Win32SDK的通用的打开、保存文件的对话框的调用
- Win32SDK应用程序
- win32sdk计算器
- 对话框程序模板
- 谨慎对待对话框模板
- 对话框模板,RegexTest
- 关于win32sdk的timer
- C下WIN32SDK进度条
- WIN32SDK自绘Tooltip
- win32SDK窗口程序
- [Win32SDK基本]GetWindowRect/GetClientRect
- [Win32SDK基本] Combo Box
- QTP测试对话框窗体模板
- 模板配置对话框的创建
- 我为什么选择Win32SDK以及Win32SDK的特点
- tornado异步机制浅析
- 【原创】IOS游戏辅助--天天酷跑助手的实现
- jdk 环境变量配置
- Web基础之正则表达式
- POJ3461 字符串之模式匹配,kmp,求目标串中有多少个位置可重叠的子串
- Win32SDK对话框模板
- iOS第三方直播的集成
- 1021. Deepest Root (25)
- 程序调试
- 回溯法——迷宫问题
- Android数据库高手秘籍
- 马达电源处理
- VMware Workstation 的安装和使用
- Nodejs事件引擎libuv源码剖析之:高效线程池(threadpool)的实现