📄 subject_57870.htm
字号:
<p>
序号:57870 发表者:哆啦A梦 发表日期:2003-10-28 17:13:20
<br>主题:哪位能给个用 API 写的最简单的窗口代码
<br>内容:关键是简单
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:樂日華 回复日期:2003-10-28 17:20:25
<br>内容:sdk<BR><BR><BR>// a.cpp : Defines the entry point for the application.<BR>//<BR><BR>#include "stdafx.h"<BR>#include "resource.h"<BR><BR>#define MAX_LOADSTRING 100<BR><BR>// Global Variables:<BR>HINSTANCE hInst; // current instance<BR>TCHAR szTitle[MAX_LOADSTRING]; // The title bar text<BR>TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text<BR><BR>// Foward declarations of functions included in this code module:<BR>ATOM MyRegisterClass(HINSTANCE hInstance);<BR>BOOL InitInstance(HINSTANCE, int);<BR>LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);<BR>LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);<BR><BR>int APIENTRY WinMain(HINSTANCE hInstance,<BR> HINSTANCE hPrevInstance,<BR> LPSTR lpCmdLine,<BR> int nCmdShow)<BR>{<BR> // TODO: Place code here.<BR> MSG msg;<BR> HACCEL hAccelTable;<BR><BR> // Initialize global strings<BR> LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);<BR> LoadString(hInstance, IDC_A, szWindowClass, MAX_LOADSTRING);<BR> MyRegisterClass(hInstance);<BR><BR> // Perform application initialization:<BR> if (!InitInstance (hInstance, nCmdShow)) <BR> {<BR> return FALSE;<BR> }<BR><BR> hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_A);<BR><BR> // Main message loop:<BR> while (GetMessage(&msg, NULL, 0, 0)) <BR> {<BR> if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) <BR> {<BR> TranslateMessage(&msg);<BR> DispatchMessage(&msg);<BR> }<BR> }<BR><BR> return msg.wParam;<BR>}<BR><BR><BR><BR>//<BR>// FUNCTION: MyRegisterClass()<BR>//<BR>// PURPOSE: Registers the window class.<BR>//<BR>// COMMENTS:<BR>//<BR>// This function and its usage is only necessary if you want this code<BR>// to be compatible with Win32 systems prior to the 'RegisterClassEx'<BR>// function that was added to Windows 95. It is important to call this function<BR>// so that the application will get 'well formed' small icons associated<BR>// with it.<BR>//<BR>ATOM MyRegisterClass(HINSTANCE hInstance)<BR>{<BR> WNDCLASSEX wcex;<BR><BR> wcex.cbSize = sizeof(WNDCLASSEX); <BR><BR> wcex.style = CS_HREDRAW | CS_VREDRAW;<BR> wcex.lpfnWndProc = (WNDPROC)WndProc;<BR> wcex.cbClsExtra = 0;<BR> wcex.cbWndExtra = 0;<BR> wcex.hInstance = hInstance;<BR> wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_A);<BR> wcex.hCursor = LoadCursor(NULL, IDC_ARROW);<BR> wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);<BR> wcex.lpszMenuName = (LPCSTR)IDC_A;<BR> wcex.lpszClassName = szWindowClass;<BR> wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);<BR><BR> return RegisterClassEx(&wcex);<BR>}<BR><BR>//<BR>// FUNCTION: InitInstance(HANDLE, int)<BR>//<BR>// PURPOSE: Saves instance handle and creates main window<BR>//<BR>// COMMENTS:<BR>//<BR>// In this function, we save the instance handle in a global variable and<BR>// create and display the main program window.<BR>//<BR>BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)<BR>{<BR> HWND hWnd;<BR><BR> hInst = hInstance; // Store instance handle in our global variable<BR><BR> hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,<BR> CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);<BR><BR> if (!hWnd)<BR> {<BR> return FALSE;<BR> }<BR><BR> ShowWindow(hWnd, nCmdShow);<BR> UpdateWindow(hWnd);<BR><BR> return TRUE;<BR>}<BR><BR>//<BR>// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)<BR>//<BR>// PURPOSE: Processes messages for the main window.<BR>//<BR>// WM_COMMAND - process the application menu<BR>// WM_PAINT - Paint the main window<BR>// WM_DESTROY - post a quit message and return<BR>//<BR>//<BR>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<BR>{<BR> int wmId, wmEvent;<BR> PAINTSTRUCT ps;<BR> HDC hdc;<BR> TCHAR szHello[MAX_LOADSTRING];<BR> LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);<BR><BR> switch (message) <BR> {<BR> case WM_COMMAND:<BR> wmId = LOWORD(wParam); <BR> wmEvent = HIWORD(wParam); <BR> // Parse the menu selections:<BR> switch (wmId)<BR> {<BR> case IDM_ABOUT:<BR> DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);<BR> break;<BR> case IDM_EXIT:<BR> DestroyWindow(hWnd);<BR> break;<BR> default:<BR> return DefWindowProc(hWnd, message, wParam, lParam);<BR> }<BR> break;<BR> case WM_PAINT:<BR> hdc = BeginPaint(hWnd, &ps);<BR> // TODO: Add any drawing code here...<BR> RECT rt;<BR> GetClientRect(hWnd, &rt);<BR> DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);<BR> EndPaint(hWnd, &ps);<BR> break;<BR> case WM_DESTROY:<BR> PostQuitMessage(0);<BR> break;<BR> default:<BR> return DefWindowProc(hWnd, message, wParam, lParam);<BR> }<BR> return 0;<BR>}<BR><BR>// Mesage handler for about box.<BR>LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)<BR>{<BR> switch (message)<BR> {<BR> case WM_INITDIALOG:<BR> return TRUE;<BR><BR> case WM_COMMAND:<BR> if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) <BR> {<BR> EndDialog(hDlg, LOWORD(wParam));<BR> return TRUE;<BR> }<BR> break;<BR> }<BR> return FALSE;<BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:哆啦A梦 回复日期:2003-10-28 17:24:47
<br>内容:你这是把那个 HELLO!WORLD 的代码复制了过来,要最简单的!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:vcTM 回复日期:2003-10-28 17:26:46
<br>内容: 最简单的,用MFC的WIN32 APPLICATION建吧
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:redleaf 回复日期:2003-10-29 11:03:46
<br>内容:#include "windows.h"<BR><BR>int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmdLine, int nShowCmd)<BR>{<BR> return MessageBox(NULL, "aaaa", "bbbb", MB_OK);<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:山人 回复日期:2003-10-29 13:11:07
<br>内容:你用vc可以自动生成的
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -