win32简单例子-NO MFC ,实现文件拖放

LLanguage 2008-11-10 03:32:55
#include <windows.h>
#include <shellapi.h>
#include <Windowsx.h>

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
HWND hwndedit1;
HWND hwndlistbox1;

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
WS_EX_ACCEPTFILES, /* Extended possibilites for variation */
szClassName, /* Classname */
"indows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);


hwndlistbox1=CreateWindow(
"listbox",
"",
WS_CHILD|WS_VISIBLE|LBS_STANDARD,
0,30,500,100,
hwnd,
(HMENU)2,
hThisInstance,
NULL
);



/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);

/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}


/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;

case WM_DROPFILES:
{
HDROP hDrop = (HDROP) wParam;

int count=DragQueryFile(hDrop,0xFFFFFFFF,NULL,0);

char *lpszFileName=new char[512];

for(int i=0;i<count;i++)
{
int nCharactersLen= DragQueryFile(hDrop,i,NULL,100);

DragQueryFile(hDrop,i,lpszFileName,nCharactersLen+1);

ListBox_AddString(GetDlgItem(hwnd,2),lpszFileName);

}
delete lpszFileName;
}
break;

default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}
...全文
139 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
1,cstatic_filespec.zip静态文本中用省略号显示长文件名(3KB)2,cstatic_filespec_demo.zip静态文本中用省略号显示长文件名的演示程序(14KB)3,newlabel_app.zipCNewLabel--高级的CStatic派生(39KB)4,jumpytext_demo.zip跳动的文本类演示程序(138KB)实现菜单的工具提示演示程序(33KB)16,dockmenubar_src.zipDevStudio样式的泊位菜单条(不用MSIE)(27KB)17,dockmenubar_demo.zipDevStudio样式的泊位菜单条演示程序(不用MSIE)(58KB)18,label_edit.zip可编辑的标号控制(5KB)19,flat_scrollbar.zip扁平滚动条控制(11KB)20,avidemo.zip动画控制的例子(145KB)21,balloontooltip_src.zip像气球一样的工具提示(7KB)22,balloontooltip_demo.zip像气球一样的工具提示演示程序(49KB)23,check_frame.zip一个有用的CheckFrame控制(31KB)24,extended_tooltip.zip扩展的ToolTipCtrl类(21KB)25,progress_in_status2_src.zip在状态栏里显示进度条(4KB)26,progress_in_status2_demo.zip在状态栏里显示进度条演示程序(39KB)27,vcmenu.zipVisual Studio/Office 97 式样的扁平工具条和可泊位菜单条(350KB)28,flatbar_source.zip另一个扁平工具条(不需要MSIE)(11KB)29,flatbar_sample_project.zip另一个扁平工具条(不需要MSIE)工程程序(185KB)30,enh_flatbar_source.zip另一个扁平工具条(不需要MSIE)增强版(25KB)31,enh_flatbar_sample.zip另一个扁平工具条(不需要MSIE)演示增强版(56KB)32,customizable_tb.zip可定制的工具条(25KB)33,treemenudemo.zip一个类似IE4的收藏夹/历史/频道视图的控制(72KB)34,cdirtreectrl_demo.zipDirTreeCtrl--显示文件夹和文件演示程序(56KB)35,cdirtreectrl_src.zipDirTreeCtrl--显示文件夹和文件(6KB)36,a

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧