📄 subject_17976.htm
字号:
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:su_37 回复日期:2002-10-17 10:34:16
<br>内容:你只需要把nMode定义为全局变量,然后在响应WM_CREATE消息时加上break;就可以达到目的了!<BR>#include <windows.h><BR>int nMode;<BR>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;<BR><BR>int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,<BR> PSTR szCmdLine, int iCmdShow)<BR>{<BR> static TCHAR szAppName[] = TEXT ("HelloWin") ;<BR> HWND hwnd ;<BR> MSG msg ;<BR> WNDCLASS wndclass ;<BR><BR> wndclass.style = CS_HREDRAW | CS_VREDRAW ;<BR> wndclass.lpfnWndProc = WndProc ;<BR> wndclass.cbClsExtra = 0 ;<BR> wndclass.cbWndExtra = 0 ;<BR> wndclass.hInstance = hInstance ;<BR> wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;<BR> wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;<BR> wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;<BR> wndclass.lpszMenuName = NULL ;<BR> wndclass.lpszClassName = szAppName ;<BR><BR> if (!RegisterClass (&wndclass))<BR> {<BR> MessageBox (NULL, TEXT ("This program requires Windows NT!"), <BR> szAppName, MB_ICONERROR) ;<BR> return 0 ;<BR> }<BR> hwnd = CreateWindow (szAppName, // window class name<BR> TEXT ("绘图示例"), // window caption<BR> WS_OVERLAPPEDWINDOW, // window style<BR> CW_USEDEFAULT, // initial x position<BR> CW_USEDEFAULT, // initial y position<BR> CW_USEDEFAULT, // initial x size<BR> CW_USEDEFAULT, // initial y size<BR> NULL, // parent window handle<BR> NULL, // window menu handle<BR> hInstance, // program instance handle<BR> NULL) ; // creation parameters<BR> <BR> ShowWindow (hwnd, iCmdShow) ;<BR> UpdateWindow (hwnd) ;<BR> <BR> while (GetMessage (&msg, NULL, 0, 0))<BR> {<BR> TranslateMessage (&msg) ;<BR> DispatchMessage (&msg) ;<BR> }<BR> return msg.wParam ;<BR>}<BR><BR>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)<BR>{<BR> HDC hdc ;<BR> PAINTSTRUCT ps ;<BR> HBRUSH hB1,hB2;<BR> <BR> switch (message)<BR> {<BR> case WM_CREATE:<BR> nMode=MM_TEXT;<BR> break;<BR> case WM_LBUTTONDOWN:<BR> nMode=MM_ISOTROPIC;<BR> InvalidateRect(hwnd,NULL,1);<BR> break;<BR> case WM_RBUTTONDOWN:<BR> nMode=MM_ANISOTROPIC;<BR> InvalidateRect(hwnd,NULL,1);<BR> break;<BR> case WM_PAINT:<BR> hdc=BeginPaint(hwnd,&ps);<BR> SetMapMode(hdc,nMode);<BR> SetWindowExtEx(hdc,150,150,NULL);<BR> SetViewportExtEx(hdc,10,10,NULL);<BR> SetViewportOrgEx(hdc,150,60,NULL);<BR> hB1=(HBRUSH)GetStockObject(BLACK_BRUSH);<BR> hB2=(HBRUSH)GetStockObject(WHITE_BRUSH);<BR> SelectObject(hdc,hB1);<BR> Rectangle(hdc,0,0,150,150);<BR> SelectObject(hdc,hB2);<BR> Ellipse(hdc,0,0,150,150);<BR> EndPaint(hwnd,&ps);<BR> return 0 ;<BR> case WM_DESTROY:<BR> DeleteObject(hB1);<BR> DeleteObject(hB2);<BR> PostQuitMessage (0) ;<BR> return 0 ;<BR> }<BR> return DefWindowProc (hwnd, message, wParam, lParam) ;<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>
回复者:蔡敏生 回复日期:2002-10-17 12:55:31
<br>内容:谢谢,tanks
<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 + -